@wix/ditto-codegen-public 1.0.241 → 1.0.242
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
|
@@ -91124,6 +91124,21 @@ You will be given an API specification under the "API SPEC" spec.
|
|
|
91124
91124
|
The dashboard page code you generate can make API calls to these endpoints to read and write data.
|
|
91125
91125
|
You cannot write the API calls yourself, you must use the API calls provided in the API SPEC.
|
|
91126
91126
|
|
|
91127
|
+
<http_client_usage>
|
|
91128
|
+
IMPORTANT: Always use httpClient.fetchWithAuth() from @wix/essentials for API calls.
|
|
91129
|
+
This ensures proper authentication and authorization for all requests.
|
|
91130
|
+
|
|
91131
|
+
Import pattern:
|
|
91132
|
+
\`\`\`typescript
|
|
91133
|
+
import { httpClient } from '@wix/essentials';
|
|
91134
|
+
\`\`\`
|
|
91135
|
+
|
|
91136
|
+
Base URL construction:
|
|
91137
|
+
\`\`\`typescript
|
|
91138
|
+
const baseApiUrl = new URL(import.meta.url).origin;
|
|
91139
|
+
\`\`\`
|
|
91140
|
+
</http_client_usage>
|
|
91141
|
+
|
|
91127
91142
|
<example_api_spec>
|
|
91128
91143
|
${JSON.stringify({
|
|
91129
91144
|
name: "Todo Management API",
|
|
@@ -91217,16 +91232,20 @@ ${JSON.stringify({
|
|
|
91217
91232
|
</example_api_spec>
|
|
91218
91233
|
|
|
91219
91234
|
<example_output_code>
|
|
91235
|
+
import { httpClient } from '@wix/essentials';
|
|
91236
|
+
|
|
91237
|
+
const baseApiUrl = new URL(import.meta.url).origin;
|
|
91238
|
+
|
|
91220
91239
|
// Reading data - GET request
|
|
91221
91240
|
async function getTodos(): Promise<Todo[]> {
|
|
91222
|
-
const response = await
|
|
91241
|
+
const response = await httpClient.fetchWithAuth(\`\${baseApiUrl}/api/todos\`);
|
|
91223
91242
|
const data = await response.json();
|
|
91224
91243
|
return data;
|
|
91225
91244
|
}
|
|
91226
91245
|
|
|
91227
91246
|
// Writing data - POST request with data model entity
|
|
91228
91247
|
async function createTodo(todo: Omit<Todo, 'id' | 'createdAt'>): Promise<Todo> {
|
|
91229
|
-
const response = await
|
|
91248
|
+
const response = await httpClient.fetchWithAuth(\`\${baseApiUrl}/api/todos\`, {
|
|
91230
91249
|
method: 'POST',
|
|
91231
91250
|
headers: {
|
|
91232
91251
|
'Content-Type': 'application/json',
|
|
@@ -91239,7 +91258,7 @@ async function createTodo(todo: Omit<Todo, 'id' | 'createdAt'>): Promise<Todo> {
|
|
|
91239
91258
|
|
|
91240
91259
|
// Writing data - PUT request with data model entity
|
|
91241
91260
|
async function updateTodo(id: string, todo: Partial<Todo>): Promise<Todo> {
|
|
91242
|
-
const response = await
|
|
91261
|
+
const response = await httpClient.fetchWithAuth(\`\${baseApiUrl}/api/todos/\${id}\`, {
|
|
91243
91262
|
method: 'PUT',
|
|
91244
91263
|
headers: {
|
|
91245
91264
|
'Content-Type': 'application/json',
|
|
@@ -122138,7 +122157,7 @@ var require_backend_api_instructions = __commonJS({
|
|
|
122138
122157
|
"use strict";
|
|
122139
122158
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
122140
122159
|
exports2.backendApiInstructions = void 0;
|
|
122141
|
-
var backendApiRole = `You are a specialized code-generation agent for creating Astro Server Endpoints (API Routes) for
|
|
122160
|
+
var backendApiRole = `You are a specialized code-generation agent for creating Astro Server Endpoints (API Routes) for Wix CLI applications.`;
|
|
122142
122161
|
var backendApiImplementationGuidelines = `Generate clean, well-structured Astro Server Endpoints based on the API Spec that follow these patterns and best practices.
|
|
122143
122162
|
Focus on creating maintainable, secure, and efficient API routes that integrate well with frontend applications.`;
|
|
122144
122163
|
var backendApiCoreKnowledge = `<astro_server_endpoints_overview>
|
|
@@ -122147,70 +122166,159 @@ Focus on creating maintainable, secure, and efficient API routes that integrate
|
|
|
122147
122166
|
- Each file exports named functions for HTTP methods (GET, POST, PUT, DELETE, etc.)
|
|
122148
122167
|
- Files use the \`.ts\` extension and are automatically converted to API endpoints
|
|
122149
122168
|
</astro_server_endpoints_overview>
|
|
122169
|
+
|
|
122150
122170
|
<file_structure_and_naming>
|
|
122151
122171
|
- API routes are created in \`src/pages/api/\` directory
|
|
122152
|
-
- File names become the endpoint path (e.g.,
|
|
122153
|
-
-
|
|
122154
|
-
-
|
|
122155
|
-
-
|
|
122172
|
+
- File names become the endpoint path (e.g., \`src/pages/api/users.ts\` \u2192 \`/api/users\`)
|
|
122173
|
+
- For dynamic routes with parameters, use square brackets in the filename:
|
|
122174
|
+
- \`src/pages/api/users/[id].ts\` \u2192 \`/api/users/:id\`
|
|
122175
|
+
- \`src/pages/api/posts/[slug].ts\` \u2192 \`/api/posts/:slug\`
|
|
122176
|
+
- \`src/pages/api/users/[userId]/posts/[postId].ts\` \u2192 \`/api/users/:userId/posts/:postId\`
|
|
122177
|
+
</file_structure_and_naming>
|
|
122156
122178
|
|
|
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
|
-
}
|
|
122179
|
+
<http_methods>
|
|
122180
|
+
Export named functions for each HTTP method. ALWAYS type with \`APIRoute\` from \`astro\`:
|
|
122181
|
+
|
|
122182
|
+
\`\`\`typescript
|
|
122183
|
+
import type { APIRoute } from "astro";
|
|
122171
122184
|
|
|
122172
|
-
|
|
122185
|
+
export const GET: APIRoute = async ({ request }) => {
|
|
122186
|
+
return new Response(JSON.stringify({ message: "Hello" }), {
|
|
122173
122187
|
status: 200,
|
|
122174
|
-
headers: {
|
|
122175
|
-
"Content-Type": "application/json",
|
|
122176
|
-
},
|
|
122188
|
+
headers: { "Content-Type": "application/json" },
|
|
122177
122189
|
});
|
|
122178
|
-
}
|
|
122190
|
+
};
|
|
122191
|
+
|
|
122192
|
+
export const POST: APIRoute = async ({ request }) => {
|
|
122193
|
+
const data = await request.json();
|
|
122194
|
+
return new Response(JSON.stringify(data), {
|
|
122195
|
+
status: 201,
|
|
122196
|
+
headers: { "Content-Type": "application/json" },
|
|
122197
|
+
});
|
|
122198
|
+
};
|
|
122179
122199
|
\`\`\`
|
|
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>
|
|
122200
|
+
</http_methods>
|
|
122201
|
+
|
|
122187
122202
|
<request_handling>
|
|
122188
|
-
|
|
122189
|
-
|
|
122190
|
-
|
|
122191
|
-
|
|
122192
|
-
|
|
122203
|
+
### Path Parameters
|
|
122204
|
+
\`\`\`typescript
|
|
122205
|
+
export const GET: APIRoute = async ({ params }) => {
|
|
122206
|
+
const { id } = params; // From /api/users/[id]
|
|
122207
|
+
|
|
122208
|
+
if (!id) {
|
|
122209
|
+
return new Response(JSON.stringify({ error: "ID required" }), {
|
|
122210
|
+
status: 400,
|
|
122211
|
+
statusText: "Bad Request",
|
|
122212
|
+
headers: { "Content-Type": "application/json" },
|
|
122213
|
+
});
|
|
122214
|
+
}
|
|
122215
|
+
|
|
122216
|
+
// Use id to fetch data
|
|
122217
|
+
};
|
|
122218
|
+
\`\`\`
|
|
122219
|
+
|
|
122220
|
+
### Query Parameters
|
|
122221
|
+
\`\`\`typescript
|
|
122222
|
+
export const GET: APIRoute = async ({ request }) => {
|
|
122223
|
+
const url = new URL(request.url);
|
|
122224
|
+
const search = url.searchParams.get("search");
|
|
122225
|
+
const limit = parseInt(url.searchParams.get("limit") || "10", 10);
|
|
122226
|
+
const offset = parseInt(url.searchParams.get("offset") || "0", 10);
|
|
122227
|
+
|
|
122228
|
+
// Use query parameters
|
|
122229
|
+
};
|
|
122230
|
+
\`\`\`
|
|
122231
|
+
|
|
122232
|
+
### Request Body (POST/PUT/PATCH)
|
|
122233
|
+
\`\`\`typescript
|
|
122234
|
+
export const POST: APIRoute = async ({ request }) => {
|
|
122235
|
+
try {
|
|
122236
|
+
const body = await request.json();
|
|
122237
|
+
const { title, content } = body;
|
|
122238
|
+
|
|
122239
|
+
if (!title || !content) {
|
|
122240
|
+
return new Response(
|
|
122241
|
+
JSON.stringify({ error: "Title and content required" }),
|
|
122242
|
+
{
|
|
122243
|
+
status: 400,
|
|
122244
|
+
statusText: "Bad Request",
|
|
122245
|
+
headers: { "Content-Type": "application/json" },
|
|
122246
|
+
}
|
|
122247
|
+
);
|
|
122248
|
+
}
|
|
122249
|
+
|
|
122250
|
+
// Process data
|
|
122251
|
+
} catch {
|
|
122252
|
+
return new Response(JSON.stringify({ error: "Invalid JSON" }), {
|
|
122253
|
+
status: 400,
|
|
122254
|
+
statusText: "Bad Request",
|
|
122255
|
+
headers: { "Content-Type": "application/json" },
|
|
122256
|
+
});
|
|
122257
|
+
}
|
|
122258
|
+
};
|
|
122259
|
+
\`\`\`
|
|
122260
|
+
|
|
122261
|
+
### Headers
|
|
122262
|
+
\`\`\`typescript
|
|
122263
|
+
const authHeader = request.headers.get("Authorization");
|
|
122264
|
+
const contentType = request.headers.get("Content-Type");
|
|
122265
|
+
\`\`\`
|
|
122193
122266
|
</request_handling>
|
|
122267
|
+
|
|
122194
122268
|
<response_patterns>
|
|
122195
|
-
|
|
122196
|
-
|
|
122197
|
-
|
|
122198
|
-
|
|
122269
|
+
Always return a \`Response\` object with proper status codes and headers:
|
|
122270
|
+
|
|
122271
|
+
\`\`\`typescript
|
|
122272
|
+
// 200 OK
|
|
122273
|
+
return new Response(JSON.stringify({ data: result }), {
|
|
122274
|
+
status: 200,
|
|
122275
|
+
headers: { "Content-Type": "application/json" },
|
|
122276
|
+
});
|
|
122277
|
+
|
|
122278
|
+
// 201 Created
|
|
122279
|
+
return new Response(JSON.stringify({ id: newId, ...data }), {
|
|
122280
|
+
status: 201,
|
|
122281
|
+
headers: { "Content-Type": "application/json" },
|
|
122282
|
+
});
|
|
122283
|
+
|
|
122284
|
+
// 204 No Content (for DELETE)
|
|
122285
|
+
return new Response(null, { status: 204 });
|
|
122286
|
+
|
|
122287
|
+
// 400 Bad Request
|
|
122288
|
+
return new Response(JSON.stringify({ error: "Invalid input" }), {
|
|
122289
|
+
status: 400,
|
|
122290
|
+
statusText: "Bad Request",
|
|
122291
|
+
headers: { "Content-Type": "application/json" },
|
|
122292
|
+
});
|
|
122293
|
+
|
|
122294
|
+
// 404 Not Found
|
|
122295
|
+
return new Response(JSON.stringify({ error: "Not found" }), {
|
|
122296
|
+
status: 404,
|
|
122297
|
+
statusText: "Not Found",
|
|
122298
|
+
headers: { "Content-Type": "application/json" },
|
|
122299
|
+
});
|
|
122300
|
+
|
|
122301
|
+
// 500 Internal Server Error
|
|
122302
|
+
return new Response(JSON.stringify({ error: "Internal server error" }), {
|
|
122303
|
+
status: 500,
|
|
122304
|
+
statusText: "Internal Server Error",
|
|
122305
|
+
headers: { "Content-Type": "application/json" },
|
|
122306
|
+
});
|
|
122307
|
+
\`\`\`
|
|
122199
122308
|
</response_patterns>
|
|
122200
|
-
|
|
122201
|
-
|
|
122202
|
-
-
|
|
122203
|
-
-
|
|
122204
|
-
-
|
|
122205
|
-
-
|
|
122206
|
-
|
|
122207
|
-
|
|
122208
|
-
-
|
|
122209
|
-
- Return appropriate HTTP status codes
|
|
122210
|
-
- Include proper headers
|
|
122309
|
+
|
|
122310
|
+
<code_quality_requirements>
|
|
122311
|
+
- Strict TypeScript: no \`any\`, explicit return types
|
|
122312
|
+
- ALWAYS type handlers with \`APIRoute\` from 'astro'
|
|
122313
|
+
- ALWAYS return \`Response\` objects with \`JSON.stringify()\` for JSON
|
|
122314
|
+
- ALWAYS include \`Content-Type: application/json\` header on JSON responses
|
|
122315
|
+
- ALWAYS include \`statusText\` in error responses (400, 404, 500)
|
|
122316
|
+
- ALWAYS handle errors with try/catch blocks
|
|
122317
|
+
- ALWAYS validate input parameters and request bodies
|
|
122211
122318
|
- Use async/await for asynchronous operations
|
|
122319
|
+
- No \`@ts-ignore\` comments
|
|
122212
122320
|
- Keep endpoints focused and single-purpose
|
|
122213
|
-
</
|
|
122321
|
+
</code_quality_requirements>`;
|
|
122214
122322
|
exports2.backendApiInstructions = {
|
|
122215
122323
|
role: backendApiRole,
|
|
122216
122324
|
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.242",
|
|
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": "90cb464e6901cf2953e1124fe897dd26936f1de6b224508edb726c64"
|
|
32
32
|
}
|