# @happyvertical/smrt-sites 中文文档

规范地址：https://npmcn.com/package/%40happyvertical/smrt-sites/

版本：0\.62\.1
npm 元数据更新时间：2026-11-17T07:55:54.638Z
中文译文更新时间：2026-11-17T10:28:44.747Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40happyvertical/smrt-sites
原文对照：https://npmcn.com/package/%40happyvertical/smrt-sites/?lang=original
项目主页：https://github.com/happyvertical/smrt#readme
源码仓库：https://github.com/happyvertical/smrt

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：317 kB，45 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：2 个
- 首次发布：2026-06-23T01:18:45.353Z
- 最新版本发布：2026-11-17T07:55:54.427Z
- 近 30 天下载量：14212（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：365（近 12 个月 365 个）

## 中文简介

多租户SMRT网络的站点生命周期管理

## 安装

```sh
npm install @happyvertical/smrt-sites
```

也可以使用：`pnpm add @happyvertical/smrt-sites`、`yarn add @happyvertical/smrt-sites`、`bun add @happyvertical/smrt-sites`

## README

# @happyvertical/ smrt- sites (英语)

多租户s-m-r-t网络的站点生命周期管理. 管理可部署网站,提供状况、分级分类、门户配置和具有优先排序的代理约束.

## 安装

```bash
pnpm add @happyvertical/smrt-sites
```

## 使用量

```typescript
import {
  Site, SiteCollection,
  SiteAgentBinding, SiteAgentBindingCollection,
  SiteService
} from '@happyvertical/smrt-sites';

// Create collections
const sites = await SiteCollection.create({ db });
const bindings = await SiteAgentBindingCollection.create({ db });

// Use SiteService for lifecycle operations
const service = new SiteService({ sites, bindings });

// Create a site (starts in draft status)
const site = await service.createSite('tenant-123', {
  name: 'Community Hub',
  domain: 'hub.example.com',
  tier: 'standard',
});

// Activate after validation (requires name + domain)
await service.activateSite(site.id);

// Mark infrastructure as provisioned
await service.markProvisioned(site.id);

// Bind agents with priority ordering (higher = first)
await service.bindAgent(site.id, 'Praeco', { schedule: '0 * * * *' });
await service.bindAgent(site.id, 'Caelus', { maxArticles: 50 });

// Get enabled agents sorted by priority descending
const agents = await service.getEnabledAgents(site.id);

// Suspend or archive a site
await service.suspendSite(site.id);
await service.archiveSite(site.id);
```

### 场地生命周期

站点通过四个状态取得进展: `draft` - > (中文) `active` - > (中文) `suspended` - > (中文) `archived`编辑 `SiteService` 在激活时执行验证(需要名称和域名),并分别通过轨道提供状态 `provisioningStatus` (待付/备付/准备/失效)。 站点由 `(tenant_id, domain)`。 。 。 .

### 代理绑定

`SiteAgentBinding` 是一个连接站点和代理类的交叉表。 每个约束有一个 `priority` (先执行高值), a `enabled` 旗子,每个地点可选 `config` 存储为 JSON 的覆盖 。 这个 `bindAgent()` 方法上调 - 如果绑定物已经存在,则更新配置,如果不存在,则创建配置. `findEnabled()` 返回绑定,按优先级下移排序.

### 区、域和项目链接

`DnsZone` 是顶端 (y)`example.com`(三); `Domain` 是一个区域下的主机名( n)`work.example.com`FK (韩语) `zoneId`(三); `ProjectDomain` 链接一个域到带有 `role` (单位:千美元)`production`, (中文(简体) ), `staging`, (中文(简体) ), `preview`, (中文(简体) ), `mail`, (中文(简体) ), `redirect`, (中文(简体) ), `other`) (中文(简体) ). 一个区主办许多项目. `projectId` 是一个 `@crossPackageRef` 改为 `@happyvertical/smrt-projects:Project` (不依赖软件包). 区型是 `DnsZone`没有 `Zone`,因为 `@happyvertical/smrt-properties` 已经注册 a `Zone`。 。 。 .

```typescript
const service = new DomainService({ domains, links });
await links.assign(domain, projectId, 'production'); // idempotent; tenant from the domain
await service.domainsByZone(tenantId, zone.id);
await service.domainsByProject(tenantId, projectId, 'staging'); // role optional
await service.unassignedDomains(tenantId); // domains with no project link
```

主机名帮助者在创建记录前验证所有者的类型 。 从 `@happyvertical/smrt-sites/hostname` 而不是浏览器安全代码中不能加载模型的根 :

```typescript
import { defaultZoneFor, hostnameBelongsToZone, parseHostname } from '@happyvertical/smrt-sites';

const host = parseHostname(' Work.Example.com. '); // 'work.example.com' (null if not a plain multi-label hostname)
if (!host) throw new Error('not a hostname');
const zone = defaultZoneFor(host); // 'example.com' (last two labels; name the zone yourself for example.co.uk)
hostnameBelongsToZone(host, zone); // true for the apex or a subdomain, never for 'evilexample.com'
```

`Site.domain` 仍然是平面字符串;尚未与 `Domain`。 。 。 .

### 门户配置

站点存储主题、品牌和导航设置 `portalConfig` 作为JSON。 使用 `getPortalConfig()`编号 :`setPortalConfig()` 安全进入 两种模式都要求租户的背景(`@TenantScoped({ mode: 'required' })`) (中文(简体) ).

## API 密码

### 模型

| 导出 | 说明 |
| --- | --- |
| `Site` | 具有域、状态、等级、提供跟踪和门户配置的站点记录 |
| `SiteAgentBinding` | 将代理类绑定在具有优先权和配置功能的站点上 |

### 收款

| 导出 | 说明 |
| --- | --- |
| `SiteCollection` | CRUD 和网站记录查询 |
| `SiteAgentBindingCollection` | 按站点、代理类和启用状态进行优先排序 |

### 服务

| 导出 | 说明 |
| --- | --- |
| `SiteService` | 高级生命周期操作:创建、激活、暂停、存档、绑定/未连接代理 |

### 密钥类型

`SiteOptions`, (中文(简体) ), `SiteStatus`, (中文(简体) ), `SiteTier`, (中文(简体) ), `ProvisioningStatus`, (中文(简体) ), `SitePortalConfig`, (中文(简体) ), `SiteServiceOptions`, (中文(简体) ), `SiteAgentBindingOptions`, (中文(简体) ), `CreateSiteData`

## 依赖关系

-   `@happyvertical/smrt-core` -- ORM 和代码生成
-   `@happyvertical/smrt-tenancy` -- 需要多用户范围界定
-   端点 : `@happyvertical/smrt-agents` (可选)

## 常见问题

### @happyvertical/smrt-sites 是什么？

多租户SMRT网络的站点生命周期管理

### 如何安装 @happyvertical/smrt-sites？

在项目目录运行 npm install @happyvertical/smrt-sites，或使用 pnpm add / yarn add / bun add。

### @happyvertical/smrt-sites 支持 TypeScript 吗？

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

### @happyvertical/smrt-sites 支持 ESM 还是 CommonJS？

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

### @happyvertical/smrt-sites 可以商用吗？

@happyvertical/smrt-sites 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @happyvertical/smrt-sites 的下载量有多少？

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

### @happyvertical/smrt-sites 还在维护吗？

最新版本 0\.62\.1 发布于 2026/11/17（今天）；至今共发布 365 个版本，其中过去 12 个月发布了 365 个；首次发布于 2026/06/23。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

