npx skills add https://github.com/wix/skills --skill wix-cli-backend-event为 Wix CLI 应用程序创建事件扩展。当特定条件满足时触发事件——对于应用项目,触发于 Wix 用户的站点;对于无头项目,则触发于您项目的站点。您的项目通过基于 JavaScript SDK Webhook 构建的事件扩展进行响应;CLI 会将您的项目订阅到这些 Webhook。
常见用例:在创建联系人、下单、确认预订或发布博客文章时运行逻辑。
创建事件扩展时,请按顺序遵循以下步骤。
src/extensions/backend/events/<event-name>/<event-name>.ts 文件,包含 SDK 事件导入和处理函数<event-name>.extension.ts 文件,包含 extensions.event() 和一个唯一的 UUIDsrc/extensions.ts 以导入并使用新扩展用户(手动操作): 如果需要在应用仪表板中为事件配置应用权限;发布版本并触发事件以进行测试。
| 主题 | 参考 |
|---|
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 常见事件(CRM、电商、预订、博客) | COMMON-EVENTS.md |
每个事件对应两个文件(文档)。应用中(包括仪表板中的处理程序)每个事件只允许有一个处理程序。
src/extensions/backend/events/<event-name>/
├── <event-name>.extension.ts # 构建器:extensions.event({ id, source }) – id 是唯一的 GUID
└── <event-name>.ts # 处理程序:导入 SDK 事件(例如 onContactCreated),在触发时运行
<event-name>.extension.ts)使用来自 @wix/astro/builders 的 extensions.event()。必需字段:id(唯一 GUID)、source(处理程序文件的路径)。
import { extensions } from "@wix/astro/builders";
export const eventContactCreated = extensions.event({
id: "{{GENERATE_UUID}}",
source: "./extensions/backend/events/contact-created/contact-created.ts",
});
关键:UUID 生成
id 必须是一个唯一的、静态的 UUID v4 字符串。为每个扩展生成一个新的 UUID——不要使用 randomUUID() 或复制示例中的 UUID。将 {{GENERATE_UUID}} 替换为新生成的 UUID,例如 "a1b2c3d4-e5f6-7890-abcd-ef1234567890"。
<event-name>.ts)从正确的 SDK 模块导入事件并传递一个处理函数。当事件发生时,Wix 会调用该处理函数并传入事件负载和元数据。处理函数签名记录在 JavaScript SDK 参考 中。
import { onContactCreated } from "@wix/crm/events";
onContactCreated((event) => {
console.log("Contact created:", event.entity);
// 自定义逻辑:同步到 CRM、发送欢迎邮件等。
});
处理函数可以是 async;确保捕获并记录错误,以免一个失败的处理函数影响其他处理函数。
需要两个步骤。
在事件文件夹内创建 <event-name>.extension.ts(以及处理程序的 <event-name>.ts),如上文“实现模式”所示。
关键: 阅读 wix-cli-extension-registration 并将事件扩展添加到 src/extensions.ts(导入并使用 .use(eventContactCreated) 或等效方法)。不执行此操作,事件扩展将不会激活。
命名:导出名称遵循 event{CamelCaseName} 格式(例如 eventContactCreated、eventOrderPaid)。
从事件处理程序内部调用 Wix API 时,请使用来自 @wix/essentials 的 auth.elevate,以便调用以正确的权限运行。
import { auth } from "@wix/essentials";
import { items } from "@wix/data";
onContactCreated(async (event) => {
const elevatedQuery = auth.elevate(items.query);
const result = await elevatedQuery("MyCollection").find();
// 使用结果
});
console.log 进行调试;保持生产环境日志最少且不包含敏感信息。每周安装数
178
代码仓库
GitHub 星标数
3
首次出现
2026年2月8日
安全审计
安装于
opencode157
cursor84
codex79
gemini-cli77
github-copilot74
amp69
Creates event extensions for Wix CLI applications. Events are triggered when specific conditions occur—on a Wix user's site for app projects, or on your project's site for headless projects. Your project responds using event extensions built on JavaScript SDK webhooks; the CLI subscribes your project to these webhooks.
Common use cases: run logic when a contact is created, an order is placed, a booking is confirmed, or a blog post is published.
Follow these steps in order when creating an event extension.
src/extensions/backend/events/<event-name>/<event-name>.ts with the SDK event import and handler function<event-name>.extension.ts with extensions.event() and a unique UUIDsrc/extensions.ts to import and use the new extensionUser (manual): Configure app permissions for the event in the app dashboard if required; release a version and trigger the event to test.
| Topic | Reference |
|---|---|
| Common events (CRM, eCommerce, Bookings, Blog) | COMMON-EVENTS.md |
Two files per event (docs). Only one handler per event allowed in the app (including dashboard handlers).
src/extensions/backend/events/<event-name>/
├── <event-name>.extension.ts # Builder: extensions.event({ id, source }) – id is unique GUID
└── <event-name>.ts # Handler: imports SDK event (e.g. onContactCreated), runs on trigger
<event-name>.extension.ts)Use extensions.event() from @wix/astro/builders. Required fields: id (unique GUID), source (path to the handler file).
import { extensions } from "@wix/astro/builders";
export const eventContactCreated = extensions.event({
id: "{{GENERATE_UUID}}",
source: "./extensions/backend/events/contact-created/contact-created.ts",
});
CRITICAL: UUID Generation
The id must be a unique, static UUID v4 string. Generate a fresh UUID for each extension—do NOT use randomUUID() or copy UUIDs from examples. Replace {{GENERATE_UUID}} with a freshly generated UUID like "a1b2c3d4-e5f6-7890-abcd-ef1234567890".
<event-name>.ts)Import the event from the correct SDK module and pass a handler. Wix invokes the handler with the event payload and metadata when the event occurs. Handler signatures are documented in the JavaScript SDK reference.
import { onContactCreated } from "@wix/crm/events";
onContactCreated((event) => {
console.log("Contact created:", event.entity);
// Custom logic: sync to CRM, send welcome email, etc.
});
Handler can be async; ensure errors are caught and logged so one failing handler does not break others.
Two steps required.
Create <event-name>.extension.ts inside the event folder (and <event-name>.ts for the handler) as shown in Implementation Pattern above.
CRITICAL: Read wix-cli-extension-registration and add the event extension to src/extensions.ts (import and .use(eventContactCreated) or equivalent). Without this, the event extension is not active.
Naming: export names follow event{CamelCaseName} (e.g. eventContactCreated, eventOrderPaid).
When calling Wix APIs from inside an event handler, use auth.elevate from @wix/essentials so the call runs with the right permissions.
import { auth } from "@wix/essentials";
import { items } from "@wix/data";
onContactCreated(async (event) => {
const elevatedQuery = auth.elevate(items.query);
const result = await elevatedQuery("MyCollection").find();
// Use result
});
console.log for debugging; keep production logs minimal and non-sensitive.Weekly Installs
178
Repository
GitHub Stars
3
First Seen
Feb 8, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode157
cursor84
codex79
gemini-cli77
github-copilot74
amp69
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
152,900 周安装
Azure Application Insights 仪表化指南 - ASP.NET Core/Node.js/Python 应用监控教程
103,100 周安装
Azure 诊断官方指南 - 调试排查生产问题、函数应用、容器应用故障排除
103,300 周安装
Azure存储服务全解析:Blob、文件、队列、表存储及Data Lake使用指南
103,300 周安装
Azure部署指南:从验证到执行,确保云应用成功上线
103,300 周安装
Azure成本优化技能:识别节省机会、清理孤立资源、调整规模 | Microsoft Copilot
103,300 周安装
scikit-survival:Python生存分析库,处理删失数据与Cox模型、随机生存森林
163 周安装