npx skills add https://github.com/wix/skills --skill wix-cli-service-plugin为 Wix CLI 应用程序创建服务插件扩展。服务插件是 Wix 定义的一组 API,您可以使用它们将自定义逻辑注入到 Wix 业务解决方案的现有后端流程中,或者为 Wix 站点引入全新的流程。
当您实现一个服务插件时,Wix 会在特定流程中调用您的自定义函数。常见的用例包括电子商务定制(运费、费用、税费、验证)和预订定制(员工排序),但服务插件可以扩展任何公开了 SPI 的 Wix 业务解决方案。
创建服务插件时,请按顺序遵循以下步骤:
src/extensions/backend/service-plugins/<service-type>/<plugin-name>/plugin.ts 文件,包含正确的导入和 provideHandlers() 调用extensions.ts 文件,包含适当的构建器方法和唯一的 UUIDsrc/extensions.ts 文件以导入和使用新的扩展npx tsc --noEmit 以验证 TypeScript 编译广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
npx wix build 以验证构建成功在实现相关 SPI 之前,您必须阅读相关的参考文档。 每个参考文档都包含正确的导入、处理函数签名、响应结构和工作示例。
| SPI 类型 | 参考文档 |
|---|---|
| 附加费用 | ADDITIONAL-FEES.md |
| 折扣触发器 | DISCOUNT-TRIGGERS.md |
| 礼品卡 | GIFT-CARDS.md |
| 运费 | SHIPPING-RATES.md |
| 税费计算 | TAX-CALCULATION.md |
| 验证 | VALIDATIONS.md |
| 预订员工排序 | BOOKINGS-STAFF-SORTING.md |
服务插件由两个协同工作的文件组成。插件的注册需要一个扩展构建器文件。
src/extensions/backend/service-plugins/
└── {service-type}/
└── {plugin-name}/
├── plugin.ts # 包含 `provideHandlers()` 的处理逻辑
└── extensions.ts # 构建器配置(id、name、source)
| 文件 | 用途 |
|---|---|
plugin.ts | 包含服务插件处理逻辑,使用 provideHandlers() - 这是您实现自定义业务逻辑的地方 |
extensions.ts | 包含服务插件构建器配置,包括 id(GUID)、name、source 路径以及构建器特定的可选字段 |
所有服务插件必须包含全面的数据验证:
处理文件 (plugin.ts) 包含服务插件逻辑。它必须:
@wix/ecom/service-plugins,预订使用 @wix/bookings/service-plugins)provideHandlers() 并传入一个包含处理函数的对象request 和 metadata 的 payloadimport { shippingRates } from "@wix/ecom/service-plugins";
shippingRates.provideHandlers({
getShippingRates: async (payload) => {
const { request, metadata } = payload;
// 基于请求数据实现自定义逻辑
// - request 包含购物车商品、收货地址等
// - metadata 包含货币、语言环境等
return {
shippingRates: [
{
code: "custom-shipping",
title: "Custom Shipping",
logistics: {
deliveryTime: "3-5 business days",
},
cost: {
price: "9.99",
currency: metadata.currency || "USD",
},
},
],
};
},
});
当相关的站点操作触发时,Wix 会自动调用处理函数。您的自定义逻辑应放置在每个处理函数内部。
从服务插件调用 Wix API 时,必须使用 @wix/essentials 中的 auth.elevate 来提升权限。
import { auth } from "@wix/essentials";
import { items } from "@wix/data";
export const myFunction = async () => {
const elevatedFunction = auth.elevate(items.query);
const elevatedResponse = await elevatedFunction("myCollection");
return elevatedResponse;
};
import { auth } from "@wix/essentials";
import { cart } from "@wix/ecom";
export const myFunction = async () => {
const elevatedFunction = auth.elevate(cart.getCart);
const elevatedResponse = await elevatedFunction("cart-id");
return elevatedResponse;
};
import { auth } from "@wix/essentials";
import { products } from "@wix/stores";
export const myFunction = async () => {
const elevatedFunction = auth.elevate(products.deleteCollection);
const elevatedResponse = await elevatedFunction("collection-id");
return elevatedResponse;
};
扩展注册是强制性的,并且需要两个步骤。
每个服务插件都需要在其文件夹中创建一个 extensions.ts 文件,其中包含适用于该 SPI 类型的适当构建器方法:
import { extensions } from "@wix/astro/builders";
export const ecomadditionalfeesMyFees = extensions.ecomAdditionalFees({
id: "{{GENERATE_UUID}}",
name: "My Additional Fees",
source: "./extensions/backend/service-plugins/ecom-additional-fees/my-fees/plugin.ts",
});
关键:UUID 生成
id 必须是一个唯一的、静态的 UUID v4 字符串。为每个扩展生成一个新的 UUID - 请勿使用 randomUUID() 或从示例中复制 UUID。将 {{GENERATE_UUID}} 替换为新生成的 UUID,例如 "a1b2c3d4-e5f6-7890-abcd-ef1234567890"。
所有构建器方法都接受以下三个字段:
| 字段 | 类型 | 描述 |
|---|---|---|
id | string | 服务插件 ID,作为 GUID。在项目的所有扩展中必须是唯一的。 |
name | string | 服务插件名称(在开发应用时显示在应用仪表板中)。 |
source | string | 指向包含插件逻辑的服务插件处理文件的路径。 |
按 SPI 类型划分的构建器方法及其接受的字段:
| SPI 类型 | 构建器方法 | 接受的字段 |
|---|---|---|
| 运费 | ecomShippingRates() | id, name, source, description, learnMoreUrl, dashboardUrl, fallbackDefinitionMandatory, thumbnailUrl |
| 附加费用 | ecomAdditionalFees() | id, name, source |
| 验证 | ecomValidations() | id, name, source, validateInCart |
| 折扣触发器 | ecomDiscountTriggers() | id, name, source |
| 礼品卡 | ecomGiftCards() | id, name, source |
| 支付设置 | ecomPaymentSettings() | id, name, source, fallbackValueForRequires3dSecure |
| 预订员工排序 | bookingsStaffSortingProvider() | id, name, source, methodName, methodDescription, dashboardPluginId |
只有 ecomShippingRates() 接受 description 字段。将不支持的字段传递给其他构建器会导致 TypeScript 错误。bookingsStaffSortingProvider() 需要 methodName 和 methodDescription 字段,并可选择性地接受 dashboardPluginId。
关键: 创建插件特定的扩展文件后,您必须阅读 wix-cli-extension-registration 并按照“应用注册”部分更新 src/extensions.ts。
如果不完成步骤 2,服务插件将不会在电子商务系统中激活。
要测试您的服务插件扩展:
每周安装次数
188
代码仓库
GitHub 星标数
3
首次出现
2026年1月26日
安全审计
安装于
opencode166
cursor92
codex87
gemini-cli85
github-copilot81
kimi-cli77
Creates service plugin extensions for Wix CLI applications. Service plugins are a set of APIs defined by Wix that you can use to inject custom logic into the existing backend flows of Wix business solutions or to introduce entirely new flows to Wix sites.
When you implement a service plugin, Wix calls your custom functions during specific flows. Common use cases include eCommerce customization (shipping, fees, taxes, validations) and Bookings customization (staff sorting), but service plugins can extend any Wix business solution that exposes SPIs.
Follow these steps in order when creating a service plugin:
src/extensions/backend/service-plugins/<service-type>/<plugin-name>/plugin.ts with correct imports and provideHandlers() callextensions.ts with appropriate builder method and unique UUIDsrc/extensions.ts to import and use the new extensionnpx tsc --noEmit to verify TypeScript compilesnpx wix build to verify build succeedsYou MUST read the relevant reference document before implementing a relevant SPI. Each reference contains the correct imports, handler signatures, response structures, and working examples.
| SPI Type | Reference |
|---|---|
| Additional Fees | ADDITIONAL-FEES.md |
| Discount Triggers | DISCOUNT-TRIGGERS.md |
| Gift Cards | GIFT-CARDS.md |
| Shipping Rates | SHIPPING-RATES.md |
| Tax Calculation | TAX-CALCULATION.md |
| Validations | VALIDATIONS.md |
| Bookings Staff Sorting | BOOKINGS-STAFF-SORTING.md |
Service plugins consist of two files that work together. Registration of plugins requires an extension builder file.
src/extensions/backend/service-plugins/
└── {service-type}/
└── {plugin-name}/
├── plugin.ts # Handler logic with provideHandlers()
└── extensions.ts # Builder configuration (id, name, source)
| File | Purpose |
|---|---|
plugin.ts | Contains the service plugin handler logic with provideHandlers() - this is where you implement your custom business logic |
extensions.ts | Contains the service plugin builder configuration with id (GUID), name, source path, and builder-specific optional fields |
All service plugins must include comprehensive data validation:
The handler file (plugin.ts) contains the service plugin logic. It must:
@wix/ecom/service-plugins for eCommerce, @wix/bookings/service-plugins for Bookings)provideHandlers() with an object containing handler functionsrequest and metadataimport { shippingRates } from "@wix/ecom/service-plugins";
shippingRates.provideHandlers({
getShippingRates: async (payload) => {
const { request, metadata } = payload;
// Implement custom logic based on request data
// - request contains cart items, shipping address, etc.
// - metadata contains currency, locale, etc.
return {
shippingRates: [
{
code: "custom-shipping",
title: "Custom Shipping",
logistics: {
deliveryTime: "3-5 business days",
},
cost: {
price: "9.99",
currency: metadata.currency || "USD",
},
},
],
};
},
});
Handler functions are called automatically by Wix when the relevant site action triggers them. Your custom logic should be placed inside each handler function.
When making Wix API calls from service plugins, you must elevate permissions using auth.elevate from @wix/essentials.
import { auth } from "@wix/essentials";
import { items } from "@wix/data";
export const myFunction = async () => {
const elevatedFunction = auth.elevate(items.query);
const elevatedResponse = await elevatedFunction("myCollection");
return elevatedResponse;
};
import { auth } from "@wix/essentials";
import { cart } from "@wix/ecom";
export const myFunction = async () => {
const elevatedFunction = auth.elevate(cart.getCart);
const elevatedResponse = await elevatedFunction("cart-id");
return elevatedResponse;
};
import { auth } from "@wix/essentials";
import { products } from "@wix/stores";
export const myFunction = async () => {
const elevatedFunction = auth.elevate(products.deleteCollection);
const elevatedResponse = await elevatedFunction("collection-id");
return elevatedResponse;
};
Extension registration is MANDATORY and has TWO required steps.
Each service plugin requires an extensions.ts file in its folder with the appropriate builder method for the SPI type:
import { extensions } from "@wix/astro/builders";
export const ecomadditionalfeesMyFees = extensions.ecomAdditionalFees({
id: "{{GENERATE_UUID}}",
name: "My Additional Fees",
source: "./extensions/backend/service-plugins/ecom-additional-fees/my-fees/plugin.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".
All builder methods accept these three fields:
| Field | Type | Description |
|---|---|---|
id | string | Service plugin ID as a GUID. Must be unique across all extensions in the project. |
name | string | The service plugin name (visible in app dashboard when developing an app). |
source | string | Path to the service plugin handler file that contains the plugin logic. |
Builder methods by SPI type and their accepted fields:
| SPI Type | Builder Method | Accepted Fields |
|---|---|---|
| Shipping Rates | ecomShippingRates() | id, name, source, description, learnMoreUrl, dashboardUrl, fallbackDefinitionMandatory, thumbnailUrl |
Only ecomShippingRates() accepts description. Passing unsupported fields to other builders causes TypeScript errors. bookingsStaffSortingProvider() requires methodName and methodDescription fields, and optionally accepts dashboardPluginId.
CRITICAL: After creating the plugin-specific extension file, you MUST read wix-cli-extension-registration and follow the "App Registration" section to update src/extensions.ts.
Without completing Step 2, the service plugin will not be active in the eCommerce system.
To test your service plugin extension:
Weekly Installs
188
Repository
GitHub Stars
3
First Seen
Jan 26, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode166
cursor92
codex87
gemini-cli85
github-copilot81
kimi-cli77
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
150,000 周安装
Appwrite PHP SDK 使用指南 - 快速集成后端云服务(用户、数据库、存储)
1 周安装
Seedance提示词设计器:AI视频生成提示词优化工具,多模态素材智能整合
186 周安装
Cherry Studio 自动化发布工具:prepare-release 技能详解与使用指南
16 周安装
GitHub PR 创建助手 - 自动化生成符合模板的 Pull Request
18 周安装
项目管理与产品需求分析技能 - PRD编写、敏捷开发、任务分解、风险管理
187 周安装
GCP Cloud Run 完全指南:无服务器容器部署、最佳实践与快速入门教程
187 周安装
| Additional Fees | ecomAdditionalFees() | id, name, source |
| Validations | ecomValidations() | id, name, source, validateInCart |
| Discount Triggers | ecomDiscountTriggers() | id, name, source |
| Gift Cards | ecomGiftCards() | id, name, source |
| Payment Settings | ecomPaymentSettings() | id, name, source, fallbackValueForRequires3dSecure |
| Bookings Staff Sorting | bookingsStaffSortingProvider() | id, name, source, methodName, methodDescription, dashboardPluginId |