@wix/ditto-codegen-public 1.0.56 → 1.0.58
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/docs-output/api-docs/data-items-get-doc.txt +72 -0
- package/dist/docs-output/api-docs/data-items-insert-doc.txt +55 -0
- package/dist/docs-output/api-docs/data-items-query-doc.txt +316 -0
- package/dist/docs-output/api-docs/data-items-remove-doc.txt +50 -0
- package/dist/docs-output/api-docs/data-items-update-doc.txt +57 -0
- package/dist/docs-output/api-docs/ecom-cart-onCartCreated-doc.txt +71 -67
- package/dist/docs-output/api-docs/ecom-cart-onCartUpdated-doc.txt +71 -68
- package/dist/docs-output/api-docs/ecom-currentCart-getCurrentCart-doc.txt +330 -0
- package/dist/out.js +62 -1255
- package/package.json +2 -2
package/dist/out.js
CHANGED
|
@@ -77705,74 +77705,35 @@ var require_servicePluginDocLoader = __commonJS({
|
|
|
77705
77705
|
}
|
|
77706
77706
|
});
|
|
77707
77707
|
|
|
77708
|
-
// dist/system-prompts/
|
|
77709
|
-
var
|
|
77710
|
-
"dist/system-prompts/
|
|
77708
|
+
// dist/system-prompts/apiDocLoader.js
|
|
77709
|
+
var require_apiDocLoader = __commonJS({
|
|
77710
|
+
"dist/system-prompts/apiDocLoader.js"(exports2) {
|
|
77711
77711
|
"use strict";
|
|
77712
77712
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
77713
|
-
exports2.
|
|
77714
|
-
|
|
77715
|
-
|
|
77716
|
-
|
|
77717
|
-
|
|
77718
|
-
|
|
77719
|
-
|
|
77720
|
-
|
|
77721
|
-
|
|
77722
|
-
|
|
77723
|
-
|
|
77724
|
-
|
|
77725
|
-
|
|
77726
|
-
|
|
77727
|
-
|
|
77728
|
-
|
|
77729
|
-
|
|
77730
|
-
|
|
77731
|
-
|
|
77732
|
-
|
|
77733
|
-
|
|
77734
|
-
|
|
77735
|
-
|
|
77736
|
-
|
|
77737
|
-
- include: none
|
|
77738
|
-
|
|
77739
|
-
#### items.insert(dataCollectionId: string, item: object)
|
|
77740
|
-
- **Description**: Inserts an item into a collection.
|
|
77741
|
-
Use for creating configuration entries and dynamic content.
|
|
77742
|
-
- Example:
|
|
77743
|
-
const toInsert = {
|
|
77744
|
-
title: "Mr.",
|
|
77745
|
-
first_name: "John",
|
|
77746
|
-
last_name: "Doe",
|
|
77747
|
-
};
|
|
77748
|
-
const inserted = await items.insert("myCollection", toInsert);
|
|
77749
|
-
|
|
77750
|
-
#### items.update(dataCollectionId: string, item: WixDataItem)
|
|
77751
|
-
- **Description**: Updates an item in a collection. The item to update must include an \`_id\` property.
|
|
77752
|
-
Use for modifying configuration settings and content updates.
|
|
77753
|
-
- \`WixDataItem\` is an object with the following structure:
|
|
77754
|
-
- \`_id\` (string): Data item ID.
|
|
77755
|
-
- Example:
|
|
77756
|
-
const toUpdate = {
|
|
77757
|
-
_id: "00001",
|
|
77758
|
-
title: "Mr.",
|
|
77759
|
-
first_name: "John",
|
|
77760
|
-
last_name: "Doe",
|
|
77761
|
-
};
|
|
77762
|
-
const updated = await items.update("myCollection", toUpdate);
|
|
77763
|
-
|
|
77764
|
-
#### items.get(dataCollectionId: string, itemId: string)
|
|
77765
|
-
- **Description**: Retrieves a single item by ID from a collection.
|
|
77766
|
-
Use for fetching specific configuration or content entries.
|
|
77767
|
-
- Example:
|
|
77768
|
-
const item = await items.get("myCollection", "00001");
|
|
77769
|
-
|
|
77770
|
-
#### items.remove(collectionId: string, itemId: string)
|
|
77771
|
-
- **Description**: Deletes an item from a collection.
|
|
77772
|
-
Use for cleaning up configuration or removing content entries.
|
|
77773
|
-
- Example:
|
|
77774
|
-
const result = await items.remove("myCollection", "00001");
|
|
77775
|
-
</wix_data_docs>`;
|
|
77713
|
+
exports2.loadApiDocumentation = loadApiDocumentation;
|
|
77714
|
+
var docLoader_1 = require_docLoader();
|
|
77715
|
+
var API_TO_DOC_MAPPING = {
|
|
77716
|
+
"stores.productsV3.updateProduct": "stores-productsV3-updateProduct-doc.txt",
|
|
77717
|
+
"stores.products.onProductCreated": "stores-productV3-onProductCreated-doc.txt",
|
|
77718
|
+
"data.items.onDataItemCreated": "data-items-onDataItemCreated.txt",
|
|
77719
|
+
"data.items.query": "data-items-query-doc.tsx",
|
|
77720
|
+
"data.items.insert": "data-items-insert-doc.txt",
|
|
77721
|
+
"data.items.remove": "data-items-remove-doc.txt",
|
|
77722
|
+
"data.items.update": "data-items-update-doc.txt",
|
|
77723
|
+
"data.items.get": "data-items-get-doc.txt",
|
|
77724
|
+
"crm.contacts.onContactCreated": "crm-contacts-onContactCreated-doc.txt",
|
|
77725
|
+
"ecom.cart.onCartCreated": "ecom-cart-onCartCreated-doc.txt",
|
|
77726
|
+
"ecom.cart.onCartUpdated": "ecom-cart-onCartUpdated-doc.txt",
|
|
77727
|
+
"ecom.currentCart.getCurrentCart": "ecom-currentCart-getCurrentCart-doc.txt"
|
|
77728
|
+
};
|
|
77729
|
+
function loadApiDocumentation(apiNames) {
|
|
77730
|
+
const apiDocs = (0, docLoader_1.loadDocumentation)(apiNames, API_TO_DOC_MAPPING, docLoader_1.DocType.API);
|
|
77731
|
+
return apiDocs ? `
|
|
77732
|
+
<api_docs>
|
|
77733
|
+
${apiDocs}
|
|
77734
|
+
</api_docs>
|
|
77735
|
+
` : "";
|
|
77736
|
+
}
|
|
77776
77737
|
}
|
|
77777
77738
|
});
|
|
77778
77739
|
|
|
@@ -77784,9 +77745,10 @@ var require_servicePluginPrompt = __commonJS({
|
|
|
77784
77745
|
exports2.servicePluginPrompt = void 0;
|
|
77785
77746
|
exports2.getServicePluginPrompt = getServicePluginPrompt;
|
|
77786
77747
|
var servicePluginDocLoader_1 = require_servicePluginDocLoader();
|
|
77787
|
-
var
|
|
77788
|
-
function getServicePluginPrompt(spiNames = [],
|
|
77748
|
+
var apiDocLoader_1 = require_apiDocLoader();
|
|
77749
|
+
function getServicePluginPrompt(spiNames = [], apiNames = []) {
|
|
77789
77750
|
const servicePluginDocs = (0, servicePluginDocLoader_1.loadServicePluginDocumentation)(spiNames);
|
|
77751
|
+
const apiDocs = (0, apiDocLoader_1.loadApiDocumentation)(apiNames);
|
|
77790
77752
|
return `
|
|
77791
77753
|
<WIXCLI_SERVICE_PLUGIN_SYSTEM_PROMPT>
|
|
77792
77754
|
|
|
@@ -77899,8 +77861,7 @@ When integrating with external services:
|
|
|
77899
77861
|
<available_service_plugins>
|
|
77900
77862
|
${servicePluginDocs}
|
|
77901
77863
|
</available_service_plugins>
|
|
77902
|
-
|
|
77903
|
-
${useData ? data_1.dataPrompt : ""}
|
|
77864
|
+
${apiDocs}
|
|
77904
77865
|
`;
|
|
77905
77866
|
}
|
|
77906
77867
|
exports2.servicePluginPrompt = getServicePluginPrompt();
|
|
@@ -120290,27 +120251,6 @@ var require_index_node = __commonJS({
|
|
|
120290
120251
|
}
|
|
120291
120252
|
});
|
|
120292
120253
|
|
|
120293
|
-
// dist/system-prompts/apiDocLoader.js
|
|
120294
|
-
var require_apiDocLoader = __commonJS({
|
|
120295
|
-
"dist/system-prompts/apiDocLoader.js"(exports2) {
|
|
120296
|
-
"use strict";
|
|
120297
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
120298
|
-
exports2.loadApiDocumentation = loadApiDocumentation;
|
|
120299
|
-
var docLoader_1 = require_docLoader();
|
|
120300
|
-
var API_TO_DOC_MAPPING = {
|
|
120301
|
-
"stores.productsV3.updateProduct": "stores-productsV3-updateProduct-doc.txt",
|
|
120302
|
-
"stores.products.onProductCreated": "stores-productV3-onProductCreated-doc.txt",
|
|
120303
|
-
"data.items.onDataItemCreated": "data-items-onDataItemCreated.txt",
|
|
120304
|
-
"crm.contacts.onContactCreated": "crm-contacts-onContactCreated-doc.txt",
|
|
120305
|
-
"ecom.cart.onCartCreated": "ecom-cart-onCartCreated-doc.txt",
|
|
120306
|
-
"ecom.cart.onCartUpdated": "ecom-cart-onCartUpdated-doc.txt"
|
|
120307
|
-
};
|
|
120308
|
-
function loadApiDocumentation(apiNames) {
|
|
120309
|
-
return (0, docLoader_1.loadDocumentation)(apiNames, API_TO_DOC_MAPPING, docLoader_1.DocType.API);
|
|
120310
|
-
}
|
|
120311
|
-
}
|
|
120312
|
-
});
|
|
120313
|
-
|
|
120314
120254
|
// dist/agents/utils.js
|
|
120315
120255
|
var require_utils14 = __commonJS({
|
|
120316
120256
|
"dist/agents/utils.js"(exports2) {
|
|
@@ -120325,7 +120265,6 @@ var require_utils14 = __commonJS({
|
|
|
120325
120265
|
var http_client_1 = require_index_node();
|
|
120326
120266
|
var fs_1 = __importDefault2(require("fs"));
|
|
120327
120267
|
var path_1 = __importDefault2(require("path"));
|
|
120328
|
-
var apiDocLoader_1 = require_apiDocLoader();
|
|
120329
120268
|
exports2.FileItemSchema = zod_1.z.object({
|
|
120330
120269
|
operation: zod_1.z.enum(["insert", "update", "delete"]).describe("File operation: insert (new file), update (modify existing), delete (remove file)").default("insert"),
|
|
120331
120270
|
path: zod_1.z.string().describe("Relative file path from project root").optional(),
|
|
@@ -120433,13 +120372,6 @@ ${JSON.stringify(planAndResources.apiSpec, null, 2)}`);
|
|
|
120433
120372
|
contextSections.push(`
|
|
120434
120373
|
## EMBEDDED SCRIPT PARAMETERS
|
|
120435
120374
|
${JSON.stringify(planAndResources.embeddedScriptParameters, null, 2)}`);
|
|
120436
|
-
}
|
|
120437
|
-
if (extension.relatedApis?.length) {
|
|
120438
|
-
const apiNames = (0, exports2.extractApiNames)(params.extension);
|
|
120439
|
-
const apiDocs = (0, apiDocLoader_1.loadApiDocumentation)(apiNames);
|
|
120440
|
-
contextSections.push(`
|
|
120441
|
-
## RELATED APIS
|
|
120442
|
-
${apiDocs}`);
|
|
120443
120375
|
}
|
|
120444
120376
|
const userMessage = `${primaryAction}:
|
|
120445
120377
|
${contextSections.join("\n")}`;
|
|
@@ -120747,15 +120679,15 @@ var require_SPIAgent = __commonJS({
|
|
|
120747
120679
|
this.apiKey = apiKey;
|
|
120748
120680
|
this.name = "SPIAgent";
|
|
120749
120681
|
}
|
|
120750
|
-
buildSystemPrompt(spiNames = [],
|
|
120751
|
-
return (0, servicePluginPrompt_1.getServicePluginPrompt)(spiNames,
|
|
120682
|
+
buildSystemPrompt(spiNames = [], apiNames = []) {
|
|
120683
|
+
return (0, servicePluginPrompt_1.getServicePluginPrompt)(spiNames, apiNames);
|
|
120752
120684
|
}
|
|
120753
120685
|
async generate(params) {
|
|
120754
|
-
const { extension, blueprint
|
|
120686
|
+
const { extension, blueprint } = params;
|
|
120755
120687
|
const examples = (0, load_examples_1.loadExamples)([load_examples_1.types.ServicePluginExtension]);
|
|
120756
120688
|
const allSpiNames = extension.relatedSpis?.map((spi) => spi.name).filter((name) => !!name) || [];
|
|
120757
|
-
const
|
|
120758
|
-
const systemPrompt = `${this.buildSystemPrompt(allSpiNames,
|
|
120689
|
+
const apiNames = (0, utils_1.extractApiNames)(params.extension);
|
|
120690
|
+
const systemPrompt = `${this.buildSystemPrompt(allSpiNames, apiNames)}
|
|
120759
120691
|
${examples}
|
|
120760
120692
|
`;
|
|
120761
120693
|
console.log(`SPI Agent System Prompt length: ${systemPrompt.length} (is that what you expect?)`);
|
|
@@ -120983,7 +120915,7 @@ ${JSON.stringify(todoExample, null, 2)}
|
|
|
120983
120915
|
});
|
|
120984
120916
|
|
|
120985
120917
|
// dist/system-prompts/planner/data.js
|
|
120986
|
-
var
|
|
120918
|
+
var require_data = __commonJS({
|
|
120987
120919
|
"dist/system-prompts/planner/data.js"(exports2) {
|
|
120988
120920
|
"use strict";
|
|
120989
120921
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
@@ -121266,7 +121198,7 @@ var require_planner = __commonJS({
|
|
|
121266
121198
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
121267
121199
|
exports2.plannerPrompt = void 0;
|
|
121268
121200
|
var apiSpec_1 = require_apiSpec();
|
|
121269
|
-
var data_1 =
|
|
121201
|
+
var data_1 = require_data();
|
|
121270
121202
|
var dynamicParameters_1 = require_dynamicParameters();
|
|
121271
121203
|
var plannerPrompt = (hasEmbeddedScriptExtensions, hasBackendApiExtensions) => {
|
|
121272
121204
|
return `
|
|
@@ -125000,7 +124932,9 @@ var require_backendEventPrompt = __commonJS({
|
|
|
125000
124932
|
"use strict";
|
|
125001
124933
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
125002
124934
|
exports2.backendEventPrompt = void 0;
|
|
125003
|
-
var
|
|
124935
|
+
var apiDocLoader_1 = require_apiDocLoader();
|
|
124936
|
+
var backendEventPrompt = (apiNames) => {
|
|
124937
|
+
const apiDocs = (0, apiDocLoader_1.loadApiDocumentation)(apiNames);
|
|
125004
124938
|
return `<BACKEND_EVENT_PROMPT>
|
|
125005
124939
|
<role>
|
|
125006
124940
|
You are a Wix backend event handler generator. Create event extensions for Wix CLI apps using the JavaScript SDK. Events are triggered when specific conditions on the app or user's site are met.
|
|
@@ -125034,6 +124968,7 @@ You are a Wix backend event handler generator. Create event extensions for Wix C
|
|
|
125034
124968
|
- Reference the corresponding SDK submodule category for event-specific information
|
|
125035
124969
|
- Events run automatically when triggered - no manual invocation needed
|
|
125036
124970
|
</implementation_guidelines>
|
|
124971
|
+
${apiDocs}
|
|
125037
124972
|
</BACKEND_EVENT_PROMPT>`;
|
|
125038
124973
|
};
|
|
125039
124974
|
exports2.backendEventPrompt = backendEventPrompt;
|
|
@@ -125093,13 +125028,14 @@ var require_BackendEventAgent = __commonJS({
|
|
|
125093
125028
|
this.apiKey = apiKey;
|
|
125094
125029
|
this.name = "BackendEventAgent";
|
|
125095
125030
|
}
|
|
125096
|
-
buildSystemPrompt() {
|
|
125097
|
-
return (0, backendEventPrompt_1.backendEventPrompt)();
|
|
125031
|
+
buildSystemPrompt(apiNames = []) {
|
|
125032
|
+
return (0, backendEventPrompt_1.backendEventPrompt)(apiNames);
|
|
125098
125033
|
}
|
|
125099
125034
|
async generate(params) {
|
|
125100
125035
|
const { blueprint } = params;
|
|
125101
125036
|
const examples = (0, load_examples_1.default)([load_examples_1.types.BackendEvent]);
|
|
125102
|
-
const
|
|
125037
|
+
const allApiNames = (0, utils_1.extractApiNames)(params.extension);
|
|
125038
|
+
const systemPrompt = `${this.buildSystemPrompt(allApiNames)}
|
|
125103
125039
|
${examples}
|
|
125104
125040
|
`;
|
|
125105
125041
|
const appName = blueprint?.appName ? `'${blueprint.appName}'` : "";
|
|
@@ -126546,7 +126482,7 @@ ${blocks}
|
|
|
126546
126482
|
});
|
|
126547
126483
|
|
|
126548
126484
|
// dist/system-prompts/dashboardPage/data.js
|
|
126549
|
-
var
|
|
126485
|
+
var require_data2 = __commonJS({
|
|
126550
126486
|
"dist/system-prompts/dashboardPage/data.js"(exports2) {
|
|
126551
126487
|
"use strict";
|
|
126552
126488
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
@@ -127098,9 +127034,10 @@ var require_dashboardPagePrompt = __commonJS({
|
|
|
127098
127034
|
var ecomPackage_1 = require_ecomPackage();
|
|
127099
127035
|
var dashboardPackage_1 = require_dashboardPackage();
|
|
127100
127036
|
var wdsPackage_1 = require_wdsPackage();
|
|
127101
|
-
var data_1 =
|
|
127037
|
+
var data_1 = require_data2();
|
|
127102
127038
|
var apiSpecPrompt_1 = require_apiSpecPrompt();
|
|
127103
127039
|
var dynamicParameters_1 = require_dynamicParameters2();
|
|
127040
|
+
var apiDocLoader_1 = require_apiDocLoader();
|
|
127104
127041
|
var wdsPackage_2 = require_wdsPackage();
|
|
127105
127042
|
Object.defineProperty(exports2, "buildWdsSystemPrompt", { enumerable: true, get: function() {
|
|
127106
127043
|
return wdsPackage_2.buildWdsSystemPrompt;
|
|
@@ -127130,8 +127067,9 @@ var require_dashboardPagePrompt = __commonJS({
|
|
|
127130
127067
|
"ToggleSwitch",
|
|
127131
127068
|
"InfoIcon"
|
|
127132
127069
|
];
|
|
127133
|
-
var dashboardPagePrompt = async ({ useData, useApiSpec, useDynamicParameters }) => {
|
|
127070
|
+
var dashboardPagePrompt = async ({ useData, useApiSpec, useDynamicParameters, apiNames }) => {
|
|
127134
127071
|
const wdsPrompt = await (0, wdsPackage_1.buildWdsSystemPrompt)(listOfWdsComponents);
|
|
127072
|
+
const apiDocs = (0, apiDocLoader_1.loadApiDocumentation)(apiNames);
|
|
127135
127073
|
return `
|
|
127136
127074
|
<WIXCLI_DASHBOARD_PAGE_SYSTEM_PROMPT>
|
|
127137
127075
|
|
|
@@ -127196,7 +127134,7 @@ You are tasked with generating a complete Wix CLI dashboard page implementation
|
|
|
127196
127134
|
${dashboardPackage_1.dashboardPackage}
|
|
127197
127135
|
${ecomPackage_1.ecomPackage}
|
|
127198
127136
|
</api_references>
|
|
127199
|
-
|
|
127137
|
+
${apiDocs}
|
|
127200
127138
|
<wds_reference>
|
|
127201
127139
|
${wdsPrompt}
|
|
127202
127140
|
</wds_reference>
|
|
@@ -127247,7 +127185,8 @@ var require_DashboardPageAgent = __commonJS({
|
|
|
127247
127185
|
const useData = Boolean(planAndResources?.createdCollections?.length);
|
|
127248
127186
|
const useApiSpec = Boolean(planAndResources?.apiSpec);
|
|
127249
127187
|
const useDynamicParameters = Boolean(planAndResources?.embeddedScriptParameters?.length);
|
|
127250
|
-
const
|
|
127188
|
+
const apiNames = (0, utils_1.extractApiNames)(params.extension);
|
|
127189
|
+
const systemPrompt = `${await this.buildSystemPrompt({ useData, useApiSpec, useDynamicParameters, apiNames })}
|
|
127251
127190
|
${examples}
|
|
127252
127191
|
`;
|
|
127253
127192
|
console.log(`Dashboard Agent System Prompt length: ${systemPrompt.length} (is that what you expect?)`);
|
|
@@ -128154,1135 +128093,6 @@ export default withDashboard(CollectionPage);
|
|
|
128154
128093
|
}
|
|
128155
128094
|
});
|
|
128156
128095
|
|
|
128157
|
-
// dist/system-prompts/SDK/ecom/cart.js
|
|
128158
|
-
var require_cart = __commonJS({
|
|
128159
|
-
"dist/system-prompts/SDK/ecom/cart.js"(exports2) {
|
|
128160
|
-
"use strict";
|
|
128161
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
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.
|
|
128942
|
-
|
|
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.
|
|
128950
|
-
|
|
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';
|
|
128956
|
-
|
|
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>
|
|
129170
|
-
<description>
|
|
129171
|
-
This embedded script can access and display dynamic content from Wix Data collections.
|
|
129172
|
-
|
|
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.
|
|
129174
|
-
</description>
|
|
129175
|
-
|
|
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
|
|
129180
|
-
|
|
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
|
|
129186
|
-
|
|
129187
|
-
Import (for backend-rendered embedded scripts):
|
|
129188
|
-
import { items } from '@wix/data';
|
|
129189
|
-
|
|
129190
|
-
Available Methods:
|
|
129191
|
-
|
|
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();
|
|
129205
|
-
|
|
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");
|
|
129211
|
-
|
|
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>
|
|
129270
|
-
|
|
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>
|
|
129279
|
-
|
|
129280
|
-
</wix_data_integration>
|
|
129281
|
-
`;
|
|
129282
|
-
exports2.dataPrompt = dataPrompt;
|
|
129283
|
-
}
|
|
129284
|
-
});
|
|
129285
|
-
|
|
129286
128096
|
// dist/system-prompts/embeddedScript/dynamicParameters.js
|
|
129287
128097
|
var require_dynamicParameters3 = __commonJS({
|
|
129288
128098
|
"dist/system-prompts/embeddedScript/dynamicParameters.js"(exports2) {
|
|
@@ -129420,10 +128230,10 @@ var require_embededScript = __commonJS({
|
|
|
129420
128230
|
"use strict";
|
|
129421
128231
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
129422
128232
|
exports2.embeddedScriptPrompt = void 0;
|
|
129423
|
-
var
|
|
129424
|
-
var data_1 = require_data4();
|
|
128233
|
+
var apiDocLoader_1 = require_apiDocLoader();
|
|
129425
128234
|
var dynamicParameters_1 = require_dynamicParameters3();
|
|
129426
|
-
var embeddedScriptPrompt = (hasDynamicParameters,
|
|
128235
|
+
var embeddedScriptPrompt = (hasDynamicParameters, apiNames) => {
|
|
128236
|
+
const apiDocs = (0, apiDocLoader_1.loadApiDocumentation)(apiNames);
|
|
129427
128237
|
return `
|
|
129428
128238
|
<WIXCLI_EMBEDDED_SCRIPT_SYSTEM_PROMPT>
|
|
129429
128239
|
|
|
@@ -129501,12 +128311,9 @@ Embedded scripts support parameterization using template variable syntax {{varia
|
|
|
129501
128311
|
</generation_requirements>
|
|
129502
128312
|
|
|
129503
128313
|
<implementation_guidelines>
|
|
129504
|
-
|
|
129505
|
-
${useData ? (0, data_1.dataPrompt)() : ""}
|
|
129506
|
-
|
|
129507
128314
|
${hasDynamicParameters ? (0, dynamicParameters_1.dynamicParametersPrompt)() : ""}
|
|
129508
128315
|
|
|
129509
|
-
${
|
|
128316
|
+
${apiDocs}
|
|
129510
128317
|
</WIXCLI_EMBEDDED_SCRIPT_SYSTEM_PROMPT>
|
|
129511
128318
|
`;
|
|
129512
128319
|
};
|
|
@@ -129552,15 +128359,15 @@ var require_EmbeddedScriptAgent = __commonJS({
|
|
|
129552
128359
|
this.apiKey = apiKey;
|
|
129553
128360
|
this.name = "EmbeddedScriptAgent";
|
|
129554
128361
|
}
|
|
129555
|
-
buildSystemPrompt(hasDynamicParameters,
|
|
129556
|
-
return (0, embededScript_1.embeddedScriptPrompt)(hasDynamicParameters,
|
|
128362
|
+
buildSystemPrompt(hasDynamicParameters, apiNames) {
|
|
128363
|
+
return (0, embededScript_1.embeddedScriptPrompt)(hasDynamicParameters, apiNames);
|
|
129557
128364
|
}
|
|
129558
128365
|
async generate(params) {
|
|
129559
128366
|
const { blueprint, planAndResources } = params;
|
|
129560
128367
|
const examples = (0, load_examples_1.loadExamples)([load_examples_1.types.EmbeddedScript]);
|
|
129561
128368
|
const hasDynamicParameters = Boolean(planAndResources?.embeddedScriptParameters && planAndResources.embeddedScriptParameters.length > 0);
|
|
129562
|
-
const
|
|
129563
|
-
const systemPrompt = `${this.buildSystemPrompt(hasDynamicParameters,
|
|
128369
|
+
const apiNames = (0, utils_1.extractApiNames)(params.extension);
|
|
128370
|
+
const systemPrompt = `${this.buildSystemPrompt(hasDynamicParameters, apiNames)}
|
|
129564
128371
|
${examples}
|
|
129565
128372
|
`;
|
|
129566
128373
|
console.log(`Embedded Script Agent System Prompt length: ${systemPrompt.length} (is that what you expect?)`);
|