@wix/agent-skills 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +111 -0
- package/package.json +29 -0
- package/skills/wix-app/SKILL.md +344 -0
- package/skills/wix-app/references/APP_IDENTIFIERS.md +35 -0
- package/skills/wix-app/references/APP_MARKET_REVIEW.md +311 -0
- package/skills/wix-app/references/APP_VALIDATION.md +171 -0
- package/skills/wix-app/references/BACKEND_API.md +233 -0
- package/skills/wix-app/references/BACKEND_EVENT.md +116 -0
- package/skills/wix-app/references/CODE_QUALITY.md +33 -0
- package/skills/wix-app/references/CUSTOM_ELEMENT_WIDGET.md +587 -0
- package/skills/wix-app/references/DASHBOARD_MENU_PLUGIN.md +157 -0
- package/skills/wix-app/references/DASHBOARD_MODAL.md +283 -0
- package/skills/wix-app/references/DASHBOARD_PAGE.md +403 -0
- package/skills/wix-app/references/DASHBOARD_PLUGIN.md +205 -0
- package/skills/wix-app/references/DATA_COLLECTION.md +451 -0
- package/skills/wix-app/references/DOCUMENTATION.md +42 -0
- package/skills/wix-app/references/EDITOR_REACT_COMPONENT.md +65 -0
- package/skills/wix-app/references/EMBEDDED_SCRIPT.md +468 -0
- package/skills/wix-app/references/EXTENSION_REGISTRATION.md +96 -0
- package/skills/wix-app/references/SERVICE_PLUGIN.md +235 -0
- package/skills/wix-app/references/SITE_PLUGIN.md +436 -0
- package/skills/wix-app/references/STORES_VERSIONING.md +334 -0
- package/skills/wix-app/references/backend-event/COMMON-EVENTS.md +84 -0
- package/skills/wix-app/references/custom-element-widget/SETTINGS_PANEL.md +345 -0
- package/skills/wix-app/references/dashboard-menu-plugin/blog-slots.md +71 -0
- package/skills/wix-app/references/dashboard-menu-plugin/bookings-slots.md +58 -0
- package/skills/wix-app/references/dashboard-menu-plugin/crm-slots.md +8 -0
- package/skills/wix-app/references/dashboard-menu-plugin/ecommerce-slots.md +17 -0
- package/skills/wix-app/references/dashboard-menu-plugin/events-slots.md +29 -0
- package/skills/wix-app/references/dashboard-menu-plugin/restaurants-slots.md +27 -0
- package/skills/wix-app/references/dashboard-menu-plugin/stores-slots.md +35 -0
- package/skills/wix-app/references/dashboard-page/API_SPEC.md +138 -0
- package/skills/wix-app/references/dashboard-page/DASHBOARD_API.md +573 -0
- package/skills/wix-app/references/dashboard-page/DYNAMIC_PARAMETERS.md +269 -0
- package/skills/wix-app/references/dashboard-page/ECOM_NAVIGATION.md +164 -0
- package/skills/wix-app/references/dashboard-plugin/SLOTS.md +294 -0
- package/skills/wix-app/references/data-collection/WIX_DATA.md +270 -0
- package/skills/wix-app/references/data-collection/extension-template.ts +107 -0
- package/skills/wix-app/references/editor-react-component/ACCESSIBILITY.md +138 -0
- package/skills/wix-app/references/editor-react-component/COMPONENT-API.md +454 -0
- package/skills/wix-app/references/editor-react-component/COMPONENT-CONFIGURATION.md +165 -0
- package/skills/wix-app/references/editor-react-component/CSS-GUIDELINES.md +576 -0
- package/skills/wix-app/references/editor-react-component/DIRECTIONALITY.md +170 -0
- package/skills/wix-app/references/editor-react-component/EDIT-FLOW.md +6 -0
- package/skills/wix-app/references/editor-react-component/PARTS.md +25 -0
- package/skills/wix-app/references/editor-react-component/PROPS-VS-CSS.md +203 -0
- package/skills/wix-app/references/editor-react-component/REACT-GUIDELINES.md +167 -0
- package/skills/wix-app/references/editor-react-component/REACT-PATTERNS.md +137 -0
- package/skills/wix-app/references/service-plugin/ADDITIONAL-FEES.md +112 -0
- package/skills/wix-app/references/service-plugin/BOOKINGS-STAFF-SORTING.md +118 -0
- package/skills/wix-app/references/service-plugin/DISCOUNT-TRIGGERS.md +87 -0
- package/skills/wix-app/references/service-plugin/GIFT-CARDS.md +86 -0
- package/skills/wix-app/references/service-plugin/PAYMENT-SETTINGS.md +135 -0
- package/skills/wix-app/references/service-plugin/SHIPPING-RATES.md +79 -0
- package/skills/wix-app/references/service-plugin/VALIDATIONS.md +68 -0
- package/skills/wix-app/references/site-plugin/EXAMPLES.md +311 -0
- package/skills/wix-app/references/site-plugin/SLOTS.md +263 -0
- package/skills/wix-design-system/SKILL.md +129 -0
- package/skills/wix-design-system/references/file-structure.md +56 -0
- package/skills/wix-design-system/scripts/wds.cjs +531 -0
- package/skills/wix-headless/SKILL.md +418 -0
- package/skills/wix-headless/references/DISCOVERY.md +332 -0
- package/skills/wix-headless/references/ORCHESTRATION.md +269 -0
- package/skills/wix-headless/references/SETUP.md +154 -0
- package/skills/wix-headless/references/blog/BLOG_CONTENT.md +152 -0
- package/skills/wix-headless/references/blog/BLOG_PAGES.md +299 -0
- package/skills/wix-headless/references/blog/BLOG_SETUP.md +218 -0
- package/skills/wix-headless/references/blog/INSTRUCTIONS.md +32 -0
- package/skills/wix-headless/references/cms/CMS_FOUNDATIONS.md +373 -0
- package/skills/wix-headless/references/cms/FAQ_KNOWLEDGE_BASE.md +229 -0
- package/skills/wix-headless/references/cms/INSTRUCTIONS.md +40 -0
- package/skills/wix-headless/references/cms/PORTFOLIO.md +454 -0
- package/skills/wix-headless/references/cms/RESOURCE_LIBRARY.md +356 -0
- package/skills/wix-headless/references/cms/TEAM_DIRECTORY.md +299 -0
- package/skills/wix-headless/references/commands/install-app.md +42 -0
- package/skills/wix-headless/references/commands/known-apps.json +5 -0
- package/skills/wix-headless/references/commands/mcp-bootstrap.md +28 -0
- package/skills/wix-headless/references/designer/INSTRUCTIONS.md +828 -0
- package/skills/wix-headless/references/ecom/CART_PAGES.md +120 -0
- package/skills/wix-headless/references/ecom/CART_WIRING.md +103 -0
- package/skills/wix-headless/references/ecom/COMPONENTS_CSS.md +132 -0
- package/skills/wix-headless/references/ecom/INSTRUCTIONS.md +59 -0
- package/skills/wix-headless/references/forms/CONTACT_FORM.md +477 -0
- package/skills/wix-headless/references/forms/INSTRUCTIONS.md +43 -0
- package/skills/wix-headless/references/gift-cards/COMPONENTS.md +119 -0
- package/skills/wix-headless/references/gift-cards/INSTRUCTIONS.md +51 -0
- package/skills/wix-headless/references/gift-cards/PAGES.md +129 -0
- package/skills/wix-headless/references/images/INSTRUCTIONS.md +359 -0
- package/skills/wix-headless/references/shared/BUILD_NOISE.md +8 -0
- package/skills/wix-headless/references/shared/IMAGE_GENERATION.md +185 -0
- package/skills/wix-headless/references/shared/IMPLEMENTER.md +155 -0
- package/skills/wix-headless/references/shared/MCP_PREFIX.md +105 -0
- package/skills/wix-headless/references/shared/PRODUCTION_SHARP_EDGES.md +97 -0
- package/skills/wix-headless/references/shared/RETURN_CONTRACT.md +423 -0
- package/skills/wix-headless/references/shared/STYLING.md +117 -0
- package/skills/wix-headless/references/stores/BACK_IN_STOCK.md +178 -0
- package/skills/wix-headless/references/stores/CATEGORY_PAGES.md +86 -0
- package/skills/wix-headless/references/stores/COMPONENTS_CSS.md +129 -0
- package/skills/wix-headless/references/stores/HOME_AND_NAV.md +227 -0
- package/skills/wix-headless/references/stores/INSTRUCTIONS.md +96 -0
- package/skills/wix-headless/references/stores/PRODUCT_CATALOG_DATA.md +249 -0
- package/skills/wix-headless/references/stores/PRODUCT_PAGES.md +213 -0
- package/skills/wix-headless/references/stores/SHARED_WIRING.md +164 -0
- package/skills/wix-headless/references/verticals/_schema.json +160 -0
- package/skills/wix-headless/references/verticals/_schema.md +185 -0
- package/skills/wix-headless/references/verticals/blog.md +125 -0
- package/skills/wix-headless/references/verticals/cms.md +121 -0
- package/skills/wix-headless/references/verticals/ecom.md +96 -0
- package/skills/wix-headless/references/verticals/forms.md +106 -0
- package/skills/wix-headless/references/verticals/gift-cards.md +121 -0
- package/skills/wix-headless/references/verticals/stores.md +167 -0
- package/skills/wix-headless/scripts/check-manifest.mjs +198 -0
- package/skills/wix-headless/scripts/copy-utility-templates.mjs +153 -0
- package/skills/wix-headless/scripts/emit-design-tokens.mjs +77 -0
- package/skills/wix-headless/scripts/finalize-run-json.mjs +141 -0
- package/skills/wix-headless/scripts/init-site-json.mjs +63 -0
- package/skills/wix-headless/scripts/patch-decorative-slots.mjs +124 -0
- package/skills/wix-headless/scripts/plan-entity-image-waves.mjs +190 -0
- package/skills/wix-headless/scripts/preview.sh +45 -0
- package/skills/wix-headless/scripts/release.sh +73 -0
- package/skills/wix-headless/scripts/scaffold.sh +53 -0
- package/skills/wix-headless/scripts/seed-utilities.sh +55 -0
- package/skills/wix-headless/shared-utilities/analytics.ts +40 -0
- package/skills/wix-headless/shared-utilities/ricos.ts +179 -0
- package/skills/wix-headless/shared-utilities/wix-image.ts +72 -0
- package/skills/wix-headless/templates/ecom/CartBadge.tsx +84 -0
- package/skills/wix-headless/templates/ecom/CartView.tsx +543 -0
- package/skills/wix-headless/templates/ecom/cart.astro +13 -0
- package/skills/wix-headless/templates/ecom/components-ecom.css +215 -0
- package/skills/wix-headless/templates/ecom/discounts.ts +71 -0
- package/skills/wix-headless/templates/ecom/thank-you.astro +24 -0
- package/skills/wix-headless/templates/gift-cards/GiftCardPurchase.tsx +172 -0
- package/skills/wix-headless/templates/gift-cards/_home-teaser-snippet.astro +42 -0
- package/skills/wix-headless/templates/gift-cards/_nav-snippet.astro +11 -0
- package/skills/wix-headless/templates/gift-cards/components-gift-cards.css +219 -0
- package/skills/wix-headless/templates/gift-cards/gift-cards.astro +51 -0
- package/skills/wix-headless/templates/gift-cards/gift-cards.ts +75 -0
- package/skills/wix-headless/templates/stores/AddToCartButton.tsx +77 -0
- package/skills/wix-headless/templates/stores/BackInStockForm.tsx +176 -0
- package/skills/wix-headless/templates/stores/CategoryRail.astro +69 -0
- package/skills/wix-headless/templates/stores/ProductCard.astro +79 -0
- package/skills/wix-headless/templates/stores/ProductPurchase.tsx +397 -0
- package/skills/wix-headless/templates/stores/SeoTags.astro +21 -0
- package/skills/wix-headless/templates/stores/back-in-stock.ts +67 -0
- package/skills/wix-headless/templates/stores/categories.ts +155 -0
- package/skills/wix-headless/templates/stores/category/[slug].astro +130 -0
- package/skills/wix-headless/templates/stores/components-stores.css +295 -0
- package/skills/wix-headless/templates/stores/products/[slug].astro +128 -0
- package/skills/wix-headless/templates/stores/products/index.astro +101 -0
- package/skills/wix-manage/SKILL.md +280 -0
- package/skills/wix-manage/references/app-installation/install-wix-apps.md +155 -0
- package/skills/wix-manage/references/app-installation/list-installed-apps.md +124 -0
- package/skills/wix-manage/references/blog/how-to-create-blog-posts.md +226 -0
- package/skills/wix-manage/references/bookings/booking-service-policy-setup.md +95 -0
- package/skills/wix-manage/references/bookings/booking-system-integration-gaps.md +416 -0
- package/skills/wix-manage/references/bookings/bookings-staff-setup.md +255 -0
- package/skills/wix-manage/references/bookings/create-and-update-booking-services.md +462 -0
- package/skills/wix-manage/references/bookings/end-to-end-booking-flow.md +278 -0
- package/skills/wix-manage/references/bookings/external-calendar-integration.md +258 -0
- package/skills/wix-manage/references/bookings/multi-resource-service-creation.md +231 -0
- package/skills/wix-manage/references/calendar/configure-default-business-hours.md +226 -0
- package/skills/wix-manage/references/cms/cms-data-items-crud.md +422 -0
- package/skills/wix-manage/references/cms/cms-data-operations-extended.md +263 -0
- package/skills/wix-manage/references/cms/cms-ecommerce-catalog-integration.md +136 -0
- package/skills/wix-manage/references/cms/cms-references-and-relationships.md +160 -0
- package/skills/wix-manage/references/cms/cms-schema-management.md +143 -0
- package/skills/wix-manage/references/contacts/bulk-delete-contacts.md +73 -0
- package/skills/wix-manage/references/contacts/bulk-label-and-unlabel-contacts.md +67 -0
- package/skills/wix-manage/references/domains/domain-search-and-purchase.md +434 -0
- package/skills/wix-manage/references/ecommerce/api-recommendation-tracking.md +420 -0
- package/skills/wix-manage/references/ecommerce/flow-add-free-shipping.md +267 -0
- package/skills/wix-manage/references/ecommerce/flow-bundle-and-save.md +290 -0
- package/skills/wix-manage/references/ecommerce/flow-fix-coverage-gaps.md +300 -0
- package/skills/wix-manage/references/ecommerce/flow-optimize-shipping-rates.md +364 -0
- package/skills/wix-manage/references/ecommerce/flow-seasonal-promotion.md +315 -0
- package/skills/wix-manage/references/ecommerce/flow-stock-mover.md +308 -0
- package/skills/wix-manage/references/ecommerce/flow-upsell-boost.md +271 -0
- package/skills/wix-manage/references/ecommerce/goal-clear-inventory.md +118 -0
- package/skills/wix-manage/references/ecommerce/goal-drive-cross-sells.md +122 -0
- package/skills/wix-manage/references/ecommerce/goal-increase-aov.md +132 -0
- package/skills/wix-manage/references/ecommerce/goal-reduce-cart-abandonment.md +148 -0
- package/skills/wix-manage/references/ecommerce/goal-seasonal-revenue.md +146 -0
- package/skills/wix-manage/references/ecommerce/guardrail-discount-conflicts.md +118 -0
- package/skills/wix-manage/references/ecommerce/guardrail-margin-protection.md +88 -0
- package/skills/wix-manage/references/ecommerce/guardrail-rate-pricing-sanity.md +108 -0
- package/skills/wix-manage/references/ecommerce/guardrail-shipping-health.md +124 -0
- package/skills/wix-manage/references/ecommerce/recipe-apply-shipping-recommendations.md +299 -0
- package/skills/wix-manage/references/ecommerce/recommend-ecommerce-strategy.md +582 -0
- package/skills/wix-manage/references/ecommerce/setup-coupons.md +338 -0
- package/skills/wix-manage/references/ecommerce/setup-discount-rules.md +444 -0
- package/skills/wix-manage/references/ecommerce/setup-shipping-rates.md +86 -0
- package/skills/wix-manage/references/ecommerce/setup-shipping-regions.md +56 -0
- package/skills/wix-manage/references/ecommerce/setup-store-pickup-location.md +209 -0
- package/skills/wix-manage/references/ecommerce/skill-graph.md +139 -0
- package/skills/wix-manage/references/ecommerce/troubleshoot-checkout-delivery-dropoff.md +124 -0
- package/skills/wix-manage/references/ecommerce/troubleshoot-discount-not-applying.md +95 -0
- package/skills/wix-manage/references/events/list-events.md +203 -0
- package/skills/wix-manage/references/forms/create-form.md +260 -0
- package/skills/wix-manage/references/get-paid/create-payment-links.md +212 -0
- package/skills/wix-manage/references/get-paid/how-to-setup-wix-payments.md +57 -0
- package/skills/wix-manage/references/get-paid/payment-links-for-bookings.md +101 -0
- package/skills/wix-manage/references/media/upload-media-to-wix.md +216 -0
- package/skills/wix-manage/references/pricing-plans/create-and-update-pricing-plans.md +77 -0
- package/skills/wix-manage/references/pricing-plans/pricing-plans-bookings-integration.md +166 -0
- package/skills/wix-manage/references/restaurants/wix-restaurants-setup.md +336 -0
- package/skills/wix-manage/references/rich-content/ricos-converter-service.md +295 -0
- package/skills/wix-manage/references/site-properties/change-payment-currency-site-properties.md +59 -0
- package/skills/wix-manage/references/sites/create-site-from-template.md +183 -0
- package/skills/wix-manage/references/sites/query-sites.md +125 -0
- package/skills/wix-manage/references/stores/add-store-pages-to-site.md +57 -0
- package/skills/wix-manage/references/stores/bulk-create-products-with-options.md +1041 -0
- package/skills/wix-manage/references/stores/create-product-catalog-v1.md +125 -0
- package/skills/wix-manage/references/stores/create-product-from-image.md +824 -0
- package/skills/wix-manage/references/stores/create-product-with-options-catalog-v3.md +566 -0
- package/skills/wix-manage/references/stores/find-products-query-and-search-catalog-v3.md +194 -0
- package/skills/wix-manage/references/stores/query-products-catalog-v1.md +80 -0
- package/skills/wix-manage/references/stores/setup-online-store-catalog-v3.md +99 -0
- package/skills/wix-manage/references/stores/update-product-pre-order.md +213 -0
- package/skills/wix-manage/references/stores/update-product-with-options.md +318 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
|
|
2
|
+
# Wix Backend API Builder
|
|
3
|
+
|
|
4
|
+
Creates HTTP endpoints for Wix CLI applications — server-side routes that handle HTTP requests, process data, and return responses. HTTP endpoints are powered by Astro endpoints and are automatically discovered from the file system.
|
|
5
|
+
|
|
6
|
+
**Key facts:**
|
|
7
|
+
|
|
8
|
+
- Files live in `src/pages/api/` with `.ts` extension
|
|
9
|
+
- Cannot be added via `npm run generate` — create files directly
|
|
10
|
+
- Don't appear on the Extensions page in the app dashboard
|
|
11
|
+
- No extension registration needed (auto-discovered)
|
|
12
|
+
- Replace the legacy "HTTP functions" from the previous Wix CLI for Apps
|
|
13
|
+
|
|
14
|
+
## Use Cases
|
|
15
|
+
|
|
16
|
+
Use HTTP endpoints when you need to:
|
|
17
|
+
|
|
18
|
+
- Build REST APIs with multiple HTTP methods
|
|
19
|
+
- Integrate with external APIs or services
|
|
20
|
+
- Handle complex form submissions or file uploads
|
|
21
|
+
- Serve dynamic content (images, RSS feeds, personalized data)
|
|
22
|
+
- Access runtime data or server-side databases
|
|
23
|
+
|
|
24
|
+
## File Structure and Naming
|
|
25
|
+
|
|
26
|
+
### Basic Endpoint
|
|
27
|
+
|
|
28
|
+
File path determines the endpoint URL:
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
src/pages/api/<your-endpoint-name>.ts
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Dynamic Routes
|
|
35
|
+
|
|
36
|
+
Use square brackets for dynamic parameters:
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
src/pages/api/users/[id].ts → /api/users/:id
|
|
40
|
+
src/pages/api/posts/[slug].ts → /api/posts/:slug
|
|
41
|
+
src/pages/api/users/[userId]/posts/[postId].ts → /api/users/:userId/posts/:postId
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## HTTP Methods
|
|
45
|
+
|
|
46
|
+
Export named functions for each HTTP method. Type with `APIRoute` from `astro`. Each handler receives a `request` object and returns a `Response`:
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import type { APIRoute } from "astro";
|
|
50
|
+
|
|
51
|
+
export const GET: APIRoute = async ({ request }) => {
|
|
52
|
+
console.log("Log from GET."); // This message logs to your CLI.
|
|
53
|
+
return new Response("Response from GET."); // This response is visible in the browser console
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export const POST: APIRoute = async ({ request }) => {
|
|
57
|
+
const data = await request.json();
|
|
58
|
+
console.log("Log POST with body: ", data); // This message logs to your CLI.
|
|
59
|
+
return new Response(JSON.stringify(data)); // This response is visible in the browser console.
|
|
60
|
+
};
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Request Handling
|
|
64
|
+
|
|
65
|
+
### Path Parameters
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
export const GET: APIRoute = async ({ params }) => {
|
|
69
|
+
const { id } = params; // From /api/users/[id]
|
|
70
|
+
|
|
71
|
+
if (!id) {
|
|
72
|
+
return new Response(JSON.stringify({ error: "ID required" }), {
|
|
73
|
+
status: 400,
|
|
74
|
+
statusText: "Bad Request",
|
|
75
|
+
headers: { "Content-Type": "application/json" },
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Use id to fetch data
|
|
80
|
+
};
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Query Parameters
|
|
84
|
+
|
|
85
|
+
Use `new URL(request.url).searchParams`:
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
export const GET: APIRoute = async ({ request }) => {
|
|
89
|
+
const url = new URL(request.url);
|
|
90
|
+
const search = url.searchParams.get("search");
|
|
91
|
+
const limit = parseInt(url.searchParams.get("limit") || "10", 10);
|
|
92
|
+
const offset = parseInt(url.searchParams.get("offset") || "0", 10);
|
|
93
|
+
|
|
94
|
+
// Use query parameters
|
|
95
|
+
};
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Request Body
|
|
99
|
+
|
|
100
|
+
Parse JSON body from POST/PUT/PATCH requests:
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
export const POST: APIRoute = async ({ request }) => {
|
|
104
|
+
try {
|
|
105
|
+
const body = await request.json();
|
|
106
|
+
const { title, content } = body;
|
|
107
|
+
|
|
108
|
+
if (!title || !content) {
|
|
109
|
+
return new Response(
|
|
110
|
+
JSON.stringify({ error: "Title and content required" }),
|
|
111
|
+
{
|
|
112
|
+
status: 400,
|
|
113
|
+
statusText: "Bad Request",
|
|
114
|
+
headers: { "Content-Type": "application/json" },
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Process data
|
|
120
|
+
} catch {
|
|
121
|
+
return new Response(JSON.stringify({ error: "Invalid JSON" }), {
|
|
122
|
+
status: 400,
|
|
123
|
+
statusText: "Bad Request",
|
|
124
|
+
headers: { "Content-Type": "application/json" },
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Headers
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
const authHeader = request.headers.get("Authorization");
|
|
134
|
+
const contentType = request.headers.get("Content-Type");
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Response Patterns
|
|
138
|
+
|
|
139
|
+
Always return a `Response` object with proper status codes and headers:
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
// 200 OK
|
|
143
|
+
return new Response(JSON.stringify({ data: result }), {
|
|
144
|
+
status: 200,
|
|
145
|
+
headers: { "Content-Type": "application/json" },
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// 201 Created
|
|
149
|
+
return new Response(JSON.stringify({ id: newId, ...data }), {
|
|
150
|
+
status: 201,
|
|
151
|
+
headers: { "Content-Type": "application/json" },
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// 204 No Content (for DELETE)
|
|
155
|
+
return new Response(null, { status: 204 });
|
|
156
|
+
|
|
157
|
+
// 400 Bad Request
|
|
158
|
+
return new Response(JSON.stringify({ error: "Invalid input" }), {
|
|
159
|
+
status: 400,
|
|
160
|
+
statusText: "Bad Request",
|
|
161
|
+
headers: { "Content-Type": "application/json" },
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// 404 Not Found
|
|
165
|
+
return new Response(JSON.stringify({ error: "Not found" }), {
|
|
166
|
+
status: 404,
|
|
167
|
+
statusText: "Not Found",
|
|
168
|
+
headers: { "Content-Type": "application/json" },
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// 500 Internal Server Error
|
|
172
|
+
return new Response(JSON.stringify({ error: "Internal server error" }), {
|
|
173
|
+
status: 500,
|
|
174
|
+
statusText: "Internal Server Error",
|
|
175
|
+
headers: { "Content-Type": "application/json" },
|
|
176
|
+
});
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Frontend Integration
|
|
180
|
+
|
|
181
|
+
Call HTTP endpoints from frontend components using Wix's built-in HTTP client (`httpClient.fetchWithAuth()`):
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
import { httpClient } from "@wix/essentials";
|
|
185
|
+
|
|
186
|
+
// GET request
|
|
187
|
+
const baseApiUrl = new URL(import.meta.url).origin;
|
|
188
|
+
const res = await httpClient.fetchWithAuth(
|
|
189
|
+
`${baseApiUrl}/api/<your-endpoint-name>`,
|
|
190
|
+
);
|
|
191
|
+
const data = await res.text();
|
|
192
|
+
|
|
193
|
+
// POST request
|
|
194
|
+
const res = await httpClient.fetchWithAuth(
|
|
195
|
+
`${baseApiUrl}/api/<your-endpoint-name>`,
|
|
196
|
+
{
|
|
197
|
+
method: "POST",
|
|
198
|
+
body: JSON.stringify({ message: "Hello from frontend" }),
|
|
199
|
+
},
|
|
200
|
+
);
|
|
201
|
+
const data = await res.json();
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Build, Deploy, and Delete
|
|
205
|
+
|
|
206
|
+
To take HTTP endpoints to production, build and release your project:
|
|
207
|
+
|
|
208
|
+
1. Build the project assets using the [`build`](https://dev.wix.com/docs/wix-cli/command-reference/project-commands/build) command.
|
|
209
|
+
2. Optionally create preview URLs using the [`preview`](https://dev.wix.com/docs/wix-cli/command-reference/project-commands/preview) command to share with team members for testing.
|
|
210
|
+
3. Release your project using the [`release`](https://dev.wix.com/docs/wix-cli/command-reference/project-commands/release) command.
|
|
211
|
+
|
|
212
|
+
Once released, endpoints are accessible at production URLs and handle live traffic.
|
|
213
|
+
|
|
214
|
+
To delete an HTTP endpoint, remove the file under `src/pages/api/` and release again.
|
|
215
|
+
|
|
216
|
+
## Output Structure
|
|
217
|
+
|
|
218
|
+
```
|
|
219
|
+
src/pages/api/
|
|
220
|
+
├── users.ts # /api/users endpoint
|
|
221
|
+
├── users/
|
|
222
|
+
│ └── [id].ts # /api/users/:id endpoint
|
|
223
|
+
└── posts.ts # /api/posts endpoint
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## Backend-API-specific Conventions
|
|
227
|
+
|
|
228
|
+
- Type all handlers with `APIRoute` from `astro`.
|
|
229
|
+
- Always return `Response` objects with `JSON.stringify()` for JSON.
|
|
230
|
+
- Use proper HTTP status codes (200, 201, 204, 400, 404, 500).
|
|
231
|
+
- Include `Content-Type: application/json` header on JSON responses.
|
|
232
|
+
- Include `statusText` in error responses.
|
|
233
|
+
- Validate input parameters and request bodies.
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
|
|
2
|
+
# Wix CLI Backend Event Extension
|
|
3
|
+
|
|
4
|
+
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.
|
|
5
|
+
|
|
6
|
+
Common use cases: run logic when a contact is created, an order is placed, a booking is confirmed, or a blog post is published.
|
|
7
|
+
|
|
8
|
+
## Quick Start Checklist
|
|
9
|
+
|
|
10
|
+
Follow these steps in order when creating an event extension.
|
|
11
|
+
|
|
12
|
+
1. [ ] Create event folder: `src/extensions/backend/events/<event-name>/`
|
|
13
|
+
2. [ ] Create `<event-name>.ts` with the SDK event import and handler function
|
|
14
|
+
3. [ ] Create `<event-name>.extension.ts` with `extensions.event()` and a unique UUID
|
|
15
|
+
4. [ ] Update `src/extensions.ts` to import and use the new extension
|
|
16
|
+
|
|
17
|
+
**User (manual):** Configure app permissions for the event in the app dashboard if required; release a version and trigger the event to test.
|
|
18
|
+
|
|
19
|
+
## References
|
|
20
|
+
|
|
21
|
+
| Topic | Reference |
|
|
22
|
+
| --- | --- |
|
|
23
|
+
| Common events (CRM, eCommerce, Bookings, Blog) | [COMMON-EVENTS.md](backend-event/COMMON-EVENTS.md) |
|
|
24
|
+
|
|
25
|
+
## Output Structure
|
|
26
|
+
|
|
27
|
+
Two files per event ([docs](https://dev.wix.com/docs/wix-cli/guides/extensions/backend-extensions/events/event-extension-files-and-code)). Only **one** handler per event allowed in the app (including dashboard handlers).
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
src/extensions/backend/events/<event-name>/
|
|
31
|
+
├── <event-name>.extension.ts # Builder: extensions.event({ id, source }) – id is unique GUID
|
|
32
|
+
└── <event-name>.ts # Handler: imports SDK event (e.g. onContactCreated), runs on trigger
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Implementation Pattern
|
|
36
|
+
|
|
37
|
+
### Event builder (`<event-name>.extension.ts`)
|
|
38
|
+
|
|
39
|
+
Use `extensions.event()` from `@wix/astro/builders`. Required fields: `id` (unique GUID), `source` (path to the handler file).
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { extensions } from "@wix/astro/builders";
|
|
43
|
+
|
|
44
|
+
export const eventContactCreated = extensions.event({
|
|
45
|
+
id: "{{GENERATE_UUID}}",
|
|
46
|
+
source: "./extensions/backend/events/contact-created/contact-created.ts",
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
**CRITICAL: UUID Generation**
|
|
51
|
+
|
|
52
|
+
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"`.
|
|
53
|
+
|
|
54
|
+
### Event handler (`<event-name>.ts`)
|
|
55
|
+
|
|
56
|
+
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](https://dev.wix.com/docs/sdk).
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { contacts } from "@wix/crm";
|
|
60
|
+
|
|
61
|
+
export default contacts.onContactCreated((event) => {
|
|
62
|
+
console.log("Contact created:", event.entity);
|
|
63
|
+
// Custom logic: sync to CRM, send welcome email, etc.
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Handler can be `async`; ensure errors are caught and logged so one failing handler does not break others.
|
|
68
|
+
|
|
69
|
+
## Extension Registration
|
|
70
|
+
|
|
71
|
+
**Two steps required.**
|
|
72
|
+
|
|
73
|
+
### Step 1: Event builder file
|
|
74
|
+
|
|
75
|
+
Create `<event-name>.extension.ts` inside the event folder (and `<event-name>.ts` for the handler) as shown in [Implementation Pattern](#implementation-pattern) above.
|
|
76
|
+
|
|
77
|
+
### Step 2: Register in main extensions.ts
|
|
78
|
+
|
|
79
|
+
**CRITICAL:** Read [Extension Registration reference](EXTENSION_REGISTRATION.md) and add the event extension to `src/extensions.ts` (import and `.use(eventContactCreated)` or equivalent). Without this, the event extension is not active.
|
|
80
|
+
|
|
81
|
+
Naming: export names follow `event{CamelCaseName}` (e.g. `eventContactCreated`, `eventOrderPaid`).
|
|
82
|
+
|
|
83
|
+
## Elevating Permissions for API Calls
|
|
84
|
+
|
|
85
|
+
When calling Wix APIs from inside an event handler, use `auth.elevate` from `@wix/essentials` so the call runs with the right permissions.
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import { contacts } from "@wix/crm";
|
|
89
|
+
import { auth } from "@wix/essentials";
|
|
90
|
+
import { items } from "@wix/data";
|
|
91
|
+
|
|
92
|
+
export default contacts.onContactCreated(async (event) => {
|
|
93
|
+
const elevatedQuery = auth.elevate(items.query);
|
|
94
|
+
const result = await elevatedQuery("MyCollection").find();
|
|
95
|
+
// Use result
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Key Constraints
|
|
100
|
+
|
|
101
|
+
- **One handler per event** – You cannot have two event extensions for the same event in the app (local or dashboard).
|
|
102
|
+
- **Permissions** – Each event may require specific permission scopes; configure them in the app dashboard (Permissions page).
|
|
103
|
+
- **Testing** – Release a version with your changes, then perform the action that triggers the event. Some events are not fully testable in local dev.
|
|
104
|
+
- **Backend limits** – Event handlers run under backend extension limits (e.g. 1000 CPU ms per request, 20 sub-requests). See [About Backend Extensions](https://dev.wix.com/docs/wix-cli/guides/extensions/backend-extensions/about-backend-extensions).
|
|
105
|
+
|
|
106
|
+
## Best Practices
|
|
107
|
+
|
|
108
|
+
- **Error handling:** Wrap handler logic in try/catch; log and optionally rethrow or report.
|
|
109
|
+
- **Idempotency:** Events may be delivered more than once; design handlers to be idempotent where possible.
|
|
110
|
+
- **Logging:** Use `console.log` for debugging; keep production logs minimal and non-sensitive.
|
|
111
|
+
- **Performance:** Finish within backend limits; offload heavy work to queues or background jobs if needed.
|
|
112
|
+
|
|
113
|
+
## Testing Event Extensions
|
|
114
|
+
|
|
115
|
+
1. **Release** a version with your changes.
|
|
116
|
+
2. **Trigger** the event by taking an action.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Code Quality Requirements
|
|
2
|
+
|
|
3
|
+
Applies to all generated code across every Wix CLI app extension type. Each per-extension reference links here instead of restating these rules.
|
|
4
|
+
|
|
5
|
+
## TypeScript Quality Guidelines
|
|
6
|
+
|
|
7
|
+
- Generated code MUST compile with zero TypeScript errors under strict settings: `strict`, `noImplicitAny`, `strictNullChecks`, `exactOptionalPropertyTypes`, `noUncheckedIndexedAccess`.
|
|
8
|
+
- Prefer type-narrowing and exhaustive logic over assertions; avoid non-null assertions (`!`) and unsafe casts (`as any`).
|
|
9
|
+
- Treat optional values, refs, and array indexing results as possibly undefined and handle them explicitly.
|
|
10
|
+
- Use exhaustive checks for unions (e.g., `switch` with a `never` check) and return total values (no implicit `undefined`).
|
|
11
|
+
- Do NOT use `// @ts-ignore` or `// @ts-expect-error`; fix the types or add guards instead.
|
|
12
|
+
|
|
13
|
+
## Core Principles
|
|
14
|
+
|
|
15
|
+
- Do NOT invent or assume new types, modules, functions, props, events, or imports. Use only entities present in the provided references or standard libraries already used in this project.
|
|
16
|
+
- NEVER use mocks, placeholders, or TODOs in shipped code. ALWAYS implement complete, production-ready functionality.
|
|
17
|
+
- If a required API, type, or module is missing, surface it to the user explicitly rather than inserting placeholder code.
|
|
18
|
+
- Do NOT create README.md, CHANGELOG.md, or other unprompted markdown documentation — only output the files the task actually requires.
|
|
19
|
+
|
|
20
|
+
## Code Quality Standards
|
|
21
|
+
|
|
22
|
+
- Add documentation only for complex or non-obvious logic — well-named identifiers should carry the rest.
|
|
23
|
+
- Prefer `async`/`await` for asynchronous operations.
|
|
24
|
+
|
|
25
|
+
## Modular Code
|
|
26
|
+
|
|
27
|
+
- If a generated file would exceed ~300 lines, split it into multiple smaller files with imports. Each component or function should stay ~50–100 lines.
|
|
28
|
+
- Extract utilities/helpers into separate files; put types/interfaces into dedicated type files.
|
|
29
|
+
|
|
30
|
+
## Error Handling
|
|
31
|
+
|
|
32
|
+
- Log errors with `console.error` for debugging.
|
|
33
|
+
- Handle network timeouts and external service failures.
|