fynd-extension
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseFynd Extension (FDK) — Rules and context for the AI
Fynd扩展(FDK)——AI参考的规则与上下文
When working on a Fynd extension codebase, follow these rules and use this context so your suggestions stay correct and consistent with FDK.
在开发Fynd扩展代码库时,请遵循以下规则并参考此上下文,确保您的建议符合FDK的规范且保持一致性。
Rules (always apply)
规则(始终适用)
-
Company context: Every Fynd Platform API call must be scoped to a company. Always obtainfrom the request (
companyIdheader,x-company-idin query/body, or your DB) and usecompany_id— never call platform APIs without a company-scoped client.getPlatformClient(companyId) -
Route mount order: Custom webhooks and extension API routes must be mounted before. If you add a new route, place it before the FDK handler in the server file so it is not swallowed by the catch-all.
fdkExtension.fdkHandler -
Fynd API access: Use onlyto get a client for Fynd Platform APIs (catalog, order, application, etc.). Do not construct API clients manually.
fdkExtension.getPlatformClient(companyId) -
Webhook handlers (Fynd → extension): Handlers registered inmust have the signature
webhook_config.event_map. Always use(event_name, request_body, company_id, application_id)andcompany_idto scope any DB writes or API calls inside the handler.application_id -
Inbound webhooks (external → extension): Any POST route that receives callbacks from an external system must be mounted before the FDK handler. Resolvefrom the payload or your DB before calling
companyId; if you cannot resolve it, return 4xx and do not call Fynd APIs.getPlatformClient(companyId) -
Extension-owned entities: When listing or returning platform entities that belong to an extension (e.g. schemes, accounts), always filter byso only this extension’s resources are shown.
extension_id === process.env.EXTENSION_API_KEY -
Backend entrypoint: FDK is configured in a single backend module (e.g.) via
backend/fdk.js. The server mountssetupFdk(),fdkHandler,platformApiRoutes, and the webhook route; do not duplicate FDK setup or mount the same paths twice.partnerApiRoutes
-
**企业上下文:**所有Fynd Platform API调用都必须限定在单个企业的作用域内。务必从请求中获取(来自
companyId请求头、查询参数/请求体中的x-company-id,或您的数据库),并使用company_id——绝对不能在没有企业作用域客户端的情况下调用平台API。getPlatformClient(companyId) -
**路由挂载顺序:**自定义webhooks和扩展API路由必须在之前挂载。如果您添加新路由,请将其放在服务器文件中的FDK处理程序之前,避免被兜底的捕获逻辑覆盖。
fdkExtension.fdkHandler -
**Fynd API访问:**仅使用获取Fynd Platform APIs(目录、订单、应用等)的客户端。请勿手动构建API客户端。
fdkExtension.getPlatformClient(companyId) -
**Webhook处理程序(Fynd → 扩展):**在中注册的处理程序必须符合签名
webhook_config.event_map。处理程序内部的所有数据库写入或API调用,都必须使用(event_name, request_body, company_id, application_id)和company_id限定作用域。application_id -
**入站Webhook(外部 → 扩展):**所有接收外部系统回调的POST路由必须在FDK处理程序之前挂载。在调用之前,务必从负载或数据库中解析出
getPlatformClient(companyId);如果无法解析,请返回4xx状态码,且不要调用Fynd APIs。companyId -
**扩展自有实体:**当列出或返回属于某个扩展的平台实体(如方案、账户)时,必须始终通过进行过滤,确保只显示当前扩展的资源。
extension_id === process.env.EXTENSION_API_KEY -
**后端入口:**FDK在单个后端模块(如)中通过
backend/fdk.js进行配置。服务器会挂载setupFdk()、fdkHandler、platformApiRoutes和webhook路由;请勿重复配置FDK,也不要重复挂载相同的路径。partnerApiRoutes
Quick context
快速上下文
- FDK module: Exports ,
fdkHandler,getPlatformClient(companyId),platformApiRoutes,partnerApiRoutes. Use the same instance everywhere.webhookRegistry - Routers: Platform routes (e.g. catalog) under ; partner routes under
/api; extension-specific routes under/apipartneror your own prefix. All need/apibasicandcompanyIdwhen calling Fynd.getPlatformClient(companyId) - Event names and payloads: Depend on extension type. Refer to Fynd Partner docs when adding or debugging webhooks.
- **FDK模块:**导出、
fdkHandler、getPlatformClient(companyId)、platformApiRoutes、partnerApiRoutes。请在所有地方使用同一个实例。webhookRegistry - **路由:**平台路由(如目录)位于下;合作伙伴路由位于
/api下;扩展专属路由位于/apipartner或您自定义的前缀下。调用Fynd API时,所有路由都需要/apibasic和companyId。getPlatformClient(companyId) - **事件名称与负载:**取决于扩展类型。添加或调试webhooks时,请参考Fynd合作伙伴文档。
When adding or changing behavior
添加或修改行为时的注意事项
- New API route: Add a router in the backend, mount it in the server before the FDK handler; in the route, read (e.g. from
companyId), callx-company-id, then call Fynd APIs.getPlatformClient(companyId) - New Fynd webhook: Add the event to in the FDK module with
webhook_config.event_map; implement the handler with signature{ handler, version }.(event_name, request_body, company_id, application_id) - New inbound webhook: Add a POST route and mount it before ; in the handler, resolve
fdkHandler, thencompanyIdand Fynd APIs as needed.getPlatformClient(companyId) - Extension-specific logic: Attach to the appropriate router (platform/partner/basic); when returning lists from the platform that are extension-scoped, filter by .
extension_id === process.env.EXTENSION_API_KEY
- 新增API路由:在后端添加一个路由,并在服务器中于FDK处理程序之前挂载该路由;在路由逻辑中,读取(例如来自
companyId请求头),调用x-company-id,然后再调用Fynd APIs。getPlatformClient(companyId) - **新增Fynd Webhook:**在FDK模块的中添加事件,配置
webhook_config.event_map;处理程序必须符合签名{ handler, version }。(event_name, request_body, company_id, application_id) - **新增入站Webhook:**添加一个POST路由并在之前挂载;在处理程序中解析出
fdkHandler,然后根据需要调用companyId和Fynd APIs。getPlatformClient(companyId) - **扩展专属逻辑:**将逻辑附加到对应的路由(平台/合作伙伴/基础路由);当从平台返回属于扩展作用域的列表时,请通过进行过滤。
extension_id === process.env.EXTENSION_API_KEY
References (load when needed)
参考资料(按需查阅)
- references/fdk-setup.md — FDK setup rules, env vars, route order.
- references/webhooks.md — Webhook registration and inbound webhook rules.
- references/extension-patterns.md — Rules by extension type (catalog, platform-scoped, custom).
- references/fdk-setup.md — FDK配置规则、环境变量、路由顺序。
- references/webhooks.md — Webhook注册与入站Webhook规则。
- references/extension-patterns.md — 按扩展类型分类的规则(目录型、平台作用域型、自定义型)。