@wix/ditto-codegen-public 1.0.241 → 1.0.243
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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useCallback, useState, type FC } from "react";
|
|
2
2
|
import { productsV3 } from "@wix/stores";
|
|
3
|
+
import { httpClient } from "@wix/essentials";
|
|
3
4
|
import { Text, Box, Card, Input, Loader } from "@wix/design-system";
|
|
4
5
|
import * as Icons from "@wix/wix-ui-icons-common";
|
|
5
6
|
import styles from "./ProductChat.module.css";
|
|
@@ -9,12 +10,14 @@ export type ChatMessage = {
|
|
|
9
10
|
author: "Business Buddy" | "User";
|
|
10
11
|
};
|
|
11
12
|
|
|
13
|
+
const baseApiUrl = new URL(import.meta.url).origin;
|
|
14
|
+
|
|
12
15
|
async function submitProductChatMessage(
|
|
13
16
|
messages: ChatMessage[],
|
|
14
17
|
product: productsV3.V3Product,
|
|
15
18
|
) {
|
|
16
19
|
try {
|
|
17
|
-
const response = await
|
|
20
|
+
const response = await httpClient.fetchWithAuth(`${baseApiUrl}/api/chat`, {
|
|
18
21
|
method: "POST",
|
|
19
22
|
headers: {
|
|
20
23
|
"Content-Type": "application/json",
|
package/dist/out.js
CHANGED
|
@@ -34,12 +34,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
34
34
|
));
|
|
35
35
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
36
|
|
|
37
|
-
// ../../node_modules/@wix/ambassador-ctp-codegen-job-service-v1-job/build/
|
|
37
|
+
// ../../node_modules/@wix/ambassador-ctp-codegen-job-service-v1-job/cjs/build/types.impl.js
|
|
38
38
|
var require_types_impl = __commonJS({
|
|
39
|
-
"../../node_modules/@wix/ambassador-ctp-codegen-job-service-v1-job/build/
|
|
39
|
+
"../../node_modules/@wix/ambassador-ctp-codegen-job-service-v1-job/cjs/build/types.impl.js"(exports2) {
|
|
40
40
|
"use strict";
|
|
41
41
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
42
|
-
exports2.Status = exports2.TaskKind = void 0;
|
|
42
|
+
exports2.UserDecisionQuestionType = exports2.Status = exports2.TaskKind = void 0;
|
|
43
43
|
var TaskKind;
|
|
44
44
|
(function(TaskKind2) {
|
|
45
45
|
TaskKind2["UNKNOWN_TASK_KIND"] = "UNKNOWN_TASK_KIND";
|
|
@@ -59,6 +59,11 @@ var require_types_impl = __commonJS({
|
|
|
59
59
|
Status2["PENDING_CANCEL"] = "PENDING_CANCEL";
|
|
60
60
|
Status2["AWAITING_USER_INPUT"] = "AWAITING_USER_INPUT";
|
|
61
61
|
})(Status || (exports2.Status = Status = {}));
|
|
62
|
+
var UserDecisionQuestionType;
|
|
63
|
+
(function(UserDecisionQuestionType2) {
|
|
64
|
+
UserDecisionQuestionType2["UNKNOWN_QUESTION_TYPE"] = "UNKNOWN_QUESTION_TYPE";
|
|
65
|
+
UserDecisionQuestionType2["UI_COMPONENT_TYPE"] = "UI_COMPONENT_TYPE";
|
|
66
|
+
})(UserDecisionQuestionType || (exports2.UserDecisionQuestionType = UserDecisionQuestionType = {}));
|
|
62
67
|
}
|
|
63
68
|
});
|
|
64
69
|
|
|
@@ -6498,9 +6503,9 @@ var require_ambassador_index = __commonJS({
|
|
|
6498
6503
|
}
|
|
6499
6504
|
});
|
|
6500
6505
|
|
|
6501
|
-
// ../../node_modules/@wix/ambassador-ctp-codegen-job-service-v1-job/build/
|
|
6506
|
+
// ../../node_modules/@wix/ambassador-ctp-codegen-job-service-v1-job/cjs/build/http.impl.js
|
|
6502
6507
|
var require_http_impl = __commonJS({
|
|
6503
|
-
"../../node_modules/@wix/ambassador-ctp-codegen-job-service-v1-job/build/
|
|
6508
|
+
"../../node_modules/@wix/ambassador-ctp-codegen-job-service-v1-job/cjs/build/http.impl.js"(exports2) {
|
|
6504
6509
|
"use strict";
|
|
6505
6510
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
6506
6511
|
exports2.listProjects = listProjects;
|
|
@@ -88366,12 +88371,12 @@ var require_api2 = __commonJS({
|
|
|
88366
88371
|
}
|
|
88367
88372
|
});
|
|
88368
88373
|
|
|
88369
|
-
// ../../node_modules/@wix/ambassador-data-v2-data-collection/build/
|
|
88374
|
+
// ../../node_modules/@wix/ambassador-data-v2-data-collection/cjs/build/types.impl.js
|
|
88370
88375
|
var require_types_impl3 = __commonJS({
|
|
88371
|
-
"../../node_modules/@wix/ambassador-data-v2-data-collection/build/
|
|
88376
|
+
"../../node_modules/@wix/ambassador-data-v2-data-collection/cjs/build/types.impl.js"(exports2) {
|
|
88372
88377
|
"use strict";
|
|
88373
88378
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
88374
|
-
exports2.WebhookIdentityType = exports2.IndexSource = exports2.IndexStatus = exports2.Order = exports2.TenantMode = exports2.SortOrder = exports2.Segment = exports2.AccessLevel = exports2.PagingMode = exports2.Type = exports2.Format = exports2.Status = exports2.Role = exports2.FieldPluginType = exports2.PageLinkType = exports2.QueryOperator = exports2.FieldType = exports2.CollectionOperation = exports2.DataOperation = exports2.Direction = exports2.CollectionType = void 0;
|
|
88379
|
+
exports2.WebhookIdentityType = exports2.IndexSource = exports2.IndexStatus = exports2.Order = exports2.TenantMode = exports2.SortOrder = exports2.Segment = exports2.AccessLevel = exports2.PagingMode = exports2.Type = exports2.Format = exports2.Status = exports2.Role = exports2.Permission = exports2.FieldPluginType = exports2.PageLinkType = exports2.QueryOperator = exports2.FieldType = exports2.CollectionOperation = exports2.DataOperation = exports2.Direction = exports2.CollectionType = void 0;
|
|
88375
88380
|
var CollectionType;
|
|
88376
88381
|
(function(CollectionType2) {
|
|
88377
88382
|
CollectionType2["NATIVE"] = "NATIVE";
|
|
@@ -88477,6 +88482,11 @@ var require_types_impl3 = __commonJS({
|
|
|
88477
88482
|
FieldPluginType2["UNKNOWN"] = "UNKNOWN";
|
|
88478
88483
|
FieldPluginType2["CMS"] = "CMS";
|
|
88479
88484
|
})(FieldPluginType || (exports2.FieldPluginType = FieldPluginType = {}));
|
|
88485
|
+
var Permission;
|
|
88486
|
+
(function(Permission2) {
|
|
88487
|
+
Permission2["ANYONE"] = "ANYONE";
|
|
88488
|
+
Permission2["RESTRICTED"] = "RESTRICTED";
|
|
88489
|
+
})(Permission || (exports2.Permission = Permission = {}));
|
|
88480
88490
|
var Role;
|
|
88481
88491
|
(function(Role2) {
|
|
88482
88492
|
Role2["UNKNOWN_ROLE"] = "UNKNOWN_ROLE";
|
|
@@ -91124,6 +91134,21 @@ You will be given an API specification under the "API SPEC" spec.
|
|
|
91124
91134
|
The dashboard page code you generate can make API calls to these endpoints to read and write data.
|
|
91125
91135
|
You cannot write the API calls yourself, you must use the API calls provided in the API SPEC.
|
|
91126
91136
|
|
|
91137
|
+
<http_client_usage>
|
|
91138
|
+
IMPORTANT: Always use httpClient.fetchWithAuth() from @wix/essentials for API calls.
|
|
91139
|
+
This ensures proper authentication and authorization for all requests.
|
|
91140
|
+
|
|
91141
|
+
Import pattern:
|
|
91142
|
+
\`\`\`typescript
|
|
91143
|
+
import { httpClient } from '@wix/essentials';
|
|
91144
|
+
\`\`\`
|
|
91145
|
+
|
|
91146
|
+
Base URL construction:
|
|
91147
|
+
\`\`\`typescript
|
|
91148
|
+
const baseApiUrl = new URL(import.meta.url).origin;
|
|
91149
|
+
\`\`\`
|
|
91150
|
+
</http_client_usage>
|
|
91151
|
+
|
|
91127
91152
|
<example_api_spec>
|
|
91128
91153
|
${JSON.stringify({
|
|
91129
91154
|
name: "Todo Management API",
|
|
@@ -91217,16 +91242,20 @@ ${JSON.stringify({
|
|
|
91217
91242
|
</example_api_spec>
|
|
91218
91243
|
|
|
91219
91244
|
<example_output_code>
|
|
91245
|
+
import { httpClient } from '@wix/essentials';
|
|
91246
|
+
|
|
91247
|
+
const baseApiUrl = new URL(import.meta.url).origin;
|
|
91248
|
+
|
|
91220
91249
|
// Reading data - GET request
|
|
91221
91250
|
async function getTodos(): Promise<Todo[]> {
|
|
91222
|
-
const response = await
|
|
91251
|
+
const response = await httpClient.fetchWithAuth(\`\${baseApiUrl}/api/todos\`);
|
|
91223
91252
|
const data = await response.json();
|
|
91224
91253
|
return data;
|
|
91225
91254
|
}
|
|
91226
91255
|
|
|
91227
91256
|
// Writing data - POST request with data model entity
|
|
91228
91257
|
async function createTodo(todo: Omit<Todo, 'id' | 'createdAt'>): Promise<Todo> {
|
|
91229
|
-
const response = await
|
|
91258
|
+
const response = await httpClient.fetchWithAuth(\`\${baseApiUrl}/api/todos\`, {
|
|
91230
91259
|
method: 'POST',
|
|
91231
91260
|
headers: {
|
|
91232
91261
|
'Content-Type': 'application/json',
|
|
@@ -91239,7 +91268,7 @@ async function createTodo(todo: Omit<Todo, 'id' | 'createdAt'>): Promise<Todo> {
|
|
|
91239
91268
|
|
|
91240
91269
|
// Writing data - PUT request with data model entity
|
|
91241
91270
|
async function updateTodo(id: string, todo: Partial<Todo>): Promise<Todo> {
|
|
91242
|
-
const response = await
|
|
91271
|
+
const response = await httpClient.fetchWithAuth(\`\${baseApiUrl}/api/todos/\${id}\`, {
|
|
91243
91272
|
method: 'PUT',
|
|
91244
91273
|
headers: {
|
|
91245
91274
|
'Content-Type': 'application/json',
|
|
@@ -122138,7 +122167,7 @@ var require_backend_api_instructions = __commonJS({
|
|
|
122138
122167
|
"use strict";
|
|
122139
122168
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
122140
122169
|
exports2.backendApiInstructions = void 0;
|
|
122141
|
-
var backendApiRole = `You are a specialized code-generation agent for creating Astro Server Endpoints (API Routes) for
|
|
122170
|
+
var backendApiRole = `You are a specialized code-generation agent for creating Astro Server Endpoints (API Routes) for Wix CLI applications.`;
|
|
122142
122171
|
var backendApiImplementationGuidelines = `Generate clean, well-structured Astro Server Endpoints based on the API Spec that follow these patterns and best practices.
|
|
122143
122172
|
Focus on creating maintainable, secure, and efficient API routes that integrate well with frontend applications.`;
|
|
122144
122173
|
var backendApiCoreKnowledge = `<astro_server_endpoints_overview>
|
|
@@ -122147,70 +122176,159 @@ Focus on creating maintainable, secure, and efficient API routes that integrate
|
|
|
122147
122176
|
- Each file exports named functions for HTTP methods (GET, POST, PUT, DELETE, etc.)
|
|
122148
122177
|
- Files use the \`.ts\` extension and are automatically converted to API endpoints
|
|
122149
122178
|
</astro_server_endpoints_overview>
|
|
122179
|
+
|
|
122150
122180
|
<file_structure_and_naming>
|
|
122151
122181
|
- API routes are created in \`src/pages/api/\` directory
|
|
122152
|
-
- File names become the endpoint path (e.g.,
|
|
122153
|
-
-
|
|
122154
|
-
-
|
|
122155
|
-
-
|
|
122182
|
+
- File names become the endpoint path (e.g., \`src/pages/api/users.ts\` \u2192 \`/api/users\`)
|
|
122183
|
+
- For dynamic routes with parameters, use square brackets in the filename:
|
|
122184
|
+
- \`src/pages/api/users/[id].ts\` \u2192 \`/api/users/:id\`
|
|
122185
|
+
- \`src/pages/api/posts/[slug].ts\` \u2192 \`/api/posts/:slug\`
|
|
122186
|
+
- \`src/pages/api/users/[userId]/posts/[postId].ts\` \u2192 \`/api/users/:userId/posts/:postId\`
|
|
122187
|
+
</file_structure_and_naming>
|
|
122156
122188
|
|
|
122157
|
-
|
|
122158
|
-
|
|
122159
|
-
|
|
122160
|
-
|
|
122161
|
-
|
|
122162
|
-
const id = params.id;
|
|
122163
|
-
const user = await getUser(id);
|
|
122164
|
-
|
|
122165
|
-
if (!user) {
|
|
122166
|
-
return new Response(null, {
|
|
122167
|
-
status: 404,
|
|
122168
|
-
statusText: "Not found",
|
|
122169
|
-
});
|
|
122170
|
-
}
|
|
122189
|
+
<http_methods>
|
|
122190
|
+
Export named functions for each HTTP method. ALWAYS type with \`APIRoute\` from \`astro\`:
|
|
122191
|
+
|
|
122192
|
+
\`\`\`typescript
|
|
122193
|
+
import type { APIRoute } from "astro";
|
|
122171
122194
|
|
|
122172
|
-
|
|
122195
|
+
export const GET: APIRoute = async ({ request }) => {
|
|
122196
|
+
return new Response(JSON.stringify({ message: "Hello" }), {
|
|
122173
122197
|
status: 200,
|
|
122174
|
-
headers: {
|
|
122175
|
-
"Content-Type": "application/json",
|
|
122176
|
-
},
|
|
122198
|
+
headers: { "Content-Type": "application/json" },
|
|
122177
122199
|
});
|
|
122178
|
-
}
|
|
122200
|
+
};
|
|
122201
|
+
|
|
122202
|
+
export const POST: APIRoute = async ({ request }) => {
|
|
122203
|
+
const data = await request.json();
|
|
122204
|
+
return new Response(JSON.stringify(data), {
|
|
122205
|
+
status: 201,
|
|
122206
|
+
headers: { "Content-Type": "application/json" },
|
|
122207
|
+
});
|
|
122208
|
+
};
|
|
122179
122209
|
\`\`\`
|
|
122180
|
-
</
|
|
122181
|
-
|
|
122182
|
-
- Import \`APIRoute\` type from 'astro'
|
|
122183
|
-
- Export named functions for HTTP methods: \`GET\`, \`POST\`, \`PUT\`, \`DELETE\`, \`PATCH\`
|
|
122184
|
-
- Use async/await for handling asynchronous operations
|
|
122185
|
-
- Always return a \`Response\` object
|
|
122186
|
-
</typescript_patterns>
|
|
122210
|
+
</http_methods>
|
|
122211
|
+
|
|
122187
122212
|
<request_handling>
|
|
122188
|
-
|
|
122189
|
-
|
|
122190
|
-
|
|
122191
|
-
|
|
122192
|
-
|
|
122213
|
+
### Path Parameters
|
|
122214
|
+
\`\`\`typescript
|
|
122215
|
+
export const GET: APIRoute = async ({ params }) => {
|
|
122216
|
+
const { id } = params; // From /api/users/[id]
|
|
122217
|
+
|
|
122218
|
+
if (!id) {
|
|
122219
|
+
return new Response(JSON.stringify({ error: "ID required" }), {
|
|
122220
|
+
status: 400,
|
|
122221
|
+
statusText: "Bad Request",
|
|
122222
|
+
headers: { "Content-Type": "application/json" },
|
|
122223
|
+
});
|
|
122224
|
+
}
|
|
122225
|
+
|
|
122226
|
+
// Use id to fetch data
|
|
122227
|
+
};
|
|
122228
|
+
\`\`\`
|
|
122229
|
+
|
|
122230
|
+
### Query Parameters
|
|
122231
|
+
\`\`\`typescript
|
|
122232
|
+
export const GET: APIRoute = async ({ request }) => {
|
|
122233
|
+
const url = new URL(request.url);
|
|
122234
|
+
const search = url.searchParams.get("search");
|
|
122235
|
+
const limit = parseInt(url.searchParams.get("limit") || "10", 10);
|
|
122236
|
+
const offset = parseInt(url.searchParams.get("offset") || "0", 10);
|
|
122237
|
+
|
|
122238
|
+
// Use query parameters
|
|
122239
|
+
};
|
|
122240
|
+
\`\`\`
|
|
122241
|
+
|
|
122242
|
+
### Request Body (POST/PUT/PATCH)
|
|
122243
|
+
\`\`\`typescript
|
|
122244
|
+
export const POST: APIRoute = async ({ request }) => {
|
|
122245
|
+
try {
|
|
122246
|
+
const body = await request.json();
|
|
122247
|
+
const { title, content } = body;
|
|
122248
|
+
|
|
122249
|
+
if (!title || !content) {
|
|
122250
|
+
return new Response(
|
|
122251
|
+
JSON.stringify({ error: "Title and content required" }),
|
|
122252
|
+
{
|
|
122253
|
+
status: 400,
|
|
122254
|
+
statusText: "Bad Request",
|
|
122255
|
+
headers: { "Content-Type": "application/json" },
|
|
122256
|
+
}
|
|
122257
|
+
);
|
|
122258
|
+
}
|
|
122259
|
+
|
|
122260
|
+
// Process data
|
|
122261
|
+
} catch {
|
|
122262
|
+
return new Response(JSON.stringify({ error: "Invalid JSON" }), {
|
|
122263
|
+
status: 400,
|
|
122264
|
+
statusText: "Bad Request",
|
|
122265
|
+
headers: { "Content-Type": "application/json" },
|
|
122266
|
+
});
|
|
122267
|
+
}
|
|
122268
|
+
};
|
|
122269
|
+
\`\`\`
|
|
122270
|
+
|
|
122271
|
+
### Headers
|
|
122272
|
+
\`\`\`typescript
|
|
122273
|
+
const authHeader = request.headers.get("Authorization");
|
|
122274
|
+
const contentType = request.headers.get("Content-Type");
|
|
122275
|
+
\`\`\`
|
|
122193
122276
|
</request_handling>
|
|
122277
|
+
|
|
122194
122278
|
<response_patterns>
|
|
122195
|
-
|
|
122196
|
-
|
|
122197
|
-
|
|
122198
|
-
|
|
122279
|
+
Always return a \`Response\` object with proper status codes and headers:
|
|
122280
|
+
|
|
122281
|
+
\`\`\`typescript
|
|
122282
|
+
// 200 OK
|
|
122283
|
+
return new Response(JSON.stringify({ data: result }), {
|
|
122284
|
+
status: 200,
|
|
122285
|
+
headers: { "Content-Type": "application/json" },
|
|
122286
|
+
});
|
|
122287
|
+
|
|
122288
|
+
// 201 Created
|
|
122289
|
+
return new Response(JSON.stringify({ id: newId, ...data }), {
|
|
122290
|
+
status: 201,
|
|
122291
|
+
headers: { "Content-Type": "application/json" },
|
|
122292
|
+
});
|
|
122293
|
+
|
|
122294
|
+
// 204 No Content (for DELETE)
|
|
122295
|
+
return new Response(null, { status: 204 });
|
|
122296
|
+
|
|
122297
|
+
// 400 Bad Request
|
|
122298
|
+
return new Response(JSON.stringify({ error: "Invalid input" }), {
|
|
122299
|
+
status: 400,
|
|
122300
|
+
statusText: "Bad Request",
|
|
122301
|
+
headers: { "Content-Type": "application/json" },
|
|
122302
|
+
});
|
|
122303
|
+
|
|
122304
|
+
// 404 Not Found
|
|
122305
|
+
return new Response(JSON.stringify({ error: "Not found" }), {
|
|
122306
|
+
status: 404,
|
|
122307
|
+
statusText: "Not Found",
|
|
122308
|
+
headers: { "Content-Type": "application/json" },
|
|
122309
|
+
});
|
|
122310
|
+
|
|
122311
|
+
// 500 Internal Server Error
|
|
122312
|
+
return new Response(JSON.stringify({ error: "Internal server error" }), {
|
|
122313
|
+
status: 500,
|
|
122314
|
+
statusText: "Internal Server Error",
|
|
122315
|
+
headers: { "Content-Type": "application/json" },
|
|
122316
|
+
});
|
|
122317
|
+
\`\`\`
|
|
122199
122318
|
</response_patterns>
|
|
122200
|
-
|
|
122201
|
-
|
|
122202
|
-
-
|
|
122203
|
-
-
|
|
122204
|
-
-
|
|
122205
|
-
-
|
|
122206
|
-
|
|
122207
|
-
|
|
122208
|
-
-
|
|
122209
|
-
- Return appropriate HTTP status codes
|
|
122210
|
-
- Include proper headers
|
|
122319
|
+
|
|
122320
|
+
<code_quality_requirements>
|
|
122321
|
+
- Strict TypeScript: no \`any\`, explicit return types
|
|
122322
|
+
- ALWAYS type handlers with \`APIRoute\` from 'astro'
|
|
122323
|
+
- ALWAYS return \`Response\` objects with \`JSON.stringify()\` for JSON
|
|
122324
|
+
- ALWAYS include \`Content-Type: application/json\` header on JSON responses
|
|
122325
|
+
- ALWAYS include \`statusText\` in error responses (400, 404, 500)
|
|
122326
|
+
- ALWAYS handle errors with try/catch blocks
|
|
122327
|
+
- ALWAYS validate input parameters and request bodies
|
|
122211
122328
|
- Use async/await for asynchronous operations
|
|
122329
|
+
- No \`@ts-ignore\` comments
|
|
122212
122330
|
- Keep endpoints focused and single-purpose
|
|
122213
|
-
</
|
|
122331
|
+
</code_quality_requirements>`;
|
|
122214
122332
|
exports2.backendApiInstructions = {
|
|
122215
122333
|
role: backendApiRole,
|
|
122216
122334
|
implementationGuidelines: backendApiImplementationGuidelines,
|
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.243",
|
|
4
4
|
"description": "AI-powered Wix CLI app generator - standalone executable",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "node build.mjs",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"@wix/ditto-codegen": "1.0.0",
|
|
29
29
|
"esbuild": "^0.27.2"
|
|
30
30
|
},
|
|
31
|
-
"falconPackageHash": "
|
|
31
|
+
"falconPackageHash": "1dea80c5a030b0e80c612a5820bde206fe15e80c5411c5f6745979f7"
|
|
32
32
|
}
|