webcake-storefront-mcp 1.31.1 → 1.31.2
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/changelog.json +7 -7
- package/dist/guides.js +35 -4
- package/package.json +1 -1
package/dist/changelog.json
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"v": "1.31.2",
|
|
4
|
+
"d": "26/06/2026",
|
|
5
|
+
"type": "Changed",
|
|
6
|
+
"en": "The HTTP_FUNCTION_GUIDE embedded in get_http_function and get_site_custom_code now includes a \"Common patterns\" section with battle-tested…",
|
|
7
|
+
"vi": "HTTP_FUNCTION_GUIDE được nhúng trong get_http_function và get_site_custom_code nay bổ sung phần \"Common patterns\" với các recipe đã được kiểm chứng…"
|
|
8
|
+
},
|
|
2
9
|
{
|
|
3
10
|
"v": "1.31.1",
|
|
4
11
|
"d": "26/06/2026",
|
|
@@ -33,12 +40,5 @@
|
|
|
33
40
|
"type": "Added",
|
|
34
41
|
"en": "New scaffold_popup tool builds and saves a designed newsletter/promo popup (heading + subtext + email subscribe form + close button, centred modal)…",
|
|
35
42
|
"vi": "Tool mới scaffold_popup xây dựng và lưu một popup newsletter/promo được thiết kế sẵn (tiêu đề + phụ đề + form đăng ký email + nút đóng, dạng modal…"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
"v": "1.27.0",
|
|
39
|
-
"d": "26/06/2026",
|
|
40
|
-
"type": "Added",
|
|
41
|
-
"en": "build_page now accepts an seo object (title, description, keyword, favicon, thumbnail) that is written to page.settings.seo with Open Graph…",
|
|
42
|
-
"vi": "build_page nay nhận thêm đối tượng seo (title, description, keyword, favicon, thumbnail) và ghi vào page.settings.seo kèm mirroring Open Graph; hỗ…"
|
|
43
43
|
}
|
|
44
44
|
]
|
package/dist/guides.js
CHANGED
|
@@ -76,7 +76,33 @@ const count = await Members.countDocuments({ playspace: psId, status: { $in: [0,
|
|
|
76
76
|
const created = await Members.create({ thanh_vien: userId, playspace: psId, status: 0 });
|
|
77
77
|
await Members.updateOne({ id: created.id }, { tien_con_lai: 100000 });
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
### Common patterns (battle-tested in production functions)
|
|
80
|
+
- FIND-OR-CREATE (ensure a row exists):
|
|
81
|
+
let row = await M.findOne({ key: v });
|
|
82
|
+
if (!row) row = await M.create({ key: v, ...defaults });
|
|
83
|
+
return row;
|
|
84
|
+
- UPSERT + read back the new version:
|
|
85
|
+
const updated = await M.findOneAndUpdate({ key: v }, { field: x }, { new: true });
|
|
86
|
+
- COUNT then DENORMALIZE onto a parent (cheap reads later):
|
|
87
|
+
const n = await Members.countDocuments({ playspace: psId, status: { $in: [0,1,2] } });
|
|
88
|
+
await PlaySpace.updateOne({ id: psId }, { so_thanh_vien: n });
|
|
89
|
+
- MULTI-TABLE write (no transactions — do the steps in order, validate first):
|
|
90
|
+
for (const it of items) await Members.updateOne({ id: it.id }, { tien_con_lai: it.bal });
|
|
91
|
+
await PlaySpace.updateOne({ id: psId }, { tien_con_lai: total });
|
|
92
|
+
await History.create({ playspace: psId, items }); // append an audit/history row
|
|
93
|
+
- SOFT DELETE (keep history) — set a status instead of deleteMany:
|
|
94
|
+
await M.updateOne({ id }, { status: INACTIVE }); // and filter it out with { status: { $ne: INACTIVE } }
|
|
95
|
+
- REFERENCE id helpers (a ref field is an id string, or an object after populate):
|
|
96
|
+
const toId = (v) => (v && typeof v === "object" ? String(v.id || "") : String(v || ""));
|
|
97
|
+
const toNumber = (v, d = 0) => (Number.isFinite(Number(v)) ? Number(v) : d);
|
|
98
|
+
- STATUS as numeric enums (define constants up top): const STATUS = { OWNER:0, ACTIVE:1, GUEST:2, INACTIVE:3 };
|
|
99
|
+
then query with { status: { $in: [STATUS.OWNER, STATUS.ACTIVE] } }.
|
|
100
|
+
- ALWAYS guard auth + wrap in try/catch returning a coded mess:
|
|
101
|
+
const userId = request.customer?.id ?? ""; if (!userId) return { mess: "NO_ACCOUNT_CALL" };
|
|
102
|
+
try { /* … */ return { mess: "OK", ...data }; } catch (err) { console.error(err?.message || err); return { mess: "SYSTEM_ERROR" }; }
|
|
103
|
+
|
|
104
|
+
## Built-in @webcake/* modules (first arg is always request; they auth via global.token — these run
|
|
105
|
+
## INSIDE the function sandbox, so they reach the /cms_function endpoints the dashboard JWT can't)
|
|
80
106
|
Thin wrappers over the backend's /cms_function/{site_id}/... endpoints. Pass request so
|
|
81
107
|
they pick up site_id. Below is EXACTLY what each call sends to the backend + what it returns.
|
|
82
108
|
|
|
@@ -96,15 +122,20 @@ they pick up site_id. Below is EXACTLY what each call sends to the backend + wha
|
|
|
96
122
|
updateArticleById(request, id, data) PATCH .../blog/article/{id} (same fields) → response
|
|
97
123
|
deleteArticleById(request, id) DELETE .../blog/article/{id} → response
|
|
98
124
|
|
|
99
|
-
- '@webcake/customer' (backend: /cms_function/{site}/customer/…) → customer object ({} if none)
|
|
100
|
-
|
|
125
|
+
- '@webcake/customer' (backend: /cms_function/{site}/customer/…) → customer object ({} if none).
|
|
126
|
+
The object has at least { id, name, avatar, email, phone_number }. ALWAYS check \`customer?.id\`
|
|
127
|
+
before using it (returns {} when not found). Confirmed against a real production function.
|
|
128
|
+
findCustomerById(request, id) GET .../customer/identity/{id}
|
|
101
129
|
findCustomerByPhone(request, phone) GET .../customer/phone/{phone}
|
|
102
130
|
findCustomerByEmail(request, email) GET .../customer/email/{email}
|
|
131
|
+
Typical lookup-by-anything helper: try a code/sku table first, else normalize the phone and
|
|
132
|
+
call findCustomerByPhone, else (has "@") findCustomerByEmail, else findCustomerById.
|
|
103
133
|
|
|
104
|
-
- '@webcake/promotion' (backend: /cms_function/{site}/promotion/add_bonus)
|
|
134
|
+
- '@webcake/promotion' (backend: /cms_function/{site}/promotion/add_bonus) — confirmed in real code
|
|
105
135
|
addBonus(request, data) POST add_bonus → response.
|
|
106
136
|
It ADDS REWARD POINTS to a customer. data: { customer_id (required),
|
|
107
137
|
point (number, required), message? (defaults "Bạn được cộng điểm") }.
|
|
138
|
+
e.g. await addBonus(request, { customer_id: "abc", point: 10, message: "Cộng 10 điểm" }).
|
|
108
139
|
|
|
109
140
|
- '@webcake/token' (backend: /external/oauth/token)
|
|
110
141
|
getAccessToken(request) → access_token string (throws if none).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webcake-storefront-mcp",
|
|
3
|
-
"version": "1.31.
|
|
3
|
+
"version": "1.31.2",
|
|
4
4
|
"description": "MCP server for the WebCake/StoreCake storefront builder — page CRUD, page authoring, products, orders, and more",
|
|
5
5
|
"mcpName": "io.github.vuluu2k/webcake-storefront-mcp",
|
|
6
6
|
"license": "MIT",
|