enonic-webhook-integrator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseEnonic Webhook Integrator
Enonic Webhook集成器
Procedures
操作流程
Step 1: Detect the Enonic XP project
- Execute to locate Enonic XP project roots in the workspace.
node scripts/find-enonic-targets.mjs . - If the script returns an empty array, stop and explain that no Enonic XP project was found.
- If multiple projects are found, ask which project should receive the integration.
- Identify the application key from (
gradle.properties) orappName.build.gradle
Step 2: Determine integration direction
- Classify the task as one of: outbound event listener (XP reacts to internal events and calls an external system), outbound webhook config (XP sends webhook payloads via built-in config), inbound webhook endpoint (XP receives payloads from an external system), or mixed (combination).
- Read to identify the correct event types, listener patterns, and filtering strategies.
references/event-reference.md - Read when the task involves outbound webhook configuration or inbound HTTP service endpoints.
references/webhook-reference.md
Step 3: Implement outbound event listener (if applicable)
- Read as a starting scaffold.
assets/event-listener.template.ts - Register the event listener in the application's (or
main.ts) controller using lib-event'smain.jsfunction.listener() - Use the parameter with a pattern matching the target node events (e.g.,
type,node.pushed,node.created,node.updated).node.deleted - Filter events by path within the callback by checking to restrict processing to the intended content tree.
event.data.nodes[].path - When the listener must call an external HTTP endpoint, use lib-httpClient's function inside the callback or delegate to a background task.
request() - For long-running processing, delegate work from the event callback to a background task using lib-task's to avoid blocking the event thread.
executeFunction() - Read for complete integration patterns including CDN invalidation, search reindexing, and notification dispatch.
references/examples.md
Step 4: Configure outbound webhooks (if applicable)
- Read for the
references/webhook-reference.mdconfiguration format.com.enonic.xp.webhooks.cfg - Create or update the file at with webhook entries specifying the target URL and event types.
XP_HOME/config/com.enonic.xp.webhooks.cfg - Validate that the configured event types match the intended content lifecycle events.
- Use HTTPS URLs for webhook targets.
- Never write actual secret values into configuration files or source code. Use descriptive placeholder tokens (e.g., ) and instruct the operator to substitute real credentials out-of-band. Secrets must be managed by the operator through secure deployment pipelines, environment variables, or secret management tools—not committed to files.
REPLACE_WITH_CDN_SECRET
Step 5: Implement inbound webhook endpoint (if applicable)
- Read as a starting scaffold.
assets/http-service.template.ts - Create an HTTP service controller at .
src/main/resources/services/<serviceName>/<serviceName>.ts - Export a function that parses the incoming JSON payload from
post(req).req.body - Reject payloads exceeding a reasonable size limit (e.g., 1 MB) before parsing.
- Validate the inbound payload by checking required fields, authentication headers, or HMAC signatures before processing.
- Sanitize all string fields from the external payload before using them in content operations: trim whitespace, enforce maximum lengths, strip or escape HTML/script content, and reject values containing path traversal sequences (,
..,/).\ - Use an allowlist of expected field names rather than passing the raw payload object to content APIs.
- Return appropriate HTTP status codes: for success,
200for malformed payloads,400for authentication failures,401for oversized payloads,413for unexpected errors.500 - When inbound payloads trigger content creation or modification, use lib-content or lib-node APIs within a context run to ensure proper permissions. Never pass unsanitized external values as content names, paths, or keys.
Step 6: Wire async processing with lib-task (if applicable)
- When event handling or webhook processing requires heavy or time-consuming work, wrap it in from lib-task.
executeFunction() - Report progress from long-running tasks using to allow monitoring.
progress() - Read for the task event lifecycle (
references/event-reference.md,task.submitted,task.updated,task.finished).task.failed
Step 7: Validate the integration
- Execute to confirm the project still resolves correctly.
node scripts/find-enonic-targets.mjs . - Verify that the event listener registration is in the application's or
main.tsfile, which runs at application startup.main.js - Confirm that outbound HTTP calls use HTTPS and include error handling for network failures and non-2xx responses.
- Confirm that no actual secret values, API keys, or credentials appear in generated source code or configuration files—only placeholder tokens.
- Confirm that inbound webhook endpoints sanitize and allowlist all fields from external payloads before passing them to content APIs.
- If a webhook config file was created, confirm the event type patterns match the intended triggers.
- Run the workspace build to verify no compilation errors.
- Read when events do not fire, webhook deliveries fail, or inbound requests are rejected.
references/troubleshooting.md
步骤1:检测Enonic XP项目
- 执行定位工作区中的Enonic XP项目根目录。
node scripts/find-enonic-targets.mjs . - 如果脚本返回空数组,停止操作并说明未找到Enonic XP项目。
- 如果找到多个项目,询问需要集成的目标项目。
- 从(
gradle.properties字段)或appName中识别应用密钥。build.gradle
步骤2:确定集成方向
- 将任务归类为以下类型之一:出站事件监听器(XP响应内部事件并调用外部系统)、出站webhook配置(XP通过内置配置发送webhook payload)、入站webhook端点(XP接收外部系统发送的payload),或混合模式(多种类型组合)。
- 阅读确定正确的事件类型、监听器模式和过滤策略。
references/event-reference.md - 如果任务涉及出站webhook配置或入站HTTP服务端点,阅读。
references/webhook-reference.md
步骤3:实现出站事件监听器(如适用)
- 参考作为初始脚手架。
assets/event-listener.template.ts - 使用lib-event的函数在应用的
listener()(或main.ts)控制器中注册事件监听器。main.js - 在参数中使用匹配目标节点事件的模式(例如
type、node.pushed、node.created、node.updated)。node.deleted - 在回调函数中通过检查按路径过滤事件,将处理范围限制在目标内容树内。
event.data.nodes[].path - 当监听器需要调用外部HTTP端点时,可在回调函数内使用lib-httpClient的函数,或委托给后台任务处理。
request() - 对于长时间运行的处理流程,使用lib-task的将工作从事件回调委托给后台任务,避免阻塞事件线程。
executeFunction() - 阅读查看完整集成模式,包括CDN失效、搜索索引重建和通知分发。
references/examples.md
步骤4:配置出站webhook(如适用)
- 阅读了解
references/webhook-reference.md的配置格式。com.enonic.xp.webhooks.cfg - 创建或更新文件,添加指定目标URL和事件类型的webhook条目。
XP_HOME/config/com.enonic.xp.webhooks.cfg - 验证配置的事件类型与预期的内容生命周期事件匹配。
- webhook目标使用HTTPS URL。
- 切勿将实际的密钥值写入配置文件或源代码中。 使用描述性的占位符(例如),并提示运维人员通过线下方式替换为真实凭证。密钥必须由运维人员通过安全部署流水线、环境变量或密钥管理工具进行管理,不得提交到文件中。
REPLACE_WITH_CDN_SECRET
步骤5:实现入站webhook端点(如适用)
- 参考作为初始脚手架。
assets/http-service.template.ts - 在路径下创建HTTP服务控制器。
src/main/resources/services/<serviceName>/<serviceName>.ts - 导出函数,从
post(req)中解析传入的JSON payload。req.body - 解析前拒绝超过合理大小限制(例如1 MB)的payload。
- 处理前通过校验必填字段、鉴权头或HMAC签名验证入站payload的合法性。
- 在内容操作中使用外部payload的字符串字段前进行安全处理:去除首尾空格、强制最大长度、剥离或转义HTML/script内容,拒绝包含路径遍历序列(、
..、/)的值。\ - 使用预期字段名白名单,不要将原始payload对象直接传递给内容API。
- 返回合适的HTTP状态码:成功返回、payload格式错误返回
200、鉴权失败返回400、payload过大返回401、意外错误返回413。500 - 当入站payload触发内容创建或修改时,在上下文运行环境中使用lib-content或lib-node API确保权限正确。切勿将未经过滤的外部值作为内容名称、路径或键使用。
步骤6:通过lib-task连接异步处理(如适用)
- 当事件处理或webhook处理需要繁重或耗时的工作时,将其封装在lib-task的中。
executeFunction() - 长时间运行的任务使用上报进度,方便监控。
progress() - 阅读了解任务事件生命周期(
references/event-reference.md、task.submitted、task.updated、task.finished)。task.failed
步骤7:验证集成
- 执行确认项目仍可正常解析。
node scripts/find-enonic-targets.mjs . - 验证事件监听器已注册在应用启动时运行的或
main.ts文件中。main.js - 确认出站HTTP调用使用HTTPS协议,且包含网络失败和非2xx响应的错误处理逻辑。
- 确认生成的源代码或配置文件中没有实际的密钥、API密钥或凭证,仅包含占位符。
- 确认入站webhook端点在将外部payload的字段传递给内容API前,已完成字段过滤和白名单校验。
- 如果创建了webhook配置文件,确认事件类型模式与预期触发条件匹配。
- 运行工作区构建验证无编译错误。
- 当事件未触发、webhook投递失败或入站请求被拒绝时,阅读。
references/troubleshooting.md
Error Handling
错误处理
- If finds no projects, confirm that
node scripts/find-enonic-targets.mjs .referencesbuild.gradleplugins or that acom.enonic.xpdirectory exists.src/main/resources/site/ - If events do not fire after registering a listener, read to check listener registration location, event type patterns, and cluster vs. local event scope.
references/troubleshooting.md - If outbound HTTP calls fail, verify the target URL, network access from the XP instance, and that the operator has substituted placeholder tokens with real credentials.
- If inbound webhook requests return 404, confirm the service controller path follows and the application is deployed.
services/<name>/<name>.ts - If background tasks fail silently, check task state using and inspect logs for errors within the task function.
taskLib.list()
- 如果未找到任何项目,确认
node scripts/find-enonic-targets.mjs .引用了build.gradle插件,或存在com.enonic.xp目录。src/main/resources/site/ - 如果注册监听器后事件未触发,阅读检查监听器注册位置、事件类型模式以及集群与本地事件作用域的差异。
references/troubleshooting.md - 如果出站HTTP调用失败,验证目标URL、XP实例的网络访问权限,以及运维人员是否已将占位符替换为真实凭证。
- 如果入站webhook请求返回404,确认服务控制器路径遵循格式,且应用已部署。
services/<name>/<name>.ts - 如果后台任务静默失败,使用检查任务状态,并查看日志中任务函数内的错误信息。
taskLib.list()