@wix/ditto-codegen-public 1.0.55 → 1.0.56
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/dist/out.js +1221 -72
- package/package.json +2 -2
package/dist/out.js
CHANGED
|
@@ -121273,7 +121273,7 @@ var require_planner = __commonJS({
|
|
|
121273
121273
|
<WIXCLI_PLANNER_SYSTEM_PROMPT>
|
|
121274
121274
|
${(0, data_1.cmsPlannerPrompt)()}
|
|
121275
121275
|
|
|
121276
|
-
${hasBackendApiExtensions ? (0, apiSpec_1.apiSpecPrompt)() : "No backend API extensions in the blueprint, return
|
|
121276
|
+
${hasBackendApiExtensions ? (0, apiSpec_1.apiSpecPrompt)() : "No backend API extensions in the blueprint, don't return anything for apiSpec"}
|
|
121277
121277
|
|
|
121278
121278
|
${hasEmbeddedScriptExtensions ? (0, dynamicParameters_1.dynamicParametersPrompt)() : 'No embeddedScriptParameters needed, no embedded scripts in the blueprint, return an empty array: "embeddedScriptParameters": []'}
|
|
121279
121279
|
</WIXCLI_PLANNER_SYSTEM_PROMPT>
|
|
@@ -123279,7 +123279,7 @@ var require_PlannerAgent = __commonJS({
|
|
|
123279
123279
|
exports2.PlannerOutputSchema = zod_1.z.object({
|
|
123280
123280
|
collections: zod_1.z.array(CMSAgent_1.CmsCollectionSchema).default([]).describe("CMS collections to be created for the app"),
|
|
123281
123281
|
embeddedScriptParameters: zod_1.z.array(EmbeddedScriptSchema_1.EmbeddedScriptParametersSchema).default([]).describe("Dynamic parameters for embedded script extensions (empty array if no embedded scripts)"),
|
|
123282
|
-
apiSpec: ApiSpecSchema_1.ApiSpecSchema.optional().describe("API specification for the app")
|
|
123282
|
+
apiSpec: ApiSpecSchema_1.ApiSpecSchema.optional().describe("API specification for the app, don't return anything if no backend API extensions")
|
|
123283
123283
|
});
|
|
123284
123284
|
var PlannerAgent = class {
|
|
123285
123285
|
constructor(apiKey) {
|
|
@@ -128154,90 +128154,1142 @@ export default withDashboard(CollectionPage);
|
|
|
128154
128154
|
}
|
|
128155
128155
|
});
|
|
128156
128156
|
|
|
128157
|
-
// dist/system-prompts/
|
|
128158
|
-
var
|
|
128159
|
-
"dist/system-prompts/
|
|
128157
|
+
// dist/system-prompts/SDK/ecom/cart.js
|
|
128158
|
+
var require_cart = __commonJS({
|
|
128159
|
+
"dist/system-prompts/SDK/ecom/cart.js"(exports2) {
|
|
128160
128160
|
"use strict";
|
|
128161
128161
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
128162
|
-
exports2.
|
|
128163
|
-
var
|
|
128164
|
-
|
|
128165
|
-
|
|
128162
|
+
exports2.cartPrompt = void 0;
|
|
128163
|
+
var cartPrompt = () => `
|
|
128164
|
+
<ecom_cart_docs>
|
|
128165
|
+
|
|
128166
|
+
<description>
|
|
128167
|
+
This is a comprehensive reference guide for the Wix Ecom Current Cart SDK.
|
|
128168
|
+
The cart is the first phase of a purchase, followed by checkout, then order.
|
|
128169
|
+
The current cart is the cart that is currently being used by the site visitor or logged-in member.
|
|
128170
|
+
|
|
128171
|
+
CRITICAL FOR EMBEDDED SCRIPTS:
|
|
128172
|
+
- Embedded scripts MUST use the @wix/ecom SDK directly - DO NOT create fetch() calls to arbitrary API endpoints
|
|
128173
|
+
- Import the currentCart module from '@wix/ecom' directly in your embedded script
|
|
128174
|
+
- NEVER create fetch() calls to /api/* endpoints for cart operations unless those endpoints are explicitly defined in the API spec
|
|
128175
|
+
- Use currentCart.getCurrentCart() and other cart methods directly in embedded script code
|
|
128176
|
+
</description>
|
|
128177
|
+
|
|
128178
|
+
<introduction>
|
|
128179
|
+
# About the eCommerce Current Cart API
|
|
128180
|
+
|
|
128181
|
+
A cart holds information about purchased items, prices, discounts, site details, buyer IDs (contact and member/visitor) and more.
|
|
128182
|
+
|
|
128183
|
+
With the eCommerce Cart API you can:
|
|
128184
|
+
- Get the current cart
|
|
128185
|
+
- Add items to the current cart
|
|
128186
|
+
- Create a checkout from the current cart
|
|
128187
|
+
- Estimate the price totals for the current cart
|
|
128188
|
+
- Update the properties of the current cart
|
|
128189
|
+
- Update the quantity of line items in the current cart
|
|
128190
|
+
- Remove a coupon from the current cart
|
|
128191
|
+
- Remove line items from the current cart
|
|
128192
|
+
- Delete the current cart
|
|
128193
|
+
|
|
128194
|
+
You can also listen for events when a cart is created, updated, and deleted.
|
|
128195
|
+
|
|
128196
|
+
</introduction>
|
|
128197
|
+
|
|
128198
|
+
<type_signatures>
|
|
128199
|
+
# Method Signatures & Types
|
|
128200
|
+
|
|
128201
|
+
## getCurrentCart()
|
|
128202
|
+
\`\`\`typescript
|
|
128203
|
+
function getCurrentCart(): Promise<Cart>
|
|
128204
|
+
\`\`\`
|
|
128205
|
+
**Returns:** Promise<Cart> - The current visitor's cart object
|
|
128206
|
+
|
|
128207
|
+
## addToCurrentCart(options)
|
|
128208
|
+
\`\`\`typescript
|
|
128209
|
+
function addToCurrentCart(options: AddToCurrentCartOptions): Promise<AddToCartResponse>
|
|
128210
|
+
|
|
128211
|
+
interface AddToCurrentCartOptions {
|
|
128212
|
+
lineItems?: Array<{
|
|
128213
|
+
catalogReference: {
|
|
128214
|
+
appId: string; // Required
|
|
128215
|
+
catalogItemId: string; // Required
|
|
128216
|
+
options?: Record<string, any>;
|
|
128217
|
+
};
|
|
128218
|
+
quantity: number; // Required
|
|
128219
|
+
catalogOverrideFields?: object;
|
|
128220
|
+
extendedFields?: object;
|
|
128221
|
+
}>;
|
|
128222
|
+
customLineItems?: Array<CustomLineItem>;
|
|
128223
|
+
businessLocationId?: string;
|
|
128224
|
+
}
|
|
128225
|
+
\`\`\`
|
|
128226
|
+
**Returns:** Promise<{cart: Cart}> - Response containing the updated cart
|
|
128227
|
+
|
|
128228
|
+
## createCheckoutFromCurrentCart(options)
|
|
128229
|
+
\`\`\`typescript
|
|
128230
|
+
function createCheckoutFromCurrentCart(options: CreateCheckoutFromCurrentCartOptions): Promise<CreateCheckoutResponse>
|
|
128231
|
+
|
|
128232
|
+
interface CreateCheckoutFromCurrentCartOptions {
|
|
128233
|
+
channelType: ChannelType; // Required: "WEB", "POS", "EBAY", etc.
|
|
128234
|
+
email?: string;
|
|
128235
|
+
shippingAddress?: Address;
|
|
128236
|
+
billingAddress?: Address;
|
|
128237
|
+
selectedShippingOption?: SelectedShippingOption;
|
|
128238
|
+
}
|
|
128239
|
+
\`\`\`
|
|
128240
|
+
**Returns:** Promise<{checkoutId: string}> - The created checkout ID
|
|
128241
|
+
|
|
128242
|
+
## estimateCurrentCartTotals(options)
|
|
128243
|
+
\`\`\`typescript
|
|
128244
|
+
function estimateCurrentCartTotals(options?: EstimateCurrentCartTotalsOptions): Promise<EstimateTotalsResponse>
|
|
128245
|
+
|
|
128246
|
+
interface EstimateCurrentCartTotalsOptions {
|
|
128247
|
+
selectedShippingOption?: SelectedShippingOption;
|
|
128248
|
+
shippingAddress?: Address;
|
|
128249
|
+
billingAddress?: Address;
|
|
128250
|
+
calculateShipping?: boolean; // Default: true
|
|
128251
|
+
calculateTax?: boolean; // Default: true
|
|
128252
|
+
selectedMemberships?: SelectedMemberships;
|
|
128253
|
+
}
|
|
128254
|
+
\`\`\`
|
|
128255
|
+
**Returns:** Promise<EstimateTotalsResponse> - Price totals, shipping info, tax summary
|
|
128256
|
+
|
|
128257
|
+
## updateCurrentCart(options)
|
|
128258
|
+
\`\`\`typescript
|
|
128259
|
+
function updateCurrentCart(options: UpdateCurrentCartOptions): Promise<Cart>
|
|
128260
|
+
|
|
128261
|
+
interface UpdateCurrentCartOptions {
|
|
128262
|
+
cartInfo?: {
|
|
128263
|
+
buyerNote?: string;
|
|
128264
|
+
buyerInfo?: BuyerInfo;
|
|
128265
|
+
contactInfo?: AddressWithContact;
|
|
128266
|
+
selectedShippingOption?: SelectedShippingOption;
|
|
128267
|
+
extendedFields?: ExtendedFields;
|
|
128268
|
+
businessLocationId?: string;
|
|
128269
|
+
overrideCheckoutUrl?: string;
|
|
128270
|
+
};
|
|
128271
|
+
lineItems?: Array<LineItem>;
|
|
128272
|
+
customLineItems?: Array<CustomLineItem>;
|
|
128273
|
+
couponCode?: string;
|
|
128274
|
+
}
|
|
128275
|
+
\`\`\`
|
|
128276
|
+
**Returns:** Promise<Cart> - The updated cart object
|
|
128277
|
+
|
|
128278
|
+
## updateCurrentCartLineItemQuantity(lineItems)
|
|
128279
|
+
\`\`\`typescript
|
|
128280
|
+
function updateCurrentCartLineItemQuantity(lineItems: Array<LineItemQuantityUpdate>): Promise<UpdateLineItemsQuantityResponse>
|
|
128281
|
+
|
|
128282
|
+
interface LineItemQuantityUpdate {
|
|
128283
|
+
_id: string; // Required: Line item ID
|
|
128284
|
+
quantity: number; // Required: New quantity (min: 1)
|
|
128285
|
+
}
|
|
128286
|
+
\`\`\`
|
|
128287
|
+
**Returns:** Promise<{cart: Cart}> - Response containing the updated cart
|
|
128288
|
+
|
|
128289
|
+
## removeCouponFromCurrentCart()
|
|
128290
|
+
\`\`\`typescript
|
|
128291
|
+
function removeCouponFromCurrentCart(): Promise<RemoveCouponResponse>
|
|
128292
|
+
\`\`\`
|
|
128293
|
+
**Returns:** Promise<{cart: Cart}> - Response containing the updated cart
|
|
128294
|
+
|
|
128295
|
+
## removeLineItemsFromCurrentCart(lineItemIds)
|
|
128296
|
+
\`\`\`typescript
|
|
128297
|
+
function removeLineItemsFromCurrentCart(lineItemIds: Array<string>): Promise<RemoveLineItemsResponse>
|
|
128298
|
+
\`\`\`
|
|
128299
|
+
**Parameters:**
|
|
128300
|
+
- lineItemIds: Array<string> - Required. IDs of line items to remove
|
|
128301
|
+
|
|
128302
|
+
**Returns:** Promise<{cart: Cart}> - Response containing the updated cart
|
|
128303
|
+
|
|
128304
|
+
## deleteCurrentCart()
|
|
128305
|
+
\`\`\`typescript
|
|
128306
|
+
function deleteCurrentCart(): Promise<void>
|
|
128307
|
+
\`\`\`
|
|
128308
|
+
**Returns:** Promise<void> - No return value
|
|
128309
|
+
|
|
128310
|
+
## Event Handlers
|
|
128311
|
+
|
|
128312
|
+
### onCartCreated(handler)
|
|
128313
|
+
\`\`\`typescript
|
|
128314
|
+
function onCartCreated(handler: (event: CartEvent) => void): void
|
|
128315
|
+
|
|
128316
|
+
interface CartEvent {
|
|
128317
|
+
entity: Cart;
|
|
128318
|
+
metadata: EventMetadata;
|
|
128319
|
+
}
|
|
128320
|
+
\`\`\`
|
|
128321
|
+
|
|
128322
|
+
### onCartUpdated(handler)
|
|
128323
|
+
\`\`\`typescript
|
|
128324
|
+
function onCartUpdated(handler: (event: CartEvent) => void): void
|
|
128325
|
+
\`\`\`
|
|
128326
|
+
|
|
128327
|
+
### onCartDeleted(handler)
|
|
128328
|
+
\`\`\`typescript
|
|
128329
|
+
function onCartDeleted(handler: (event: DeletedCartEvent) => void): void
|
|
128330
|
+
|
|
128331
|
+
interface DeletedCartEvent {
|
|
128332
|
+
metadata: {
|
|
128333
|
+
entityId: string;
|
|
128334
|
+
eventTime: string;
|
|
128335
|
+
};
|
|
128336
|
+
}
|
|
128337
|
+
\`\`\`
|
|
128338
|
+
|
|
128339
|
+
## Common Types
|
|
128340
|
+
|
|
128341
|
+
### Cart Object
|
|
128342
|
+
\`\`\`typescript
|
|
128343
|
+
interface Cart {
|
|
128344
|
+
_id: string;
|
|
128345
|
+
_createdDate: Date;
|
|
128346
|
+
_updatedDate: Date;
|
|
128347
|
+
lineItems: Array<LineItem>;
|
|
128348
|
+
buyerInfo?: BuyerInfo;
|
|
128349
|
+
currency: string;
|
|
128350
|
+
conversionCurrency: string;
|
|
128351
|
+
paymentCurrency: string;
|
|
128352
|
+
subtotal: MultiCurrencyPrice;
|
|
128353
|
+
appliedDiscounts?: Array<CartDiscount>;
|
|
128354
|
+
taxIncludedInPrices: boolean;
|
|
128355
|
+
weightUnit: "KG" | "LB";
|
|
128356
|
+
buyerLanguage: string;
|
|
128357
|
+
siteLanguage: string;
|
|
128358
|
+
checkoutId?: string;
|
|
128359
|
+
purchaseFlowId: string;
|
|
128360
|
+
// ... additional fields
|
|
128361
|
+
}
|
|
128362
|
+
\`\`\`
|
|
128363
|
+
|
|
128364
|
+
### LineItem Object
|
|
128365
|
+
\`\`\`typescript
|
|
128366
|
+
interface LineItem {
|
|
128367
|
+
_id: string;
|
|
128368
|
+
quantity: number;
|
|
128369
|
+
catalogReference: {
|
|
128370
|
+
appId: string;
|
|
128371
|
+
catalogItemId: string;
|
|
128372
|
+
options?: Record<string, any>;
|
|
128373
|
+
};
|
|
128374
|
+
productName: {
|
|
128375
|
+
original: string;
|
|
128376
|
+
translated?: string;
|
|
128377
|
+
};
|
|
128378
|
+
price: MultiCurrencyPrice;
|
|
128379
|
+
fullPrice: MultiCurrencyPrice;
|
|
128380
|
+
priceBeforeDiscounts: MultiCurrencyPrice;
|
|
128381
|
+
lineItemPrice: MultiCurrencyPrice;
|
|
128382
|
+
image?: string;
|
|
128383
|
+
url?: string;
|
|
128384
|
+
availability?: ItemAvailabilityInfo;
|
|
128385
|
+
physicalProperties?: PhysicalProperties;
|
|
128386
|
+
itemType: ItemType;
|
|
128387
|
+
// ... additional fields
|
|
128388
|
+
}
|
|
128389
|
+
\`\`\`
|
|
128390
|
+
|
|
128391
|
+
### Address Object
|
|
128392
|
+
\`\`\`typescript
|
|
128393
|
+
interface Address {
|
|
128394
|
+
addressLine1?: string;
|
|
128395
|
+
addressLine2?: string;
|
|
128396
|
+
city?: string;
|
|
128397
|
+
country?: string; // ISO-3166 alpha-2 format
|
|
128398
|
+
subdivision?: string; // ISO 3166-2 format
|
|
128399
|
+
postalCode?: string;
|
|
128400
|
+
streetAddress?: {
|
|
128401
|
+
name?: string;
|
|
128402
|
+
number?: string;
|
|
128403
|
+
};
|
|
128404
|
+
}
|
|
128405
|
+
\`\`\`
|
|
128406
|
+
|
|
128407
|
+
### MultiCurrencyPrice Object
|
|
128408
|
+
\`\`\`typescript
|
|
128409
|
+
interface MultiCurrencyPrice {
|
|
128410
|
+
amount: string;
|
|
128411
|
+
convertedAmount: string;
|
|
128412
|
+
formattedAmount: string;
|
|
128413
|
+
formattedConvertedAmount: string;
|
|
128414
|
+
}
|
|
128415
|
+
\`\`\`
|
|
128416
|
+
|
|
128417
|
+
### CartDiscount Object
|
|
128418
|
+
\`\`\`typescript
|
|
128419
|
+
interface CartDiscount {
|
|
128420
|
+
coupon?: {
|
|
128421
|
+
_id: string;
|
|
128422
|
+
code: string;
|
|
128423
|
+
};
|
|
128424
|
+
merchantDiscount?: {
|
|
128425
|
+
amount: MultiCurrencyPrice;
|
|
128426
|
+
};
|
|
128427
|
+
}
|
|
128428
|
+
\`\`\`
|
|
128429
|
+
|
|
128430
|
+
### BuyerInfo Object
|
|
128431
|
+
\`\`\`typescript
|
|
128432
|
+
interface BuyerInfo {
|
|
128433
|
+
contactId?: string;
|
|
128434
|
+
email?: string;
|
|
128435
|
+
memberId?: string; // If buyer is a site member
|
|
128436
|
+
userId?: string; // If buyer is a Wix user
|
|
128437
|
+
visitorId?: string; // If buyer is not a site member
|
|
128438
|
+
}
|
|
128439
|
+
\`\`\`
|
|
128440
|
+
|
|
128441
|
+
**Getting User ID:**
|
|
128442
|
+
To get the user's ID, use \`getCurrentCart()\` and access the \`buyerInfo\` object. The user will have one of three ID types:
|
|
128443
|
+
- \`buyerInfo.memberId\` - Present when the buyer is a logged-in site member
|
|
128444
|
+
- \`buyerInfo.userId\` - Present when the buyer is a Wix user (cart owner)
|
|
128445
|
+
- \`buyerInfo.visitorId\` - Present when the buyer is an anonymous visitor (not logged in)
|
|
128446
|
+
|
|
128447
|
+
Example:
|
|
128448
|
+
\`\`\`javascript
|
|
128449
|
+
const cart = await currentCart.getCurrentCart();
|
|
128450
|
+
const userId = cart.buyerInfo?.memberId || cart.buyerInfo?.userId || cart.buyerInfo?.visitorId;
|
|
128451
|
+
\`\`\`
|
|
128452
|
+
|
|
128453
|
+
### ItemAvailabilityInfo Object
|
|
128454
|
+
\`\`\`typescript
|
|
128455
|
+
interface ItemAvailabilityInfo {
|
|
128456
|
+
status: "AVAILABLE" | "NOT_AVAILABLE" | "NOT_FOUND" | "PARTIALLY_AVAILABLE";
|
|
128457
|
+
quantityAvailable?: number;
|
|
128458
|
+
}
|
|
128459
|
+
\`\`\`
|
|
128460
|
+
|
|
128461
|
+
### PhysicalProperties Object
|
|
128462
|
+
\`\`\`typescript
|
|
128463
|
+
interface PhysicalProperties {
|
|
128464
|
+
sku?: string;
|
|
128465
|
+
shippable?: boolean;
|
|
128466
|
+
weight?: number; // Measurement unit matches weightUnit in cart
|
|
128467
|
+
}
|
|
128468
|
+
\`\`\`
|
|
128469
|
+
|
|
128470
|
+
### ItemType Object
|
|
128471
|
+
\`\`\`typescript
|
|
128472
|
+
interface ItemType {
|
|
128473
|
+
preset?: "PHYSICAL" | "DIGITAL" | "GIFT_CARD" | "SERVICE" | "UNRECOGNISED";
|
|
128474
|
+
custom?: string; // Custom type when preset is not suitable
|
|
128475
|
+
}
|
|
128476
|
+
\`\`\`
|
|
128477
|
+
|
|
128478
|
+
### ProductName Object
|
|
128479
|
+
\`\`\`typescript
|
|
128480
|
+
interface ProductName {
|
|
128481
|
+
original: string; // Required - in site's default language
|
|
128482
|
+
translated?: string; // Translated into buyer's language
|
|
128483
|
+
}
|
|
128484
|
+
\`\`\`
|
|
128485
|
+
|
|
128486
|
+
### DescriptionLine Object
|
|
128487
|
+
\`\`\`typescript
|
|
128488
|
+
interface DescriptionLine {
|
|
128489
|
+
name: {
|
|
128490
|
+
original: string;
|
|
128491
|
+
translated?: string;
|
|
128492
|
+
};
|
|
128493
|
+
colorInfo?: {
|
|
128494
|
+
original: string;
|
|
128495
|
+
translated?: string;
|
|
128496
|
+
code: string; // HEX or RGB color code
|
|
128497
|
+
};
|
|
128498
|
+
plainText?: {
|
|
128499
|
+
original: string;
|
|
128500
|
+
translated?: string;
|
|
128501
|
+
};
|
|
128502
|
+
lineType?: string;
|
|
128503
|
+
}
|
|
128504
|
+
\`\`\`
|
|
128505
|
+
|
|
128506
|
+
### SelectedShippingOption Object
|
|
128507
|
+
\`\`\`typescript
|
|
128508
|
+
interface SelectedShippingOption {
|
|
128509
|
+
carrierId?: string;
|
|
128510
|
+
code?: string; // e.g., "usps_std_overnight"
|
|
128511
|
+
}
|
|
128512
|
+
\`\`\`
|
|
128513
|
+
|
|
128514
|
+
### AddressWithContact Object
|
|
128515
|
+
\`\`\`typescript
|
|
128516
|
+
interface AddressWithContact {
|
|
128517
|
+
address?: Address;
|
|
128518
|
+
contactDetails?: {
|
|
128519
|
+
firstName?: string;
|
|
128520
|
+
lastName?: string;
|
|
128521
|
+
phone?: string;
|
|
128522
|
+
company?: string;
|
|
128523
|
+
vatId?: {
|
|
128524
|
+
_id?: string;
|
|
128525
|
+
type?: "CPF" | "CNPJ" | "UNSPECIFIED"; // For Brazil only
|
|
128526
|
+
};
|
|
128527
|
+
};
|
|
128528
|
+
}
|
|
128529
|
+
\`\`\`
|
|
128530
|
+
|
|
128531
|
+
### ExtendedFields Object
|
|
128532
|
+
\`\`\`typescript
|
|
128533
|
+
interface ExtendedFields {
|
|
128534
|
+
namespaces?: Record<string, any>; // App-specific extended field data
|
|
128535
|
+
}
|
|
128536
|
+
\`\`\`
|
|
128537
|
+
|
|
128538
|
+
### CustomLineItem Object
|
|
128539
|
+
\`\`\`typescript
|
|
128540
|
+
interface CustomLineItem {
|
|
128541
|
+
_id?: string; // Auto-generated if not provided
|
|
128542
|
+
productName: ProductName; // Required
|
|
128543
|
+
price: string; // Required - number or decimal without symbols
|
|
128544
|
+
itemType: ItemType; // Required
|
|
128545
|
+
quantity?: number; // Min: 1, Max: 100000
|
|
128546
|
+
catalogReference?: CatalogReference;
|
|
128547
|
+
descriptionLines?: Array<DescriptionLine>;
|
|
128548
|
+
media?: string; // Image from Wix media manager
|
|
128549
|
+
url?: string;
|
|
128550
|
+
fullPrice?: string;
|
|
128551
|
+
quantityAvailable?: number;
|
|
128552
|
+
physicalProperties?: PhysicalProperties;
|
|
128553
|
+
deliveryProfileId?: string;
|
|
128554
|
+
taxGroupId?: string;
|
|
128555
|
+
membersOnly?: boolean;
|
|
128556
|
+
paymentOption?: PaymentOptionType;
|
|
128557
|
+
depositAmount?: string;
|
|
128558
|
+
// ... additional fields
|
|
128559
|
+
}
|
|
128560
|
+
\`\`\`
|
|
128561
|
+
|
|
128562
|
+
### CatalogReference Object
|
|
128563
|
+
\`\`\`typescript
|
|
128564
|
+
interface CatalogReference {
|
|
128565
|
+
appId: string; // Required
|
|
128566
|
+
catalogItemId: string; // Required
|
|
128567
|
+
options?: Record<string, any>; // Additional item details
|
|
128568
|
+
}
|
|
128569
|
+
\`\`\`
|
|
128570
|
+
|
|
128571
|
+
### PaymentOptionType
|
|
128572
|
+
\`\`\`typescript
|
|
128573
|
+
type PaymentOptionType =
|
|
128574
|
+
| "FULL_PAYMENT_ONLINE" // Entire payment during checkout
|
|
128575
|
+
| "FULL_PAYMENT_OFFLINE" // Payment after checkout (cash, check, etc.)
|
|
128576
|
+
| "MEMBERSHIP" // Charged to membership
|
|
128577
|
+
| "MEMBERSHIP_OFFLINE" // Membership, manually redeemed by admin
|
|
128578
|
+
| "DEPOSIT_ONLINE" // Partial payment upfront
|
|
128579
|
+
| "MEMBERSHIP_ONLINE_WITH_OFFLINE_REMAINDER"; // Membership + offline remainder
|
|
128580
|
+
\`\`\`
|
|
128581
|
+
|
|
128582
|
+
### ChannelType
|
|
128583
|
+
\`\`\`typescript
|
|
128584
|
+
type ChannelType =
|
|
128585
|
+
| "WEB" // Web client
|
|
128586
|
+
| "POS" // Point of sale
|
|
128587
|
+
| "EBAY" // eBay shop
|
|
128588
|
+
| "AMAZON" // Amazon shop
|
|
128589
|
+
| "FACEBOOK" // Facebook shop
|
|
128590
|
+
| "WIX_APP_STORE" // Wix Owner app
|
|
128591
|
+
| "BACKOFFICE_MERCHANT" // Wix merchant backoffice
|
|
128592
|
+
| "OTHER_PLATFORM"; // Other platform
|
|
128593
|
+
\`\`\`
|
|
128594
|
+
|
|
128595
|
+
### ModifierGroup Object
|
|
128596
|
+
\`\`\`typescript
|
|
128597
|
+
interface ModifierGroup {
|
|
128598
|
+
_id?: string;
|
|
128599
|
+
name?: {
|
|
128600
|
+
original: string;
|
|
128601
|
+
translated?: string;
|
|
128602
|
+
};
|
|
128603
|
+
modifiers?: Array<{
|
|
128604
|
+
_id?: string;
|
|
128605
|
+
label?: {
|
|
128606
|
+
original: string;
|
|
128607
|
+
translated?: string;
|
|
128608
|
+
};
|
|
128609
|
+
price?: MultiCurrencyPrice;
|
|
128610
|
+
quantity?: number;
|
|
128611
|
+
details?: {
|
|
128612
|
+
original: string;
|
|
128613
|
+
translated?: string;
|
|
128614
|
+
};
|
|
128615
|
+
}>;
|
|
128616
|
+
}
|
|
128617
|
+
\`\`\`
|
|
128618
|
+
|
|
128619
|
+
### SelectedMembership Object
|
|
128620
|
+
\`\`\`typescript
|
|
128621
|
+
interface SelectedMembership {
|
|
128622
|
+
_id: string; // Required - Membership GUID
|
|
128623
|
+
appId: string; // Required - App GUID providing this payment option
|
|
128624
|
+
}
|
|
128625
|
+
\`\`\`
|
|
128626
|
+
|
|
128627
|
+
### ServiceProperties Object
|
|
128628
|
+
\`\`\`typescript
|
|
128629
|
+
interface ServiceProperties {
|
|
128630
|
+
numberOfParticipants?: number; // Number of people (class size, hotel room, etc.)
|
|
128631
|
+
scheduledDate?: Date; // ISO-8601 format - when service is provided
|
|
128632
|
+
}
|
|
128633
|
+
\`\`\`
|
|
128634
|
+
|
|
128635
|
+
### EstimateTotalsResponse Object
|
|
128636
|
+
\`\`\`typescript
|
|
128637
|
+
interface EstimateTotalsResponse {
|
|
128638
|
+
cart: Cart;
|
|
128639
|
+
calculatedLineItems: Array<{
|
|
128640
|
+
lineItemId: string;
|
|
128641
|
+
pricesBreakdown: LineItemPricesData;
|
|
128642
|
+
paymentOption?: PaymentOptionType;
|
|
128643
|
+
taxableAddress?: TaxableAddress;
|
|
128644
|
+
}>;
|
|
128645
|
+
priceSummary: PriceSummary;
|
|
128646
|
+
shippingInfo?: ShippingInformation;
|
|
128647
|
+
taxSummary?: TaxSummary;
|
|
128648
|
+
appliedDiscounts?: Array<AppliedDiscount>;
|
|
128649
|
+
additionalFees?: Array<AdditionalFee>;
|
|
128650
|
+
calculationErrors?: CalculationErrors;
|
|
128651
|
+
membershipOptions?: MembershipOptions;
|
|
128652
|
+
currency: string;
|
|
128653
|
+
weightUnit: "KG" | "LB";
|
|
128654
|
+
// ... additional fields
|
|
128655
|
+
}
|
|
128656
|
+
\`\`\`
|
|
128657
|
+
|
|
128658
|
+
### PriceSummary Object
|
|
128659
|
+
\`\`\`typescript
|
|
128660
|
+
interface PriceSummary {
|
|
128661
|
+
subtotal: MultiCurrencyPrice;
|
|
128662
|
+
shipping?: MultiCurrencyPrice;
|
|
128663
|
+
tax?: MultiCurrencyPrice;
|
|
128664
|
+
discount?: MultiCurrencyPrice;
|
|
128665
|
+
total: MultiCurrencyPrice;
|
|
128666
|
+
additionalFees?: MultiCurrencyPrice;
|
|
128667
|
+
}
|
|
128668
|
+
\`\`\`
|
|
128669
|
+
|
|
128670
|
+
### TaxSummary Object
|
|
128671
|
+
\`\`\`typescript
|
|
128672
|
+
interface TaxSummary {
|
|
128673
|
+
taxableAmount?: MultiCurrencyPrice;
|
|
128674
|
+
totalTax?: MultiCurrencyPrice;
|
|
128675
|
+
}
|
|
128676
|
+
\`\`\`
|
|
128677
|
+
|
|
128678
|
+
### ShippingInformation Object
|
|
128679
|
+
\`\`\`typescript
|
|
128680
|
+
interface ShippingInformation {
|
|
128681
|
+
region?: {
|
|
128682
|
+
_id: string;
|
|
128683
|
+
name: string;
|
|
128684
|
+
};
|
|
128685
|
+
selectedCarrierServiceOption?: {
|
|
128686
|
+
carrierId: string;
|
|
128687
|
+
code: string;
|
|
128688
|
+
title: string;
|
|
128689
|
+
cost: {
|
|
128690
|
+
price: MultiCurrencyPrice;
|
|
128691
|
+
totalPriceBeforeTax: MultiCurrencyPrice;
|
|
128692
|
+
totalPriceAfterTax: MultiCurrencyPrice;
|
|
128693
|
+
taxDetails?: ItemTaxFullDetails;
|
|
128694
|
+
totalDiscount?: MultiCurrencyPrice;
|
|
128695
|
+
};
|
|
128696
|
+
logistics?: DeliveryLogistics;
|
|
128697
|
+
requestedShippingOption?: boolean;
|
|
128698
|
+
};
|
|
128699
|
+
carrierServiceOptions?: Array<CarrierServiceOption>;
|
|
128700
|
+
}
|
|
128701
|
+
\`\`\`
|
|
128702
|
+
|
|
128703
|
+
</type_signatures>
|
|
128704
|
+
|
|
128705
|
+
<methods>
|
|
128706
|
+
|
|
128707
|
+
## getCurrentCart()
|
|
128708
|
+
|
|
128709
|
+
Retrieves the current site visitor's cart.
|
|
128710
|
+
|
|
128711
|
+
**Important Notes:**
|
|
128712
|
+
- This method requires visitor or member authentication.
|
|
128713
|
+
|
|
128714
|
+
**Import:**
|
|
128715
|
+
\`\`\`javascript
|
|
128716
|
+
import { currentCart } from '@wix/ecom';
|
|
128717
|
+
\`\`\`
|
|
128718
|
+
|
|
128719
|
+
**Example - General Usage:**
|
|
128720
|
+
\`\`\`javascript
|
|
128721
|
+
import { currentCart } from '@wix/ecom';
|
|
128722
|
+
|
|
128723
|
+
currentCart.getCurrentCart()
|
|
128724
|
+
.then((myCurrentCart) => {
|
|
128725
|
+
const cartId = myCurrentCart._id;
|
|
128726
|
+
const cartLineItems = myCurrentCart.lineItems;
|
|
128727
|
+
console.log('Success! Retrieved myCurrentCart:', myCurrentCart);
|
|
128728
|
+
return myCurrentCart;
|
|
128729
|
+
})
|
|
128730
|
+
.catch((error) => {
|
|
128731
|
+
console.error(error);
|
|
128732
|
+
});
|
|
128733
|
+
\`\`\`
|
|
128734
|
+
|
|
128735
|
+
---
|
|
128736
|
+
|
|
128737
|
+
## addToCurrentCart(options)
|
|
128738
|
+
|
|
128739
|
+
Adds catalog line items to the current site visitor's cart.
|
|
128740
|
+
|
|
128741
|
+
**Important Notes:**
|
|
128742
|
+
- When adding catalog line items, the \`lineItems.catalogReference.appId\` and \`lineItems.catalogReference.catalogItemId\` fields are required.
|
|
128743
|
+
- This method requires visitor or member authentication.
|
|
128744
|
+
- After a cart is updated, call Refresh Cart to update the cart's UI elements and trigger the Cart Updated event.
|
|
128745
|
+
|
|
128746
|
+
**Example - Add a Wix Stores product to the current cart:**
|
|
128747
|
+
\`\`\`javascript
|
|
128748
|
+
// Backend code - my-backend-file.web.js/ts
|
|
128749
|
+
import { Permissions, webMethod } from '@wix/web-methods';
|
|
128750
|
+
import { currentCart } from '@wix/ecom';
|
|
128751
|
+
|
|
128752
|
+
export const myAddToCurrentCartFunction = webMethod(Permissions.Anyone, async (options) => {
|
|
128753
|
+
try {
|
|
128754
|
+
const updatedCurrentCart = await currentCart.addToCurrentCart(options);
|
|
128755
|
+
console.log('Success! Updated current cart:', updatedCurrentCart);
|
|
128756
|
+
return updatedCurrentCart;
|
|
128757
|
+
} catch (error) {
|
|
128758
|
+
console.error(error);
|
|
128759
|
+
}
|
|
128760
|
+
});
|
|
128761
|
+
|
|
128762
|
+
// Page code
|
|
128763
|
+
import { ecom } from "@wix/site-ecom";
|
|
128764
|
+
import { myAddToCurrentCartFunction } from 'backend/my-backend-file.web';
|
|
128765
|
+
|
|
128766
|
+
const options = {
|
|
128767
|
+
"lineItems": [{
|
|
128768
|
+
"catalogReference": {
|
|
128769
|
+
"appId": "215238eb-22a5-4c36-9e7b-e7c08025e04e", // Wix Stores appId
|
|
128770
|
+
"catalogItemId": "1a2d7e83-4bef-31d5-09e1-3326ee271c09", // Wix Stores productId
|
|
128771
|
+
"options": {
|
|
128772
|
+
"variantId": "132b84e8-aab8-47a1-a1f6-2c47557b64a4" // Wix Stores variantId
|
|
128773
|
+
}
|
|
128774
|
+
},
|
|
128775
|
+
"quantity": 1
|
|
128776
|
+
}]
|
|
128777
|
+
};
|
|
128778
|
+
|
|
128779
|
+
const updatedCurrentCart = await myAddToCurrentCartFunction(options);
|
|
128780
|
+
await ecom.refreshCart();
|
|
128781
|
+
await ecom.navigateToCartPage();
|
|
128782
|
+
\`\`\`
|
|
128783
|
+
|
|
128784
|
+
---
|
|
128785
|
+
|
|
128786
|
+
## createCheckoutFromCurrentCart(options)
|
|
128787
|
+
|
|
128788
|
+
Creates a checkout from the current site visitor's cart. If a checkout was already created from the current cart, that checkout will be updated with any new information from the cart.
|
|
128789
|
+
|
|
128790
|
+
**Important Notes:**
|
|
128791
|
+
- \`channelType\` is a required field.
|
|
128792
|
+
- This method requires visitor or member authentication.
|
|
128793
|
+
|
|
128794
|
+
**Example:**
|
|
128795
|
+
\`\`\`javascript
|
|
128796
|
+
// Backend code - my-backend-file.web.js/ts
|
|
128797
|
+
import { Permissions, webMethod } from '@wix/web-methods';
|
|
128798
|
+
import { currentCart } from '@wix/ecom';
|
|
128799
|
+
|
|
128800
|
+
export const myCreateCheckoutFromCurrentCartFunction = webMethod(Permissions.Anyone, async (options) => {
|
|
128801
|
+
try {
|
|
128802
|
+
const checkoutId = await currentCart.createCheckoutFromCurrentCart(options);
|
|
128803
|
+
console.log('Success! Checkout created, checkoutId:', checkoutId);
|
|
128804
|
+
return checkoutId;
|
|
128805
|
+
} catch (error) {
|
|
128806
|
+
console.error(error);
|
|
128807
|
+
}
|
|
128808
|
+
});
|
|
128809
|
+
|
|
128810
|
+
// Page code
|
|
128811
|
+
import { myCreateCheckoutFromCurrentCartFunction } from 'backend/my-backend-file.web';
|
|
128812
|
+
|
|
128813
|
+
const options = {
|
|
128814
|
+
"channelType": "WEB", // required field
|
|
128815
|
+
"email": "janedoe@example.com",
|
|
128816
|
+
"shippingAddress": {
|
|
128817
|
+
"addressLine1": "235 West 23rd Street",
|
|
128818
|
+
"addressLine2": "3rd floor",
|
|
128819
|
+
"city": "New York",
|
|
128820
|
+
"country": "US",
|
|
128821
|
+
"postalCode": "10011",
|
|
128822
|
+
"streetAddress": {
|
|
128823
|
+
"name": "West 23rd Street",
|
|
128824
|
+
"number": "235"
|
|
128825
|
+
},
|
|
128826
|
+
"subdivision": "US-NY"
|
|
128827
|
+
}
|
|
128828
|
+
};
|
|
128829
|
+
|
|
128830
|
+
const checkoutId = await myCreateCheckoutFromCurrentCartFunction(options);
|
|
128831
|
+
\`\`\`
|
|
128832
|
+
|
|
128833
|
+
---
|
|
128834
|
+
|
|
128835
|
+
## estimateCurrentCartTotals(options)
|
|
128836
|
+
|
|
128837
|
+
Estimates the current cart's price totals (including tax), based on a selected carrier service, shipping address, and billing information.
|
|
128838
|
+
|
|
128839
|
+
**Important Notes:**
|
|
128840
|
+
- Not passing any properties will only estimate the cart items price totals, without considering shipping and billing information.
|
|
128841
|
+
- This method requires visitor or member authentication.
|
|
128842
|
+
|
|
128843
|
+
**Example:**
|
|
128844
|
+
\`\`\`javascript
|
|
128845
|
+
// Backend code - my-backend-file.web.js/ts
|
|
128846
|
+
import { Permissions, webMethod } from '@wix/web-methods';
|
|
128847
|
+
import { currentCart } from '@wix/ecom';
|
|
128848
|
+
|
|
128849
|
+
export const myEstimateCurrentCartTotalsFunction = webMethod(Permissions.Anyone, async (estimateOptions) => {
|
|
128850
|
+
try {
|
|
128851
|
+
const estimatedCartTotals = await currentCart.estimateCurrentCartTotals(estimateOptions);
|
|
128852
|
+
console.log('Success! Cart totals estimated:', estimatedCartTotals);
|
|
128853
|
+
return estimatedCartTotals;
|
|
128854
|
+
} catch (error) {
|
|
128855
|
+
console.error(error);
|
|
128856
|
+
}
|
|
128857
|
+
});
|
|
128858
|
+
|
|
128859
|
+
// Page code
|
|
128860
|
+
import { myEstimateCurrentCartTotalsFunction } from 'backend/my-backend-file.web';
|
|
128861
|
+
|
|
128862
|
+
const estimateOptions = {
|
|
128863
|
+
"selectedShippingOption": {
|
|
128864
|
+
"code": "standard_us_shipping"
|
|
128865
|
+
},
|
|
128866
|
+
"shippingAddress": {
|
|
128867
|
+
"addressLine1": "235 West 23rd Street",
|
|
128868
|
+
"addressLine2": "3rd floor",
|
|
128869
|
+
"city": "New York",
|
|
128870
|
+
"country": "US",
|
|
128871
|
+
"postalCode": "10011",
|
|
128872
|
+
"streetAddress": {
|
|
128873
|
+
"name": "West 23rd Street",
|
|
128874
|
+
"number": "235"
|
|
128875
|
+
},
|
|
128876
|
+
"subdivision": "US-NY"
|
|
128877
|
+
},
|
|
128878
|
+
"billingAddress": {
|
|
128879
|
+
"addressLine1": "235 West 23rd Street",
|
|
128880
|
+
"addressLine2": "3rd floor",
|
|
128881
|
+
"city": "New York",
|
|
128882
|
+
"country": "US",
|
|
128883
|
+
"postalCode": "10011",
|
|
128884
|
+
"streetAddress": {
|
|
128885
|
+
"name": "West 23rd Street",
|
|
128886
|
+
"number": "235"
|
|
128887
|
+
},
|
|
128888
|
+
"subdivision": "US-NY"
|
|
128889
|
+
}
|
|
128890
|
+
};
|
|
128891
|
+
|
|
128892
|
+
const estimatedCartTotals = await myEstimateCurrentCartTotalsFunction(estimateOptions);
|
|
128893
|
+
const formattedShippingPrice = estimatedCartTotals.priceSummary.shipping.formattedAmount;
|
|
128894
|
+
const estimatedCartTotal = estimatedCartTotals.priceSummary.total.formattedAmount;
|
|
128895
|
+
\`\`\`
|
|
128896
|
+
|
|
128897
|
+
---
|
|
128898
|
+
|
|
128899
|
+
## updateCurrentCart(options)
|
|
128900
|
+
|
|
128901
|
+
Updates the current site visitor's cart.
|
|
128902
|
+
|
|
128903
|
+
**Important Notes:**
|
|
128904
|
+
- When adding catalog line items, the \`lineItems.catalogReference.appId\` and \`lineItems.catalogReference.catalogItemId\` fields are required.
|
|
128905
|
+
- This method requires visitor or member authentication.
|
|
128906
|
+
- After a cart is updated, call Refresh Cart to update the cart's UI elements and trigger the Cart Updated event.
|
|
128907
|
+
|
|
128908
|
+
**Example - Apply a coupon to the current cart:**
|
|
128909
|
+
\`\`\`javascript
|
|
128910
|
+
// Backend code - my-backend-file.web.js/ts
|
|
128911
|
+
import { Permissions, webMethod } from '@wix/web-methods';
|
|
128912
|
+
import { currentCart } from '@wix/ecom';
|
|
128913
|
+
|
|
128914
|
+
export const myUpdateCurrentCartFunction = webMethod(Permissions.Anyone, async (options) => {
|
|
128915
|
+
try {
|
|
128916
|
+
const updatedCurrentCart = await currentCart.updateCurrentCart(options);
|
|
128917
|
+
console.log('Success! Updated current cart:', updatedCurrentCart);
|
|
128918
|
+
return updatedCurrentCart;
|
|
128919
|
+
} catch (error) {
|
|
128920
|
+
console.error(error);
|
|
128921
|
+
}
|
|
128922
|
+
});
|
|
128923
|
+
|
|
128924
|
+
// Page code
|
|
128925
|
+
import { ecom } from "@wix/site-ecom";
|
|
128926
|
+
import { myUpdateCurrentCartFunction } from 'backend/my-backend-file.web';
|
|
128927
|
+
|
|
128928
|
+
const updateOptions = {
|
|
128929
|
+
"couponCode": "SUMMERSALE10"
|
|
128930
|
+
};
|
|
128931
|
+
|
|
128932
|
+
const updatedCurrentCart = await myUpdateCurrentCartFunction(updateOptions);
|
|
128933
|
+
await ecom.refreshCart();
|
|
128934
|
+
await ecom.navigateToCartPage();
|
|
128935
|
+
\`\`\`
|
|
128936
|
+
|
|
128937
|
+
---
|
|
128938
|
+
|
|
128939
|
+
## updateCurrentCartLineItemQuantity(lineItems)
|
|
128940
|
+
|
|
128941
|
+
Updates the quantity of 1 or more line items in the current site visitor's cart.
|
|
128166
128942
|
|
|
128167
|
-
|
|
128168
|
-
|
|
128943
|
+
**Important Notes:**
|
|
128944
|
+
- This method is only for updating the quantity of line items.
|
|
128945
|
+
- To entirely remove a line item from the current cart, use the removeLineItemsFromCurrentCart method.
|
|
128946
|
+
- To add a new line item to the current cart, use the addToCurrentCart method.
|
|
128947
|
+
- This method checks the amount of stock remaining for this line item. If the specified quantity is greater than the remaining stock, then the quantity returned in the response is the total amount of remaining stock.
|
|
128948
|
+
- This method requires visitor or member authentication.
|
|
128949
|
+
- After a cart is updated, call Refresh Cart to update the cart's UI elements and trigger the Cart Updated event.
|
|
128169
128950
|
|
|
128170
|
-
|
|
128171
|
-
|
|
128951
|
+
**Example:**
|
|
128952
|
+
\`\`\`javascript
|
|
128953
|
+
// Backend code - my-backend-file.web.js/ts
|
|
128954
|
+
import { Permissions, webMethod } from '@wix/web-methods';
|
|
128955
|
+
import { currentCart } from '@wix/ecom';
|
|
128172
128956
|
|
|
128173
|
-
|
|
128957
|
+
export const myUpdateCurrentCartLineItemQuantityFunction = webMethod(Permissions.Anyone, async (lineItems) => {
|
|
128958
|
+
try {
|
|
128959
|
+
const updatedCurrentCart = await currentCart.updateCurrentCartLineItemQuantity(lineItems);
|
|
128960
|
+
console.log('Success! Line item quantities updated:', updatedCurrentCart);
|
|
128961
|
+
return updatedCurrentCart;
|
|
128962
|
+
} catch (error) {
|
|
128963
|
+
console.error(error);
|
|
128964
|
+
}
|
|
128965
|
+
});
|
|
128966
|
+
|
|
128967
|
+
// Page code
|
|
128968
|
+
import { ecom } from "@wix/site-ecom";
|
|
128969
|
+
import { myUpdateCurrentCartLineItemQuantityFunction } from 'backend/my-backend-file.web';
|
|
128970
|
+
|
|
128971
|
+
const lineItems = [
|
|
128972
|
+
{
|
|
128973
|
+
"_id": '00000000-0000-0000-0000-000000000001',
|
|
128974
|
+
"quantity": 2
|
|
128975
|
+
},
|
|
128976
|
+
{
|
|
128977
|
+
"_id": '00000000-0000-0000-0000-000000000002',
|
|
128978
|
+
"quantity": 3
|
|
128979
|
+
}
|
|
128980
|
+
];
|
|
128981
|
+
|
|
128982
|
+
const updatedCurrentCart = await myUpdateCurrentCartLineItemQuantityFunction(lineItems);
|
|
128983
|
+
await ecom.refreshCart();
|
|
128984
|
+
await ecom.navigateToCartPage();
|
|
128985
|
+
\`\`\`
|
|
128986
|
+
|
|
128987
|
+
---
|
|
128988
|
+
|
|
128989
|
+
## removeCouponFromCurrentCart()
|
|
128990
|
+
|
|
128991
|
+
Removes the coupon from the current site visitor's cart.
|
|
128992
|
+
|
|
128993
|
+
**Important Notes:**
|
|
128994
|
+
- This method requires visitor or member authentication.
|
|
128995
|
+
- After a cart is updated, call Refresh Cart to update the cart's UI elements and trigger the Cart Updated event.
|
|
128996
|
+
|
|
128997
|
+
**Example:**
|
|
128998
|
+
\`\`\`javascript
|
|
128999
|
+
// Backend code - my-backend-file.web.js/ts
|
|
129000
|
+
import { Permissions, webMethod } from '@wix/web-methods';
|
|
129001
|
+
import { currentCart } from '@wix/ecom';
|
|
129002
|
+
|
|
129003
|
+
export const myRemoveCouponFromCurrentCartFunction = webMethod(Permissions.Anyone, async () => {
|
|
129004
|
+
try {
|
|
129005
|
+
const updatedCurrentCart = await currentCart.removeCouponFromCurrentCart();
|
|
129006
|
+
console.log('Success! Updated current cart:', updatedCurrentCart);
|
|
129007
|
+
return updatedCurrentCart;
|
|
129008
|
+
} catch (error) {
|
|
129009
|
+
console.error(error);
|
|
129010
|
+
}
|
|
129011
|
+
});
|
|
129012
|
+
|
|
129013
|
+
// Page code
|
|
129014
|
+
import { ecom } from "@wix/site-ecom";
|
|
129015
|
+
import { myRemoveCouponFromCurrentCartFunction } from 'backend/my-backend-file.web';
|
|
129016
|
+
|
|
129017
|
+
const updatedCurrentCart = await myRemoveCouponFromCurrentCartFunction();
|
|
129018
|
+
await ecom.refreshCart();
|
|
129019
|
+
await ecom.navigateToCartPage();
|
|
129020
|
+
\`\`\`
|
|
129021
|
+
|
|
129022
|
+
---
|
|
129023
|
+
|
|
129024
|
+
## removeLineItemsFromCurrentCart(lineItemIds)
|
|
129025
|
+
|
|
129026
|
+
Removes line items from the current site visitor's cart.
|
|
129027
|
+
|
|
129028
|
+
**Important Notes:**
|
|
129029
|
+
- This method requires visitor or member authentication.
|
|
129030
|
+
- After a cart is updated, call Refresh Cart to update the cart's UI elements and trigger the Cart Updated event.
|
|
129031
|
+
|
|
129032
|
+
**Example - Remove 3 line items from the current cart:**
|
|
129033
|
+
\`\`\`javascript
|
|
129034
|
+
// Backend code - my-backend-file.web.js/ts
|
|
129035
|
+
import { Permissions, webMethod } from '@wix/web-methods';
|
|
129036
|
+
import { currentCart } from '@wix/ecom';
|
|
129037
|
+
|
|
129038
|
+
export const myRemoveLineItemsFromCurrentCartFunction = webMethod(Permissions.Anyone, async (lineItemIds) => {
|
|
129039
|
+
try {
|
|
129040
|
+
const updatedCurrentCart = await currentCart.removeLineItemsFromCurrentCart(lineItemIds);
|
|
129041
|
+
console.log('Success! Line items removed from cart:', updatedCurrentCart);
|
|
129042
|
+
return updatedCurrentCart;
|
|
129043
|
+
} catch (error) {
|
|
129044
|
+
console.error(error);
|
|
129045
|
+
}
|
|
129046
|
+
});
|
|
129047
|
+
|
|
129048
|
+
// Page code
|
|
129049
|
+
import { ecom } from "@wix/site-ecom";
|
|
129050
|
+
import { myRemoveLineItemsFromCurrentCartFunction } from 'backend/my-backend-file.web';
|
|
129051
|
+
|
|
129052
|
+
const lineItemIds = [
|
|
129053
|
+
'00000000-0000-0000-0000-000000000001',
|
|
129054
|
+
'00000000-0000-0000-0000-000000000002',
|
|
129055
|
+
'00000000-0000-0000-0000-000000000003'
|
|
129056
|
+
];
|
|
129057
|
+
|
|
129058
|
+
const updatedCurrentCart = await myRemoveLineItemsFromCurrentCartFunction(lineItemIds);
|
|
129059
|
+
await ecom.refreshCart();
|
|
129060
|
+
await ecom.navigateToCartPage();
|
|
129061
|
+
\`\`\`
|
|
129062
|
+
|
|
129063
|
+
---
|
|
129064
|
+
|
|
129065
|
+
## deleteCurrentCart()
|
|
129066
|
+
|
|
129067
|
+
Deletes the current site visitor's cart.
|
|
129068
|
+
|
|
129069
|
+
**Important Notes:**
|
|
129070
|
+
- This method requires visitor or member authentication.
|
|
129071
|
+
|
|
129072
|
+
**Example:**
|
|
129073
|
+
\`\`\`javascript
|
|
129074
|
+
// Backend code - my-backend-file.web.js/ts
|
|
129075
|
+
import { Permissions, webMethod } from '@wix/web-methods';
|
|
129076
|
+
import { currentCart } from '@wix/ecom';
|
|
129077
|
+
|
|
129078
|
+
export const myDeleteCurrentCartFunction = webMethod(Permissions.Anyone, async () => {
|
|
129079
|
+
try {
|
|
129080
|
+
await currentCart.deleteCurrentCart();
|
|
129081
|
+
console.log('Success! Deleted cart');
|
|
129082
|
+
return;
|
|
129083
|
+
} catch (error) {
|
|
129084
|
+
console.error(error);
|
|
129085
|
+
}
|
|
129086
|
+
});
|
|
129087
|
+
|
|
129088
|
+
// Page code
|
|
129089
|
+
import { myDeleteCurrentCartFunction } from 'backend/my-backend-file.web';
|
|
129090
|
+
|
|
129091
|
+
myDeleteCurrentCartFunction()
|
|
129092
|
+
.then(() => {
|
|
129093
|
+
console.log('Success! Deleted current cart');
|
|
129094
|
+
})
|
|
129095
|
+
.catch((error) => {
|
|
129096
|
+
console.error(error);
|
|
129097
|
+
});
|
|
129098
|
+
\`\`\`
|
|
129099
|
+
|
|
129100
|
+
</methods>
|
|
129101
|
+
|
|
129102
|
+
<events>
|
|
129103
|
+
|
|
129104
|
+
## onCartCreated(handler)
|
|
129105
|
+
|
|
129106
|
+
Triggered when a cart is created.
|
|
129107
|
+
|
|
129108
|
+
**Event Handler:**
|
|
129109
|
+
\`\`\`javascript
|
|
129110
|
+
import { currentCart } from '@wix/ecom';
|
|
129111
|
+
|
|
129112
|
+
currentCart.onCartCreated((event) => {
|
|
129113
|
+
const cart = event.entity;
|
|
129114
|
+
console.log('Cart created:', cart);
|
|
129115
|
+
});
|
|
129116
|
+
\`\`\`
|
|
129117
|
+
|
|
129118
|
+
---
|
|
129119
|
+
|
|
129120
|
+
## onCartUpdated(handler)
|
|
129121
|
+
|
|
129122
|
+
Triggered when a cart is updated.
|
|
129123
|
+
|
|
129124
|
+
**Event Handler:**
|
|
129125
|
+
\`\`\`javascript
|
|
129126
|
+
import { currentCart } from '@wix/ecom';
|
|
129127
|
+
|
|
129128
|
+
currentCart.onCartUpdated((event) => {
|
|
129129
|
+
const cart = event.entity;
|
|
129130
|
+
console.log('Cart updated:', cart);
|
|
129131
|
+
});
|
|
129132
|
+
\`\`\`
|
|
129133
|
+
|
|
129134
|
+
---
|
|
129135
|
+
|
|
129136
|
+
## onCartDeleted(handler)
|
|
129137
|
+
|
|
129138
|
+
Triggered when a cart is deleted.
|
|
129139
|
+
|
|
129140
|
+
**Event Handler:**
|
|
129141
|
+
\`\`\`javascript
|
|
129142
|
+
import { currentCart } from '@wix/ecom';
|
|
129143
|
+
|
|
129144
|
+
currentCart.onCartDeleted((event) => {
|
|
129145
|
+
const cartId = event.metadata.entityId;
|
|
129146
|
+
console.log('Cart deleted:', cartId);
|
|
129147
|
+
});
|
|
129148
|
+
\`\`\`
|
|
129149
|
+
|
|
129150
|
+
</events>
|
|
129151
|
+
|
|
129152
|
+
<migration_note>
|
|
129153
|
+
To assist in migration from the Stores to eCommerce APIs, please refer to the Stores to eCommerce Cart Conversion Table.
|
|
129154
|
+
</migration_note>
|
|
129155
|
+
|
|
129156
|
+
</ecom_cart_docs>
|
|
129157
|
+
`;
|
|
129158
|
+
exports2.cartPrompt = cartPrompt;
|
|
129159
|
+
}
|
|
129160
|
+
});
|
|
129161
|
+
|
|
129162
|
+
// dist/system-prompts/embeddedScript/data.js
|
|
129163
|
+
var require_data4 = __commonJS({
|
|
129164
|
+
"dist/system-prompts/embeddedScript/data.js"(exports2) {
|
|
129165
|
+
"use strict";
|
|
129166
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
129167
|
+
exports2.dataPrompt = void 0;
|
|
129168
|
+
var dataPrompt = () => `
|
|
129169
|
+
<wix_data_integration>
|
|
128174
129170
|
<description>
|
|
128175
|
-
|
|
129171
|
+
This embedded script can access and display dynamic content from Wix Data collections.
|
|
128176
129172
|
|
|
128177
|
-
|
|
129173
|
+
IMPORTANT: Since collections are provided in the CREATED COLLECTIONS section, you MUST use @wix/data to interact with them - BUT ONLY if the collection is relevant to your use case. Import and use the data module to query, retrieve, and display collection items in your embedded script when they serve a clear purpose in the script's functionality.
|
|
128178
129174
|
</description>
|
|
128179
129175
|
|
|
128180
|
-
<
|
|
128181
|
-
|
|
128182
|
-
-
|
|
128183
|
-
-
|
|
129176
|
+
<wix_data_docs>
|
|
129177
|
+
Summary:
|
|
129178
|
+
- Read: items.query('Collection').filter/sort.limit.find() \u2192 { items, totalCount, hasNext }
|
|
129179
|
+
- Embedded scripts primarily use read-only data operations for displaying dynamic content
|
|
128184
129180
|
|
|
128185
|
-
|
|
128186
|
-
|
|
129181
|
+
Access data using the collection schema:
|
|
129182
|
+
- Always use the exact field keys you defined in the collection schema.
|
|
129183
|
+
- YOU MUST use the collection id exactly as you defined it in the collection schema.
|
|
129184
|
+
- YOU MUST use the collection schema's exact field types for all operations (query, insert, update, remove)
|
|
129185
|
+
- All custom fields are stored in the [key: string]: any part of the WixDataItem interface
|
|
128187
129186
|
|
|
128188
|
-
|
|
128189
|
-
|
|
128190
|
-
- ESSENTIAL: Enables site visitors to move around the site and use essential features like secure and private areas crucial to the functioning of the site.
|
|
128191
|
-
- FUNCTIONAL: Remembers choices site visitors make to improve their experience, such as language.
|
|
128192
|
-
- ANALYTICS: Provides statistics to the site owner on how visitors use the site, such as which pages they visit. This helps improve the site by identifying errors and performance issues.
|
|
128193
|
-
- ADVERTISING: Provides visitor information to the site owner to help market their products, such as data on the impact of marketing campaigns, re-targeted advertising, and so on.
|
|
128194
|
-
An embedded script must have a type. If your script falls into more than one type, choose the option closest to the bottom of the list above. For example, if your script has Advertising and Analytics aspects, choose Advertising as its type. It's unlikely that you'll need to mark it as Essential.
|
|
128195
|
-
</script_types>
|
|
129187
|
+
Import (for backend-rendered embedded scripts):
|
|
129188
|
+
import { items } from '@wix/data';
|
|
128196
129189
|
|
|
128197
|
-
|
|
128198
|
-
An enum indicating where in the page's DOM the HTML code will be injected. Possible values are:
|
|
128199
|
-
- HEAD: Injects the code between the page's <head> and </head> tags.
|
|
128200
|
-
- BODY_START: Injects the code immediately after the page's opening <body> tag.
|
|
128201
|
-
- BODY_END: Injects the code immediately before the page's closing </body> tag.
|
|
128202
|
-
</placement_options>
|
|
129190
|
+
Available Methods:
|
|
128203
129191
|
|
|
128204
|
-
|
|
128205
|
-
|
|
128206
|
-
|
|
128207
|
-
|
|
128208
|
-
|
|
129192
|
+
#### items.query(dataCollectionId: string)
|
|
129193
|
+
- **Description**: Creates a query to retrieve items from a collection. Supports filtering, sorting, and pagination via chaining methods.
|
|
129194
|
+
Use for reading dynamic content to display in embedded scripts.
|
|
129195
|
+
The query() method runs with the following WixDataQuery defaults that you can override:
|
|
129196
|
+
- skip: 0
|
|
129197
|
+
- limit: 50
|
|
129198
|
+
- descending: by _createdDate
|
|
129199
|
+
- include: none
|
|
129200
|
+
- Example:
|
|
129201
|
+
const result = await items.query("myCollection")
|
|
129202
|
+
.eq("status", "active")
|
|
129203
|
+
.limit(10)
|
|
129204
|
+
.find();
|
|
128209
129205
|
|
|
128210
|
-
|
|
129206
|
+
#### items.get(dataCollectionId: string, itemId: string)
|
|
129207
|
+
- **Description**: Retrieves a single item by ID from a collection.
|
|
129208
|
+
Use for fetching specific content entries.
|
|
129209
|
+
- Example:
|
|
129210
|
+
const item = await items.get("myCollection", "00001");
|
|
128211
129211
|
|
|
128212
|
-
|
|
128213
|
-
|
|
128214
|
-
|
|
128215
|
-
|
|
128216
|
-
|
|
128217
|
-
|
|
128218
|
-
|
|
128219
|
-
|
|
129212
|
+
Note: Embedded scripts should primarily focus on read operations. For write operations (insert, update, remove),
|
|
129213
|
+
consider using backend code (HTTP functions or service plugins) and calling them from the embedded script via fetch/AJAX.
|
|
129214
|
+
</wix_data_docs>
|
|
129215
|
+
|
|
129216
|
+
<usage_in_embedded_scripts>
|
|
129217
|
+
|
|
129218
|
+
1. Relevant Collection Usage (CRITICAL):
|
|
129219
|
+
- Only use collections that are directly relevant to your embedded script's functionality
|
|
129220
|
+
- Ignore collections that don't apply to what you're implementing
|
|
129221
|
+
- Each collection you query should serve a clear purpose in the script's behavior
|
|
129222
|
+
- It's perfectly fine to not use any collections if they're not applicable to your use case
|
|
129223
|
+
- Don't force data usage just because collections exist - use them only when they add value
|
|
129224
|
+
|
|
129225
|
+
2. DIRECT SDK USAGE (REQUIRED):
|
|
129226
|
+
- Embedded scripts MUST use @wix/data SDK directly - DO NOT use fetch() calls to API endpoints
|
|
129227
|
+
- Import and use the items module from @wix/data directly in your embedded script
|
|
129228
|
+
- NEVER create fetch() calls to /api/* endpoints for data operations
|
|
129229
|
+
- Use items.query() directly in the embedded script code
|
|
129230
|
+
|
|
129231
|
+
3. Display Dynamic Content:
|
|
129232
|
+
- Query collections directly using @wix/data to get dynamic content that's relevant to your embedded script
|
|
129233
|
+
- Render the data in your HTML/JavaScript
|
|
129234
|
+
- Handle loading states and errors gracefully
|
|
129235
|
+
|
|
129236
|
+
4. Example Pattern - Displaying Collection Items:
|
|
129237
|
+
<div id="content-container"></div>
|
|
129238
|
+
<script type="module">
|
|
129239
|
+
import { items } from '@wix/data';
|
|
129240
|
+
|
|
129241
|
+
// CORRECT: Use @wix/data directly
|
|
129242
|
+
async function loadContent() {
|
|
129243
|
+
try {
|
|
129244
|
+
const result = await items.query('myCollection')
|
|
129245
|
+
.limit(10)
|
|
129246
|
+
.find();
|
|
129247
|
+
|
|
129248
|
+
const container = document.getElementById('content-container');
|
|
129249
|
+
result.items.forEach(item => {
|
|
129250
|
+
const el = document.createElement('div');
|
|
129251
|
+
el.textContent = item.title;
|
|
129252
|
+
container.appendChild(el);
|
|
129253
|
+
});
|
|
129254
|
+
} catch (error) {
|
|
129255
|
+
console.error('Failed to load content:', error);
|
|
129256
|
+
}
|
|
129257
|
+
}
|
|
129258
|
+
|
|
129259
|
+
loadContent();
|
|
129260
|
+
</script>
|
|
129261
|
+
|
|
129262
|
+
5. Best Practices:
|
|
129263
|
+
- Cache data when appropriate to reduce queries
|
|
129264
|
+
- Handle empty states gracefully
|
|
129265
|
+
- Show loading indicators for better UX
|
|
129266
|
+
- Implement error handling for failed queries
|
|
129267
|
+
- Consider pagination for large datasets
|
|
129268
|
+
|
|
129269
|
+
</usage_in_embedded_scripts>
|
|
128220
129270
|
|
|
128221
|
-
<
|
|
128222
|
-
|
|
128223
|
-
|
|
128224
|
-
|
|
128225
|
-
|
|
128226
|
-
|
|
128227
|
-
|
|
128228
|
-
|
|
128229
|
-
- Analytics/tracking \u2192 HEAD (initialize early)
|
|
128230
|
-
- Advertising \u2192 BODY_END (non-blocking)
|
|
128231
|
-
- Critical functionality \u2192 HEAD or BODY_START
|
|
128232
|
-
- Non-critical features \u2192 BODY_END (performance)
|
|
128233
|
-
4. Implement complete business logic with proper error handling
|
|
128234
|
-
5. Use template variables {{variableName}} for configurable values (API keys, settings, etc.)
|
|
128235
|
-
6. Include proper TypeScript imports when using external modules
|
|
128236
|
-
</generation_requirements>
|
|
129271
|
+
<validation_requirements>
|
|
129272
|
+
- Only query collections that are directly relevant to your embedded script's specific use case
|
|
129273
|
+
- Ignore collections that don't contribute to the functionality you're implementing
|
|
129274
|
+
- Each collection query should serve a clear, necessary purpose
|
|
129275
|
+
- Don't include data operations just because collections are available
|
|
129276
|
+
- Use the exact collection IDs and field keys as defined in the collection schema
|
|
129277
|
+
- Handle cases where collections might be empty or queries might fail
|
|
129278
|
+
</validation_requirements>
|
|
128237
129279
|
|
|
128238
|
-
|
|
129280
|
+
</wix_data_integration>
|
|
129281
|
+
`;
|
|
129282
|
+
exports2.dataPrompt = dataPrompt;
|
|
129283
|
+
}
|
|
129284
|
+
});
|
|
128239
129285
|
|
|
128240
|
-
|
|
129286
|
+
// dist/system-prompts/embeddedScript/dynamicParameters.js
|
|
129287
|
+
var require_dynamicParameters3 = __commonJS({
|
|
129288
|
+
"dist/system-prompts/embeddedScript/dynamicParameters.js"(exports2) {
|
|
129289
|
+
"use strict";
|
|
129290
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
129291
|
+
exports2.dynamicParametersPrompt = void 0;
|
|
129292
|
+
var dynamicParametersPrompt = () => `
|
|
128241
129293
|
<dynamic_parameters_usage>
|
|
128242
129294
|
|
|
128243
129295
|
<description>
|
|
@@ -128357,8 +129409,104 @@ Pattern 3 - Conditional Logic:
|
|
|
128357
129409
|
</validation_requirements>
|
|
128358
129410
|
|
|
128359
129411
|
</dynamic_parameters_usage>
|
|
128360
|
-
|
|
129412
|
+
`;
|
|
129413
|
+
exports2.dynamicParametersPrompt = dynamicParametersPrompt;
|
|
129414
|
+
}
|
|
129415
|
+
});
|
|
129416
|
+
|
|
129417
|
+
// dist/system-prompts/embeddedScript/embededScript.js
|
|
129418
|
+
var require_embededScript = __commonJS({
|
|
129419
|
+
"dist/system-prompts/embeddedScript/embededScript.js"(exports2) {
|
|
129420
|
+
"use strict";
|
|
129421
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
129422
|
+
exports2.embeddedScriptPrompt = void 0;
|
|
129423
|
+
var cart_1 = require_cart();
|
|
129424
|
+
var data_1 = require_data4();
|
|
129425
|
+
var dynamicParameters_1 = require_dynamicParameters3();
|
|
129426
|
+
var embeddedScriptPrompt = (hasDynamicParameters, useData = false) => {
|
|
129427
|
+
return `
|
|
129428
|
+
<WIXCLI_EMBEDDED_SCRIPT_SYSTEM_PROMPT>
|
|
129429
|
+
|
|
129430
|
+
<role>
|
|
129431
|
+
You are a senior Wix CLI App Developer Expert specialized in creating embedded scripts for Wix applications. You have deep knowledge of embedded script best practices, HTML/JavaScript injection patterns, and third-party integrations.
|
|
129432
|
+
|
|
129433
|
+
You are tasked with generating a complete Wix CLI embedded script implementation based on the user's requirements.
|
|
129434
|
+
</role>
|
|
129435
|
+
|
|
129436
|
+
<embedded_script_extension_files_and_code>
|
|
129437
|
+
<description>
|
|
129438
|
+
Embedded scripts are HTML code fragments that get injected into the DOM of Wix sites. They enable integration with third-party services, analytics tracking, advertising, and custom JavaScript functionality.
|
|
129439
|
+
|
|
129440
|
+
Each embedded script lives in its own folder under src/site/embedded-scripts/ and you generate the embedded.html file containing the HTML/JavaScript code to be injected.
|
|
129441
|
+
</description>
|
|
129442
|
+
|
|
129443
|
+
<metadata_fields>
|
|
129444
|
+
You will also specify metadata that determines how the script is injected:
|
|
129445
|
+
- scriptType: ESSENTIAL | FUNCTIONAL | ANALYTICS | ADVERTISING
|
|
129446
|
+
- placement: HEAD | BODY_START | BODY_END
|
|
129447
|
+
|
|
129448
|
+
These are returned separately from the HTML file.
|
|
129449
|
+
</metadata_fields>
|
|
129450
|
+
|
|
129451
|
+
<script_types>
|
|
129452
|
+
An enum used by consent management apps to determine whether site visitors consent to having your script run during their visit. Possible values are:
|
|
129453
|
+
- ESSENTIAL: Enables site visitors to move around the site and use essential features like secure and private areas crucial to the functioning of the site.
|
|
129454
|
+
- FUNCTIONAL: Remembers choices site visitors make to improve their experience, such as language.
|
|
129455
|
+
- ANALYTICS: Provides statistics to the site owner on how visitors use the site, such as which pages they visit. This helps improve the site by identifying errors and performance issues.
|
|
129456
|
+
- ADVERTISING: Provides visitor information to the site owner to help market their products, such as data on the impact of marketing campaigns, re-targeted advertising, and so on.
|
|
129457
|
+
An embedded script must have a type. If your script falls into more than one type, choose the option closest to the bottom of the list above. For example, if your script has Advertising and Analytics aspects, choose Advertising as its type. It's unlikely that you'll need to mark it as Essential.
|
|
129458
|
+
</script_types>
|
|
129459
|
+
|
|
129460
|
+
<placement_options>
|
|
129461
|
+
An enum indicating where in the page's DOM the HTML code will be injected. Possible values are:
|
|
129462
|
+
- HEAD: Injects the code between the page's <head> and </head> tags.
|
|
129463
|
+
- BODY_START: Injects the code immediately after the page's opening <body> tag.
|
|
129464
|
+
- BODY_END: Injects the code immediately before the page's closing </body> tag.
|
|
129465
|
+
</placement_options>
|
|
129466
|
+
|
|
129467
|
+
<template_variables>
|
|
129468
|
+
Embedded scripts support parameterization using template variable syntax {{variableName}}.
|
|
129469
|
+
- Correct: <div data-value="{{myVariable}}"></div>
|
|
129470
|
+
- Common use cases: API keys, configuration values, user-specific data
|
|
129471
|
+
</template_variables>
|
|
129472
|
+
|
|
129473
|
+
</embedded_script_extension_files_and_code>
|
|
129474
|
+
|
|
129475
|
+
<core_principles>
|
|
129476
|
+
- Do NOT invent or assume new types, modules, functions, or imports not available in standard browser APIs or explicitly imported libraries
|
|
129477
|
+
- NEVER use mocks, placeholders, or TODOs in any code
|
|
129478
|
+
- ALWAYS implement complete, production-ready functionality
|
|
129479
|
+
- Handle errors gracefully and fail silently when appropriate for embedded scripts
|
|
129480
|
+
- Minimize performance impact - embedded scripts should be lightweight and non-blocking
|
|
129481
|
+
- Follow web security best practices (avoid inline event handlers, validate data, escape user input)
|
|
129482
|
+
- ONLY create fetch() calls to /api/* endpoints that are explicitly defined in the provided API spec - verify each endpoint exists before using it
|
|
129483
|
+
- If no API spec is provided, do NOT create ANY /api/* fetch calls
|
|
129484
|
+
</core_principles>
|
|
129485
|
+
|
|
129486
|
+
<generation_requirements>
|
|
129487
|
+
1. Generate the embedded.html file with complete HTML/JavaScript implementation
|
|
129488
|
+
2. **VERIFY API ENDPOINTS**: Before using fetch() to /api/*, confirm the endpoint exists in "## API SPEC" section
|
|
129489
|
+
3. Specify appropriate scriptType based on the use case:
|
|
129490
|
+
- Analytics tools \u2192 ANALYTICS
|
|
129491
|
+
- Ad networks, marketing pixels \u2192 ADVERTISING
|
|
129492
|
+
- Core functionality \u2192 ESSENTIAL
|
|
129493
|
+
- Enhanced features \u2192 FUNCTIONAL
|
|
129494
|
+
5. Choose optimal placement:
|
|
129495
|
+
- Analytics/tracking \u2192 HEAD (initialize early)
|
|
129496
|
+
- Advertising \u2192 BODY_END (non-blocking)
|
|
129497
|
+
- Critical functionality \u2192 HEAD or BODY_START
|
|
129498
|
+
- Non-critical features \u2192 BODY_END (performance)
|
|
129499
|
+
6. Implement complete business logic with proper error handling
|
|
129500
|
+
7. Use template variables {{variableName}} for configurable values and backend data
|
|
129501
|
+
</generation_requirements>
|
|
129502
|
+
|
|
129503
|
+
<implementation_guidelines>
|
|
129504
|
+
|
|
129505
|
+
${useData ? (0, data_1.dataPrompt)() : ""}
|
|
128361
129506
|
|
|
129507
|
+
${hasDynamicParameters ? (0, dynamicParameters_1.dynamicParametersPrompt)() : ""}
|
|
129508
|
+
|
|
129509
|
+
${(0, cart_1.cartPrompt)()}
|
|
128362
129510
|
</WIXCLI_EMBEDDED_SCRIPT_SYSTEM_PROMPT>
|
|
128363
129511
|
`;
|
|
128364
129512
|
};
|
|
@@ -128404,14 +129552,15 @@ var require_EmbeddedScriptAgent = __commonJS({
|
|
|
128404
129552
|
this.apiKey = apiKey;
|
|
128405
129553
|
this.name = "EmbeddedScriptAgent";
|
|
128406
129554
|
}
|
|
128407
|
-
|
|
128408
|
-
return (0, embededScript_1.embeddedScriptPrompt)(hasDynamicParameters);
|
|
129555
|
+
buildSystemPrompt(hasDynamicParameters, useData) {
|
|
129556
|
+
return (0, embededScript_1.embeddedScriptPrompt)(hasDynamicParameters, useData);
|
|
128409
129557
|
}
|
|
128410
129558
|
async generate(params) {
|
|
128411
129559
|
const { blueprint, planAndResources } = params;
|
|
128412
129560
|
const examples = (0, load_examples_1.loadExamples)([load_examples_1.types.EmbeddedScript]);
|
|
128413
129561
|
const hasDynamicParameters = Boolean(planAndResources?.embeddedScriptParameters && planAndResources.embeddedScriptParameters.length > 0);
|
|
128414
|
-
const
|
|
129562
|
+
const useData = Boolean(planAndResources?.createdCollections?.length);
|
|
129563
|
+
const systemPrompt = `${this.buildSystemPrompt(hasDynamicParameters, useData)}
|
|
128415
129564
|
${examples}
|
|
128416
129565
|
`;
|
|
128417
129566
|
console.log(`Embedded Script Agent System Prompt length: ${systemPrompt.length} (is that what you expect?)`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/ditto-codegen-public",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.56",
|
|
4
4
|
"description": "AI-powered Wix CLI app generator - standalone executable",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "node build.mjs",
|
|
@@ -24,5 +24,5 @@
|
|
|
24
24
|
"@wix/ditto-codegen": "1.0.0",
|
|
25
25
|
"esbuild": "^0.25.9"
|
|
26
26
|
},
|
|
27
|
-
"falconPackageHash": "
|
|
27
|
+
"falconPackageHash": "ac4c956df1113dd695b40d48a736148438db44885aa1e6be180cf235"
|
|
28
28
|
}
|