commerce-app-eventing
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseConfigure Commerce App Eventing
配置Commerce应用事件处理
Adds or modifies event sources — Commerce-native events or external events — in an existing .
Extensibility domains other than eventing (webhooks, business config) are added separately via their own skills.
app.commerce.config.ts在现有的中添加或修改事件源——Commerce原生事件或外部事件。事件处理之外的扩展领域(如webhooks、业务配置)需通过各自的技能单独添加。
app.commerce.config.tsPrerequisites
前提条件
- Verify the app is scaffolded and initialized, not merely that the config exists. Require both:
- present in the project root, and
app.commerce.config.ts - the project initialized — signalled by the generated directory and installed
src/commerce-extensibility-1/(thenode_modulesdependency).@adobe/aio-commerce-lib-app
- If is missing, stop and invoke
app.commerce.config.tsfirst (it writes the config, then runs init).commerce-app-init - If the config is present but the project is not initialized (no or
src/commerce-extensibility-1/), runnode_modulesbefore continuing. Init is idempotent — it finds the existing config, skips the interactive prompts, installs dependencies, and generates the project files.npx @adobe/aio-commerce-lib-app init - Actions can be authored in TypeScript only once the project has the TypeScript build setup (+ root
webpack-config.cjs) thattsconfig.jsonscaffolds for a TypeScript Commerce config — seeinit. Otherwise, author actions in JavaScript.commerce-app-init - Ensure (I/O Events) and
CloudIntegrationSDK(Adobe I/O Events for Adobe Commerce) are subscribed in the Developer Console workspace:commerceeventing-
List currently subscribed services:sh
aio console workspace api list --projectName <project> --workspaceName <workspace> --json -
If either service is missing, re-subscribe with the full merged set of service codes (existing + missing).replaces the subscription list — omitting a currently-subscribed service will remove it.
aio console workspace api addshaio console workspace api add \ --projectName <project> \ --workspaceName <workspace> \ --service-code <existing-codes>,CloudIntegrationSDK,commerceeventing \ --jsonIf the command fails with "product profile required" for, ask the user for the profile name and retry withcommerceeventing.--license-config commerceeventing=<profile>
-
- 验证应用已搭建并初始化,而非仅存在配置文件。需同时满足:
- 项目根目录下存在,且
app.commerce.config.ts - 项目已完成初始化——标志为生成的目录和已安装的
src/commerce-extensibility-1/(包含node_modules依赖)。@adobe/aio-commerce-lib-app
- 项目根目录下存在
- 如果缺少,请先停止当前操作并调用
app.commerce.config.ts(它会写入配置文件,然后执行初始化)。commerce-app-init - 如果配置文件存在但项目未初始化(无或
src/commerce-extensibility-1/),请先运行node_modules再继续。初始化操作是幂等的——它会找到现有配置,跳过交互式提示,安装依赖并生成项目文件。npx @adobe/aio-commerce-lib-app init - 只有当项目具备为TypeScript Commerce配置搭建的TypeScript构建环境(
init+ 根目录webpack-config.cjs)时,才能用TypeScript编写Action,详情见tsconfig.json。否则请用JavaScript编写Action。commerce-app-init - 确保Developer Console工作区已订阅(I/O Events)和
CloudIntegrationSDK(Adobe I/O Events for Adobe Commerce):commerceeventing-
列出当前已订阅的服务:sh
aio console workspace api list --projectName <project> --workspaceName <workspace> --json -
如果任一服务缺失,使用完整的合并服务代码集(现有代码+缺失代码)重新订阅。会替换订阅列表——遗漏当前已订阅的服务会导致其被移除。
aio console workspace api addshaio console workspace api add \ --projectName <project> \ --workspaceName <workspace> \ --service-code <existing-codes>,CloudIntegrationSDK,commerceeventing \ --json如果命令因的“product profile required”失败,请向用户索要配置文件名称并添加commerceeventing参数后重试。--license-config commerceeventing=<profile>
-
Step 1 — Understand intent
步骤1 — 明确需求
Ask whether the user wants to configure Commerce events, external events, or both:
- Commerce events (): native Commerce events. Names follow
eventing.commerceorplugin.<segments>.observer.<segments> - External events (): events from third-party systems (e.g., ERP, CRM). Names are free-form (
eventing.external).[\w\-_.]+
For each event source, gather:
- Provider label, description, and optional key
- For each event: name, label, description, and which runtime action(s) should handle it (format: )
<package>/<action> - For Commerce events only: fields to extract from the event payload (empty array captures the full payload), and any optional filter rules
- Optionally, which Commerce environments the event applies to ()
env
询问用户是否要配置Commerce事件、外部事件,或两者都配置:
- Commerce事件():Commerce原生事件。名称遵循
eventing.commerce或plugin.<segments>格式。observer.<segments> - 外部事件():来自第三方系统(如ERP、CRM)的事件。名称为自由格式(
eventing.external)。[\w\-_.]+
针对每个事件源,收集以下信息:
- 提供商标签、描述及可选的键值
- 每个事件的名称、标签、描述,以及应处理该事件的运行时Action(格式:)
<package>/<action> - 仅针对Commerce事件:从事件负载中提取的字段(空数组表示捕获完整负载),以及可选的过滤规则
- 可选:事件适用的Commerce环境()
env
Step 2 — Derive config values
步骤2 — 推导配置值
Apply the following validation rules before writing the config. Surface any issues to the user before proceeding.
| Field | Constraint |
|---|---|
| Commerce event name | Starts with |
| External event name | |
| Provider label | Max 100 chars |
| Provider description | Max 255 chars |
| Provider key | Optional; alphanumeric + hyphens only; max 50 chars |
| Event label | Max 100 chars |
| Event description | Max 255 chars |
| Field name | |
| Rule operator | |
| Runtime action | |
| Event env (optional) | Non-empty array of |
在写入配置前应用以下验证规则。在继续操作前向用户说明任何问题。
| 字段 | 约束条件 |
|---|---|
| Commerce事件名称 | 以 |
| 外部事件名称 | |
| 提供商标签 | 最大长度100字符 |
| 提供商描述 | 最大长度255字符 |
| 提供商键值 | 可选;仅包含字母数字和连字符;最大长度50字符 |
| 事件标签 | 最大长度100字符 |
| 事件描述 | 最大长度255字符 |
| 字段名称 | |
| 规则运算符 | |
| 运行时Action | |
| 事件环境(可选) | 非空数组,元素为 |
Step 3 — Update app.commerce.config.ts
app.commerce.config.ts步骤3 — 更新app.commerce.config.ts
app.commerce.config.tsAdd or merge and/or into the existing config, preserving all other domains. If the config already has an key, extend it rather than replacing it.
eventing.commerceeventing.externaleventingMinimal example (Commerce event):
ts
eventing: {
commerce: [{
provider: { label: "Commerce Events Provider", description: "..." },
events: [{
name: "plugin.order_placed", // plugin.<segments> or observer.<segments>
label: "Order Placed",
description: "Triggered when a customer places an order.",
fields: [{ name: "order_id" }], // empty array = full payload; Commerce events only
runtimeActions: ["my-package/handle-order-placed"], // <package>/<action>
}],
}],
}See assets/eventing-config.ts for the full reference including external event sources.
将和/或添加或合并到现有配置中,保留所有其他配置域。如果配置中已有键,请扩展它而非替换。
eventing.commerceeventing.externaleventing最简示例(Commerce事件):
ts
eventing: {
commerce: [{
provider: { label: "Commerce Events Provider", description: "..." },
events: [{
name: "plugin.order_placed", // plugin.<segments> or observer.<segments>
label: "Order Placed",
description: "Triggered when a customer places an order.",
fields: [{ name: "order_id" }], // empty array = full payload; Commerce events only
runtimeActions: ["my-package/handle-order-placed"], // <package>/<action>
}],
}],
}完整参考示例(包含外部事件源)请见assets/eventing-config.ts。
Creating the handler action
创建处理程序Action
For events that reference runtime actions via , create the action file under and register it in .
runtimeActionssrc/actions/app.config.yaml对于通过引用运行时Action的事件,需在下创建Action文件并在中注册。
runtimeActionssrc/actions/app.config.yamlRegister the action
注册Action
Add a user-defined package to alongside the existing package. Use any name except (reserved by the framework):
src/commerce-extensibility-1/ext.config.yamlapp-managementapp-managementyaml
undefined在中添加用户自定义包,与现有包并列。包名不能为(框架保留名):
src/commerce-extensibility-1/ext.config.yamlapp-managementapp-managementyaml
undefinedsrc/commerce-extensibility-1/ext.config.yaml
src/commerce-extensibility-1/ext.config.yaml
(add below the auto-generated app-management package)
(添加到自动生成的app-management包下方)
runtimeManifest:
packages:
app-management:
# ... auto-generated — do not edit
my-app: # your package name — any name except "app-management"
actions:
handle-order-placed:
function: actions/handle-order-placed/index.js # relative to src/commerce-extensibility-1/
web: "no"
runtime: nodejs:24
annotations:
require-adobe-auth: false
The `<package>/<action>` format in `runtimeActions` maps directly: `my-app/handle-order-placed` → package `my-app`, action `handle-order-placed`.runtimeManifest:
packages:
app-management:
# ... 自动生成内容 — 请勿编辑
my-app: # 你的包名 — 除"app-management"外的任意名称
actions:
handle-order-placed:
function: actions/handle-order-placed/index.js # 相对于src/commerce-extensibility-1/的路径
web: "no"
runtime: nodejs:24
annotations:
require-adobe-auth: false
`runtimeActions`中的`<package>/<action>`格式直接对应:`my-app/handle-order-placed` → 包`my-app`,Action`handle-order-placed`。Handler skeleton
处理程序骨架
Event handlers receive a CloudEvents-shaped payload. The event data lives in .
params.datatypescript
// src/commerce-extensibility-1/actions/handle-order-placed/index.ts
export async function main(params: Record<string, unknown>) {
const data = params.data as Record<string, unknown>;
// data contains the fields declared in the event's `fields` array
// (or the full payload if fields is empty)
const orderId = data["order_id"];
// process the event ...
return { statusCode: 200, body: { processed: true } };
}事件处理程序接收CloudEvents格式的负载。事件数据位于中。
params.datatypescript
// src/commerce-extensibility-1/actions/handle-order-placed/index.ts
export async function main(params: Record<string, unknown>) {
const data = params.data as Record<string, unknown>;
// data包含事件`fields`数组中声明的字段
// (如果fields为空则包含完整负载)
const orderId = data["order_id"];
// 处理事件...
return { statusCode: 200, body: { processed: true } };
}Step 4 — Validate
步骤4 — 验证
Build the project to confirm the updated config is valid:
sh
aio app buildA build failure with a validation error points directly to the offending config field.
构建项目以确认更新后的配置有效:
sh
aio app build构建失败时的验证错误会直接指向有问题的配置字段。
Common Issues
常见问题
- External event has : The
fieldsproperty is only valid on Commerce events; external events don't support it.fields - format error: Must be
runtimeActions. Both parts are lowercase alphanumeric + hyphens only.<package>/<action> - package name conflict: The framework generates this package in
app-managementon every build. Use any other name for your own actions.ext.config.yaml - Function path is relative to : Do not use
src/commerce-extensibility-1/or project-root-relative paths.src/...resolves correctly;actions/handle-order-placed/index.jsdoes not.src/commerce-extensibility-1/actions/handle-order-placed/index.js - not found: Ensure
defineConfigis installed and@adobe/aio-commerce-lib-appis imported fromdefineConfig.@adobe/aio-commerce-lib-app/config - Build fails on missing action: A runtime action referenced in must exist in the project. Check the action files under
runtimeActionsand create any missing stubs.src/commerce-extensibility-1/actions/
- 外部事件包含属性:
fields属性仅对Commerce事件有效;外部事件不支持该属性。fields - 格式错误:必须为
runtimeActions格式。两部分均只能包含小写字母数字和连字符。<package>/<action> - 包名冲突:框架会在每次构建时在
app-management中生成该包。请使用其他名称命名你的自定义Action。ext.config.yaml - 函数路径需相对于:请勿使用
src/commerce-extensibility-1/或项目根目录相对路径。src/...路径有效;actions/handle-order-placed/index.js路径无效。src/commerce-extensibility-1/actions/handle-order-placed/index.js - 找不到:确保已安装
defineConfig并从@adobe/aio-commerce-lib-app导入@adobe/aio-commerce-lib-app/config。defineConfig - 构建因缺失Action失败:中引用的运行时Action必须存在于项目中。检查
runtimeActions下的Action文件,创建任何缺失的存根文件。src/commerce-extensibility-1/actions/
Quality Bar
质量标准
- completes without errors
aio app build
- 执行完成且无错误
aio app build
Chaining
后续操作
After passes:
aio app build- Add webhook interception — invoke to intercept Commerce operations
commerce-app-webhooks - Add merchant settings — invoke to expose configurable settings in Commerce Admin
commerce-app-business-config - Extend the Admin UI — invoke to add custom columns, mass actions, or menu entries in Commerce Admin
commerce-app-admin-ui - Add persistent storage — invoke to back event handlers with queryable DB storage
commerce-app-storage
aio app build- 添加webhook拦截 — 调用拦截Commerce操作
commerce-app-webhooks - 添加商家设置 — 调用在Commerce Admin中暴露可配置的设置
commerce-app-business-config - 扩展Admin UI — 调用在Commerce Admin中添加自定义列、批量操作或菜单项
commerce-app-admin-ui - 添加持久化存储 — 调用为事件处理程序提供可查询的数据库存储支持
commerce-app-storage
References
参考资料
- assets/eventing-config.ts — Reference config showing both Commerce and external event source shapes
- assets/eventing-config.ts — 展示Commerce和外部事件源结构的参考配置