GenPM 模块共享类型:内容、站点地图、搜索、后台资源、支付和追踪事件
代码10 个文件上下文约 532 个 token扫描通过
安装
$
genpm add @core/contracts你将获得
- 源代码位于 src/lib/contracts/,共 10 个文件。 (13.3 kB)
- AI 规则位于 src/lib/contracts/AGENTS.md,另附 IDE 规则文件。
README
此包没有 README。
约 532 个 token→ src/lib/contracts/AGENTS.md→ .cursor/rules/genpm-core-contracts.mdc
这正是你的 AI 在 src/lib/contracts 中工作时读取的内容。不会向其上下文添加其他任何内容。
@core/contracts — rules for AI agents
Purpose
Types and small zod schemas shared by GenPM catalog modules, so a module can consume "anything that provides content /
sitemap URLs / search documents / admin resources / payments" without importing the concrete module. No logic, no
tables, no runtime dependency besides zod.
Map
index.ts— public API. Import from here only.content.ts—ContentSource,ContentEntry(implemented by @core/content and CMS adapters).sitemap.ts—SitemapSource(consumed by @core/seo).search.ts—SearchSource,SearchDocument(consumed by @core/search).admin.ts—AdminResource,AdminField(consumed by @core/admin).payment.ts—PaymentProvider(implemented by @core/checkout, used by @core/orders).events.ts—CommerceEvent,LeadEventand their zod schemas (consumed by @core/pixels).money.ts—Money(integer minor units + ISO 4217 code).
Integration
- Usually installed as a dependency of another module; nothing to wire.
- To expose your own data to the admin, sitemap or search, implement the type and register it in the project file
the consuming module documents (
src/genpm/admin.ts,src/genpm/seo.ts,src/genpm/search.ts):import { defineSitemapSource } from './lib/contracts/index.ts'; export const projects = defineSitemapSource({ name: 'projects', async *urls() { yield { loc: '/projects' }; } }); - Validate untrusted tracking payloads with
TrackedEventSchema.parse(body)before forwarding them.
Conventions
- Money is always
{ amount: integer minor units, currency: 'EUR' }; never floats. - Sources are async iterables: stream rows in pages, don't load whole tables into memory.
AdminResource.inputvalidates create/update input; permissions are<resource>:<action>(posts:update).
Don't
- Don't add implementations or helpers with behaviour here; put them in the module that owns the concept.
- Don't change an existing type incompatibly: every catalog module depends on it (major version of the whole train).
- Don't import other modules from this folder.
# @core/contracts — rules for AI agents
## Purpose
Types and small zod schemas shared by GenPM catalog modules, so a module can consume "anything that provides content /
sitemap URLs / search documents / admin resources / payments" without importing the concrete module. No logic, no
tables, no runtime dependency besides `zod`.
## Map
- `index.ts` — public API. Import from here only.
- `content.ts` — `ContentSource`, `ContentEntry` (implemented by @core/content and CMS adapters).
- `sitemap.ts` — `SitemapSource` (consumed by @core/seo).
- `search.ts` — `SearchSource`, `SearchDocument` (consumed by @core/search).
- `admin.ts` — `AdminResource`, `AdminField` (consumed by @core/admin).
- `payment.ts` — `PaymentProvider` (implemented by @core/checkout, used by @core/orders).
- `events.ts` — `CommerceEvent`, `LeadEvent` and their zod schemas (consumed by @core/pixels).
- `money.ts` — `Money` (integer minor units + ISO 4217 code).
## Integration
1. Usually installed as a dependency of another module; nothing to wire.
2. To expose your own data to the admin, sitemap or search, implement the type and register it in the project file
the consuming module documents (`src/genpm/admin.ts`, `src/genpm/seo.ts`, `src/genpm/search.ts`):
```ts
import { defineSitemapSource } from './lib/contracts/index.ts';
export const projects = defineSitemapSource({ name: 'projects', async *urls() { yield { loc: '/projects' }; } });
```
3. Validate untrusted tracking payloads with `TrackedEventSchema.parse(body)` before forwarding them.
## Conventions
- Money is always `{ amount: integer minor units, currency: 'EUR' }`; never floats.
- Sources are async iterables: stream rows in pages, don't load whole tables into memory.
- `AdminResource.input` validates create/update input; permissions are `<resource>:<action>` (`posts:update`).
## Don't
- Don't add implementations or helpers with behaviour here; put them in the module that owns the concept.
- Don't change an existing type incompatibly: every catalog module depends on it (major version of the whole train).
- Don't import other modules from this folder.
应用 .genpmignore 后将被注入的确切目录树。固定于
// Recurso del panel de administración: cualquier paquete describe sus datos así y @core/admin genera lista,
// formulario y acciones sin pantallas escritas a mano. El paquete no depende de @core/admin, solo de este tipo.
import type { ZodType } from 'zod';
export type AdminFieldType =
| 'text'
| 'textarea'
| 'slug'
| 'email'
| 'url'
| 'number'
| 'money'
| 'boolean'
| 'date'
| 'datetime'
| 'select'
| 'relation'
| 'media'
| 'richText'
| 'blocks'
| 'list'
| 'json'
| (string & {});
export type AdminField = {
name: string;
label: string;
type: AdminFieldType;
required?: boolean;
help?: string;
readOnly?: boolean;
/** Mostrar como columna en la lista. */
list?: boolean;
/** `select`: opciones. */
options?: Array<{ value: string; label: string }>;
/** `relation`: nombre del recurso relacionado. */
relationTo?: string;
/** `relation`: campo del registro relacionado que se guarda (por defecto `id`; p. ej. `slug`). */
relationKey?: string;
/** `relation` / `media`: admite varios valores. */
many?: boolean;
/** `list`: campos de cada elemento (lista ordenable de objetos: características, preguntas, testimonios…). */
fields?: AdminField[];
};
/** Usuario que actúa en el panel. `can` ya resuelve los permisos (lo inyecta @core/admin con @core/rbac). */
export type AdminContext = {
user: { id: string; email: string | null; name: string | null };
can(permission: string): Promise<boolean>;
};
export type AdminListQuery = {
page: number;
pageSize: number;
search?: string;
sort?: { field: string; dir: 'asc' | 'desc' };
filters?: Record<string, string>;
};
export type AdminListResult<T> = { rows: T[]; total: number };
/** Acción extra sobre un registro (publicar, programar, reembolsar…). El panel la muestra si `can(permission)`. */
export type AdminAction<T> = {
name: string;
label: string;
permission: string;
/** Pide confirmación antes de ejecutarla. */
confirm?: boolean;
/** Entrada adicional (p. ej. fecha de programación). */
input?: ZodType;
/** Si se ofrece para este registro. */
available?(row: T): boolean;
run(id: string, input: unknown, ctx: AdminContext): Promise<T>;
};
export type AdminResource<T extends { id: string } = { id: string } & Record<string, unknown>> = {
/** Identificador en URLs y permisos: `posts` → `/admin/posts`, `posts:read`. */
name: string;
label: { singular: string; plural: string };
icon?: string;
/** Grupo del menú lateral (`Content`, `Store`…). */
group?: string;
fields: AdminField[];
/** Valida la entrada de create/update. */
input: ZodType;
/** Texto con el que se muestra un registro (títulos, relaciones, auditoría). */
title(row: T): string;
list(query: AdminListQuery, ctx: AdminContext): Promise<AdminListResult<T>>;
get(id: string, ctx: AdminContext): Promise<T | null>;
create?(input: unknown, ctx: AdminContext): Promise<T>;
update?(id: string, input: unknown, ctx: AdminContext): Promise<T>;
delete?(id: string, ctx: AdminContext): Promise<void>;
actions?: AdminAction<T>[];
/** Enlaces del registro en la vista de edición ("Ver", "Vista previa"…). Rutas relativas o https. */
links?(row: T, ctx: AdminContext): Promise<Array<{ label: string; href: string }>> | Array<{ label: string; href: string }>;
};
export const defineAdminResource = <T extends { id: string }>(resource: AdminResource<T>): AdminResource<T> =>
resource;
此包未声明 MCP 服务器。
| 版本 | 提交 | 发布时间 | 扫描 |
|---|---|---|---|
| 1.0.0 | 7266529 | 7小时前 | 扫描通过 |
- genpm
- 无
- npm
- zod ^4.0.0
- 建议
- GenPM 会给出 npm 命令建议,只有你同意时才会运行。
- 被以下包使用(22)
- @core/admin ^1.0.0@core/blocks ^1.0.0@core/blog ^1.0.0@core/cart ^1.0.0@core/catalog ^1.0.0@core/comments ^1.0.0@core/content ^1.0.0@core/experiments ^1.0.0@core/forms ^1.0.0@core/invoices ^1.0.0@core/media ^1.0.0@core/money ^1.0.0@core/newsletter ^1.0.0@core/orders ^1.0.0@core/pixels ^1.0.0@core/pricing ^1.0.0@core/rbac ^1.0.0@core/search ^1.0.0@core/seo ^1.0.0@core/shipping ^1.0.0
- 扫描
- 扫描通过 · 0 个问题
- 提交
- v1.0.0 → 7266529e19beb49b518121150977d7b712cb7e5f · 获取后已校验
- 脚本
- 无。GenPM 从不运行包中的代码。
- 许可证
- MIT
- 质量
- 100/100
- 可识别的许可证已满足
- AGENTS.md 说明了用途已满足
- AGENTS.md 包含集成步骤已满足
- AGENTS.md 列出约定或禁止事项已满足
- 包含测试已满足
- 通过安全扫描已满足
- 最近 6 个月内发布已满足
- 已验证的发布者已满足
- 摘要和关键词已满足
- 举报
- 发现问题了吗?