@happyvertical/smrt-sites

中文文档
0.62.1发布于 2026/11/17MITTypeScriptES Module近 30 天下载 1.4万

Site lifecycle management for multi-tenant SMRT networks

原始使用文档
文档目录12 节
  1. Installation
  2. Usage
  3. Site lifecycle
  4. Agent bindings
  5. Zones, domains, and project links
  6. Portal configuration
  7. API
  8. Models
  9. Collections
  10. Services
  11. Key Types
  12. Dependencies

@happyvertical/smrt-sites

Site lifecycle management for multi-tenant s-m-r-t networks. Manages deployable websites with provisioning status, tier classification, portal configuration, and agent bindings with priority ordering.

Installation

pnpm add @happyvertical/smrt-sites

Usage

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);

Site lifecycle

Sites progress through four statuses: draft -> active -> suspended -> archived. The SiteService enforces validation on activation (name and domain required) and tracks provisioning state separately via provisioningStatus (pending/provisioning/ready/failed). Sites are uniquely identified by (tenant_id, domain).

Agent bindings

SiteAgentBinding is a junction table linking sites to agent classes. Each binding has a priority (higher values execute first), an enabled flag, and optional per-site config overrides stored as JSON. The bindAgent() method upserts -- updating config if a binding already exists, creating one if not. findEnabled() returns bindings sorted by priority descending.

DnsZone is an apex (example.com); Domain is one hostname under a zone (work.example.com, FK zoneId); ProjectDomain links a domain to a project with a role (production, staging, preview, mail, redirect, other). One zone hosts many projects. projectId is a @crossPackageRef to @happyvertical/smrt-projects:Project (no package dependency). The zone model is DnsZone, not Zone, because @happyvertical/smrt-properties already registers a Zone.

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

Hostname helpers validate what an owner types before you create records. Import from @happyvertical/smrt-sites/hostname instead of the root in browser-safe code that must not load the models:

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 remains a plain string; it is not yet linked to Domain.

Portal configuration

Sites store theme, branding, and navigation settings in portalConfig as JSON. Use getPortalConfig()/setPortalConfig() for type-safe access. Both models require tenant context (@TenantScoped({ mode: 'required' })).

API

Models

ExportDescription
SiteSite record with domain, status, tier, provisioning tracking, and portal config
SiteAgentBindingJunction binding an agent class to a site with priority and config overrides

Collections

ExportDescription
SiteCollectionCRUD and queries for Site records
SiteAgentBindingCollectionQueries by site, agent class, and enabled state with priority sorting

Services

ExportDescription
SiteServiceHigh-level lifecycle ops: create, activate, suspend, archive, bind/unbind agents

Key Types

SiteOptions, SiteStatus, SiteTier, ProvisioningStatus, SitePortalConfig, SiteServiceOptions, SiteAgentBindingOptions, CreateSiteData

Dependencies

  • @happyvertical/smrt-core -- ORM and code generation
  • @happyvertical/smrt-tenancy -- required multi-tenant scoping
  • Peer: @happyvertical/smrt-agents (optional)

版本与发布记录

@happyvertical/smrt-sites 共发布 365 个版本,首次发布于 2026/06/23;过去 12 个月发布了 365 个版本。

版本发布日期距今
0.62.1latest2026/11/17今天
0.62.02026/11/17今天
0.61.62026/11/161 天前
0.61.52026/11/161 天前
0.61.42026/11/161 天前
0.61.32026/11/152 天前

关于 @happyvertical/smrt-sites 的常见问题

@happyvertical/smrt-sites 是什么?

Site lifecycle management for multi-tenant SMRT networks

如何安装 @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 和提交记录判断。