webcake-storefront-mcp 1.34.0 → 1.35.0
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/README.md +1 -0
- package/README.vi.md +1 -0
- package/dist/api.js +16 -1
- package/dist/builder/page.js +25 -6
- package/dist/changelog.json +14 -14
- package/dist/tools/apps.js +2 -2
- package/dist/tools/context.js +16 -5
- package/dist/tools/registry.js +3 -1
- package/dist/tools/site-plans.js +183 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -181,6 +181,7 @@ in chat via `update_auth` and `switch_site` — saved to a local config file at
|
|
|
181
181
|
| **Content & store** | blog articles · themes / site style · apps · customers · `send_mail` | token + session |
|
|
182
182
|
| **Backend code** | HTTP-function CRUD (`get_http_function`, `edit_http_function`, `run_function`, `debug_function`…) | token + session |
|
|
183
183
|
| **Context** | `get_current_context` · `list_my_sites` · `switch_site` · `update_auth` · `toggle_confirm_mode` | token |
|
|
184
|
+
| **Site plans** | `get_site_subscription` (current plan, status, days left) · `count_my_sites` (by plan / custom domain / trash) · `list_plans` | token |
|
|
184
185
|
|
|
185
186
|
Every write **defaults to `dry_run=true`** — it previews the exact change and only touches your site when you re-run with `dry_run=false`.
|
|
186
187
|
|
package/README.vi.md
CHANGED
|
@@ -180,6 +180,7 @@ trong chat bằng `update_auth` và `switch_site` — lưu vào file cấu hình
|
|
|
180
180
|
| **Nội dung & store** | bài blog · theme / site style · app · khách hàng · `send_mail` | token + session |
|
|
181
181
|
| **Code backend** | CRUD HTTP-function (`get_http_function`, `edit_http_function`, `run_function`, `debug_function`…) | token + session |
|
|
182
182
|
| **Ngữ cảnh** | `get_current_context` · `list_my_sites` · `switch_site` · `update_auth` · `toggle_confirm_mode` | token |
|
|
183
|
+
| **Gói cước site** | `get_site_subscription` (gói hiện tại, trạng thái, số ngày còn lại) · `count_my_sites` (theo gói / tên miền riêng / thùng rác) · `list_plans` | token |
|
|
183
184
|
|
|
184
185
|
Mọi thao tác ghi **mặc định `dry_run=true`** — xem trước thay đổi, chỉ đụng site khi bạn chạy lại với `dry_run=false`.
|
|
185
186
|
|
package/dist/api.js
CHANGED
|
@@ -72,9 +72,21 @@ export class WebcakeCmsApi {
|
|
|
72
72
|
getMe() {
|
|
73
73
|
return this.request("GET", `/api/v1/@me`);
|
|
74
74
|
}
|
|
75
|
+
/** Personal sites only (persona_or_team==0). `filter` must be "all" (status 1) or "removed"
|
|
76
|
+
* (trash, status 0) — any other value makes the backend 500. */
|
|
75
77
|
listMySites(query) {
|
|
76
78
|
return this.request("GET", `/api/v1/dashboard/site/all`, { query });
|
|
77
79
|
}
|
|
80
|
+
/** Plan purchase history of one site, `{ subscriptions: { data[], total_entries } }`.
|
|
81
|
+
* The path's misspelling is the real route. Rows carry payment secrets — whitelist before
|
|
82
|
+
* returning. 404 for a site in trash (SitePlug requires status 1). */
|
|
83
|
+
getSiteSubscriptions(siteId = this.siteId, query = { page: 1, limit: 100 }) {
|
|
84
|
+
return this.request("GET", `/api/v1/site/${siteId}/get_subsctription_package_by_site_id`, { query });
|
|
85
|
+
}
|
|
86
|
+
/** Plan catalog `{ packages: { data[] } }` (names are free text, no enum). */
|
|
87
|
+
listPackages(query = { page: 1, limit: 100 }) {
|
|
88
|
+
return this.request("GET", `/api/v1/site/${this.siteId}/get_packages`, { query });
|
|
89
|
+
}
|
|
78
90
|
/** Create a brand-new personal site. The backend seeds sample categories/products/blog
|
|
79
91
|
* but NO pages. Returns { data: { site: { id, site_slug:{slug}, ... } } }.
|
|
80
92
|
* Fails with 403 when the account's site quota is reached (free plan: 4 sites). */
|
|
@@ -122,7 +134,10 @@ export class WebcakeCmsApi {
|
|
|
122
134
|
const settings = typeof site?.settings === "string" ? JSON.parse(site.settings || "{}") : site?.settings;
|
|
123
135
|
return settings?.breakpoints || null;
|
|
124
136
|
})
|
|
125
|
-
.catch(() =>
|
|
137
|
+
.catch(() => {
|
|
138
|
+
this._siteBps = null; // don't cache a failed lookup — retry on the next save
|
|
139
|
+
return null;
|
|
140
|
+
});
|
|
126
141
|
return this._siteBps;
|
|
127
142
|
}
|
|
128
143
|
/** Update auth token (in-memory) */
|
package/dist/builder/page.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// their children in a CSS grid driven by runtime.config (grid / columns / rows) and each
|
|
5
5
|
// child's runtime.config (columnStart/End, rowStart/End, constraintX/Y). The helpers here
|
|
6
6
|
// produce that structure the same way the builder does, so generated pages render.
|
|
7
|
-
import { buildElement, isKnownType, ELEMENT_TYPES
|
|
7
|
+
import { buildElement, isKnownType, ELEMENT_TYPES } from "./catalog.js";
|
|
8
8
|
import { randomString } from "./factory.js";
|
|
9
9
|
import { validateEvents } from "./events.js";
|
|
10
10
|
import { validateBindings } from "./bindings.js";
|
|
@@ -350,6 +350,8 @@ export function validatePage(source) {
|
|
|
350
350
|
}
|
|
351
351
|
});
|
|
352
352
|
// Third pass (needs ancestry): structures the renderer silently mishandles. Warnings only.
|
|
353
|
+
// Child check uses LEAF_TYPES, not "factory has no children": swiper, grid-product, post-list,
|
|
354
|
+
// member-bar… render children even though their factories create none.
|
|
353
355
|
const checkTree = (node, ancestors) => {
|
|
354
356
|
if (!node || typeof node !== "object")
|
|
355
357
|
return;
|
|
@@ -357,7 +359,7 @@ export function validatePage(source) {
|
|
|
357
359
|
const kids = Array.isArray(node.children) ? node.children : [];
|
|
358
360
|
if (!ancestors.length && type && type !== "section" && type !== "popup")
|
|
359
361
|
warnings.push(`Top-level node "${node.id}" is a ${type}: pages render only sections at the top level — wrap it in a section.`);
|
|
360
|
-
if (kids.length &&
|
|
362
|
+
if (kids.length && LEAF_TYPES.has(type))
|
|
361
363
|
warnings.push(`"${node.id}" (${type}) has ${kids.length} child node(s), but ${type} is not a container — they won't render.`);
|
|
362
364
|
if (type === "submit-button" && !ancestors.some((t) => /form/.test(t)))
|
|
363
365
|
warnings.push(`Submit button "${node.id}" is not inside a form — it has nothing to submit.`);
|
|
@@ -375,6 +377,19 @@ export function validatePage(source) {
|
|
|
375
377
|
stats: { sections: source.sections.length, total_elements: total, element_types: typeCounts },
|
|
376
378
|
};
|
|
377
379
|
}
|
|
380
|
+
/**
|
|
381
|
+
* Expand one node's `runtime.{style,config}` into the per-breakpoint keys the storefront
|
|
382
|
+
* renderer reads (bp1..bp4). Mirrors builderx_spa's syncBreakpoint: the authored
|
|
383
|
+
* (desktop) values are copied onto every breakpoint. Sections additionally get their
|
|
384
|
+
* centred 3-column grid recomputed per breakpoint via genGridByBp (the side-margin
|
|
385
|
+
* widths shrink on smaller screens). Nodes already in breakpoint shape are left as-is,
|
|
386
|
+
* so this is safe to run over a mixed source (e.g. add_section onto an existing page).
|
|
387
|
+
*/
|
|
388
|
+
/** Renderer builders that never draw children (builderx_api lib/qwik/html) — deliberately short. */
|
|
389
|
+
const LEAF_TYPES = new Set([
|
|
390
|
+
"text", "image", "button", "line", "video", "input", "email", "password", "text-area", "select",
|
|
391
|
+
"text-dataset", "image-dataset", "submit-button",
|
|
392
|
+
]);
|
|
378
393
|
/** The site's breakpoints if they're a usable map that differs from the standard four, else null. */
|
|
379
394
|
function customBreakpoints(site) {
|
|
380
395
|
if (!site || typeof site !== "object")
|
|
@@ -393,15 +408,19 @@ function customBreakpoints(site) {
|
|
|
393
408
|
* breakpoint containing its min width; sections regenerate their grid for that width. */
|
|
394
409
|
function remapToSiteBreakpoints(node, site) {
|
|
395
410
|
const std = Object.entries(BREAKPOINTS);
|
|
396
|
-
const pick = (minW) => (std.find(([, [lo, hi]]) => minW >= lo && minW <= hi) || std[std.length - 1])[0];
|
|
397
411
|
const out = {};
|
|
398
|
-
for (const [key, [minW]] of Object.entries(site)) {
|
|
399
|
-
|
|
412
|
+
for (const [key, [minW, maxW]] of Object.entries(site)) {
|
|
413
|
+
// The open-ended (widest) breakpoint is the desktop view: a site cut down to one breakpoint
|
|
414
|
+
// ({bp1:[320,1e9]}) must not get the phone layout everywhere.
|
|
415
|
+
const openEnded = maxW >= BREAKPOINTS.bp1[1];
|
|
416
|
+
const src = openEnded ? "bp1" : (std.find(([, [lo, hi]]) => minW >= lo && minW <= hi) || std[std.length - 1])[0];
|
|
417
|
+
const from = node[src];
|
|
400
418
|
if (!from)
|
|
401
419
|
continue;
|
|
402
420
|
out[key] = clone(from);
|
|
421
|
+
const gridWidth = openEnded ? Math.max(minW, BREAKPOINTS.bp1[0]) : minW;
|
|
403
422
|
if (node.type === "section")
|
|
404
|
-
out[key].config.columns = clone(genGridByBp(
|
|
423
|
+
out[key].config.columns = clone(genGridByBp(gridWidth).columns);
|
|
405
424
|
}
|
|
406
425
|
for (const k of BREAKPOINT_KEYS)
|
|
407
426
|
delete node[k];
|
package/dist/changelog.json
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"v": "1.35.0",
|
|
4
|
+
"d": "22/10/2026",
|
|
5
|
+
"type": "Added",
|
|
6
|
+
"en": "New get_site_subscription tool reads a site's plan (current/default site): plan_name, status (active | expired | pending_payment | none),…",
|
|
7
|
+
"vi": "Tool mới get_site_subscription đọc gói cước của site (mặc định site hiện tại): plan_name, status (active | expired | pending_payment | none),…"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"v": "1.34.1",
|
|
11
|
+
"d": "14/10/2026",
|
|
12
|
+
"type": "Fixed",
|
|
13
|
+
"en": "validate_page's \"not a container\" warning now only fires for true leaf elements (text, image, button, inputs, datasets, etc.); container-like…",
|
|
14
|
+
"vi": "Cảnh báo \"not a container\" của validate_page nay chỉ xuất hiện với các element leaf thật sự (text, image, button, các input, dataset...); các…"
|
|
15
|
+
},
|
|
2
16
|
{
|
|
3
17
|
"v": "1.34.0",
|
|
4
18
|
"d": "14/10/2026",
|
|
@@ -26,19 +40,5 @@
|
|
|
26
40
|
"type": "Added",
|
|
27
41
|
"en": "Every tool, whether registered natively or reached through the search gateway (search_tools/invoke_tool/list_tool_groups), now reports readOnlyHint…",
|
|
28
42
|
"vi": "Mọi tool, dù được đăng ký native hay được tiếp cận qua search gateway (search_tools/invoke_tool/list_tool_groups), nay đều có thêm annotation…"
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
"v": "1.32.0",
|
|
32
|
-
"d": "14/10/2026",
|
|
33
|
-
"type": "Changed",
|
|
34
|
-
"en": "The server now serves a raster PNG icon (/favicon.ico, /favicon.png, /icon.png, /apple-touch-icon.png) alongside the existing SVG favicon, and…",
|
|
35
|
-
"vi": "Server nay phục vụ thêm icon dạng raster PNG (/favicon.ico, /favicon.png, /icon.png, /apple-touch-icon.png) bên cạnh favicon SVG hiện có, và khai…"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
"v": "1.31.13",
|
|
39
|
-
"d": "09/10/2026",
|
|
40
|
-
"type": "Added",
|
|
41
|
-
"en": "create_product, update_product, create_product_category, update_product_category, and create_blog_category accept a new seo object to write…",
|
|
42
|
-
"vi": "create_product, update_product, create_product_category, update_product_category và create_blog_category nay nhận thêm đối tượng seo để ghi…"
|
|
43
43
|
}
|
|
44
44
|
]
|
package/dist/tools/apps.js
CHANGED
|
@@ -4,13 +4,13 @@ export function registerAppTools(server, api, handle) {
|
|
|
4
4
|
server.tool("list_apps", `List the site's installed applications (type, status, settings).
|
|
5
5
|
App type codes: ${APP_TYPE_REFERENCE}.`, {}, () => handle(async () => {
|
|
6
6
|
const res = await api.listApps();
|
|
7
|
-
const
|
|
8
|
-
const list = Array.isArray(raw) ? raw : raw?.data || [];
|
|
7
|
+
const list = res?.apps ?? res?.data?.apps ?? (Array.isArray(res?.data) ? res.data : []);
|
|
9
8
|
return {
|
|
10
9
|
apps: list.map((a) => ({
|
|
11
10
|
type: a.type,
|
|
12
11
|
type_name: APP_NAME_BY_TYPE[a.type] ?? undefined,
|
|
13
12
|
status: a.status,
|
|
13
|
+
is_active: a.is_active,
|
|
14
14
|
id: a.id,
|
|
15
15
|
})),
|
|
16
16
|
app_types: APP_TYPES,
|
package/dist/tools/context.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { getConfig, setConfig } from "../db.js";
|
|
3
3
|
import { resolvePreviewUrl } from "../config.js";
|
|
4
|
+
import { SITE_FILTERS, normalizeSiteFilter, hasCustomDomain } from "./site-plans.js";
|
|
4
5
|
/** Read all saved credentials from the local config file for startup */
|
|
5
6
|
export function getSavedConfig() {
|
|
6
7
|
return {
|
|
@@ -110,18 +111,27 @@ export function registerContextTools(server, api, handle) {
|
|
|
110
111
|
hint: "Use list_my_sites to see all sites, switch_site to change site. Use toggle_confirm_mode to switch between 'always_confirm' (safe) and 'auto_apply' (fast).",
|
|
111
112
|
};
|
|
112
113
|
}));
|
|
113
|
-
server.tool("list_my_sites",
|
|
114
|
+
server.tool("list_my_sites", `List the current account's PERSONAL sites (team sites are not included). Use this to find a site_id before switching.
|
|
115
|
+
filter: "all" = active sites (default), "removed" = sites in trash. Each site has status, published_at (set at
|
|
116
|
+
creation — not proof of publishing), slug, primary domain and has_custom_domain (verified, live, non-default domain).
|
|
117
|
+
For plans use get_site_subscription / count_my_sites.`, {
|
|
114
118
|
page: z.number().default(1).describe("Page number"),
|
|
115
119
|
limit: z.number().default(20).describe("Items per page"),
|
|
116
|
-
term: z.string().optional().describe("Search by site name"),
|
|
117
|
-
|
|
118
|
-
|
|
120
|
+
term: z.string().optional().describe("Search by site name, site id or domain"),
|
|
121
|
+
filter: z.enum(SITE_FILTERS).optional().describe('"all" (active, default) or "removed" (trash)'),
|
|
122
|
+
}, ({ page, limit, term, filter }) => handle(async () => {
|
|
123
|
+
const res = await api.listMySites({ page, limit, filter: normalizeSiteFilter(filter), ...(term && { term }) });
|
|
119
124
|
const raw = res?.data?.sites || res?.data || [];
|
|
120
125
|
const list = Array.isArray(raw) ? raw : [];
|
|
121
126
|
const sites = list.map((s) => ({
|
|
122
127
|
id: s.id,
|
|
123
128
|
name: s.name,
|
|
124
|
-
|
|
129
|
+
status: s.status,
|
|
130
|
+
slug: s.site_slug?.slug ?? null,
|
|
131
|
+
published_at: s.published_at ?? null,
|
|
132
|
+
domain: s.primary_domain?.domain ?? null,
|
|
133
|
+
custom_domain_verified: s.primary_domain?.is_verified ?? null,
|
|
134
|
+
has_custom_domain: hasCustomDomain(s),
|
|
125
135
|
is_current: s.id === api.siteId,
|
|
126
136
|
}));
|
|
127
137
|
return {
|
|
@@ -129,6 +139,7 @@ export function registerContextTools(server, api, handle) {
|
|
|
129
139
|
sites,
|
|
130
140
|
total: res?.data?.total_entries || sites.length,
|
|
131
141
|
page,
|
|
142
|
+
...(res?.data?.has_site_in_trash && { has_site_in_trash: true }),
|
|
132
143
|
};
|
|
133
144
|
}));
|
|
134
145
|
server.tool("create_site", `Create a brand-new storefront site for the current account, then (by default) switch to it
|
package/dist/tools/registry.js
CHANGED
|
@@ -32,6 +32,7 @@ import { registerImageTools } from "./images.js";
|
|
|
32
32
|
import { registerBuilderTools } from "./builder.js";
|
|
33
33
|
import { registerBuilderExtraTools } from "./builder-extras.js";
|
|
34
34
|
import { registerPageDraftTools } from "./page-draft.js";
|
|
35
|
+
import { registerSitePlanTools } from "./site-plans.js";
|
|
35
36
|
/** Tool groups. `core` groups load natively; the rest are reached via search_tools + invoke_tool. */
|
|
36
37
|
export const GROUPS = [
|
|
37
38
|
{ name: "session", title: "Session & apps", core: true, desc: "Connection context, site switch, app install/list, result cache" },
|
|
@@ -39,7 +40,7 @@ export const GROUPS = [
|
|
|
39
40
|
{ name: "store", title: "Store", core: true, desc: "Products, categories, collections, orders, promotions, combos" },
|
|
40
41
|
{ name: "content", title: "Content & customers", core: true, desc: "Blog articles, customers, CMS files / HTTP functions" },
|
|
41
42
|
{ name: "catalog", title: "Catalog extras", desc: "Brands, suppliers, product tags, ribbons, materials, variations, measurement, price-contact" },
|
|
42
|
-
{ name: "site_config", title: "Site configuration", desc: "Custom domains, SEO redirects, shipping, UTM links, fonts, site settings, API keys, publish history" },
|
|
43
|
+
{ name: "site_config", title: "Site configuration", desc: "Custom domains, SEO redirects, shipping, UTM links, fonts, site settings, API keys, publish history, site plans/subscriptions (gói cước), site counts" },
|
|
43
44
|
{ name: "marketing", title: "Marketing & CRM", desc: "Email templates, contacts, subscribers, customer tags, employees, invitations, insight, notifications" },
|
|
44
45
|
{ name: "i18n", title: "Multilingual", desc: "Enable languages and manage translations for products/categories/articles/etc." },
|
|
45
46
|
{ name: "media", title: "Media & PWA", desc: "Media library folders/content, capacity, base64 upload, PWA manifest" },
|
|
@@ -85,6 +86,7 @@ const MODULES = [
|
|
|
85
86
|
["web", registerBuilderTools],
|
|
86
87
|
["web", registerBuilderExtraTools],
|
|
87
88
|
["web", registerPageDraftTools],
|
|
89
|
+
["site_config", registerSitePlanTools],
|
|
88
90
|
];
|
|
89
91
|
/** Captures server.tool(...) calls into a registry instead of registering them. */
|
|
90
92
|
class ToolCollector {
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// Site plans (gói cước): read a site's subscription, count the account's sites by plan /
|
|
2
|
+
// custom domain / trash, list the plan catalog. All account-token endpoints (no super-admin).
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
const DAY = 86_400_000;
|
|
5
|
+
/** Storefront keeps serving on the default link this long after expiry (time_live_active_site). */
|
|
6
|
+
export const GRACE_DAYS = 15;
|
|
7
|
+
const DEFAULT_DOMAIN_SUFFIXES = ["webcake.me", "mywebcake.com", "storecake.net", "storecake.io"];
|
|
8
|
+
export const SITE_FILTERS = ["all", "removed"];
|
|
9
|
+
export const PLAN_NOTES = [
|
|
10
|
+
`After expiry the storefront keeps running on the default link for ${GRACE_DAYS} days.`,
|
|
11
|
+
"A custom domain is removed right after the plan expires.",
|
|
12
|
+
"A site with no plan on a default domain is blocked 10 minutes after published_at.",
|
|
13
|
+
];
|
|
14
|
+
/** Only "all" | "removed" are accepted — anything else makes the backend 500. */
|
|
15
|
+
export function normalizeSiteFilter(filter) {
|
|
16
|
+
const f = (filter ?? "all").trim().toLowerCase();
|
|
17
|
+
if (f === "all" || f === "removed")
|
|
18
|
+
return f;
|
|
19
|
+
throw new Error(`Invalid filter "${filter}": use "all" (active sites) or "removed" (trash).`);
|
|
20
|
+
}
|
|
21
|
+
export function isDefaultDomain(domain) {
|
|
22
|
+
const d = String(domain || "").trim().toLowerCase().replace(/\.$/, "");
|
|
23
|
+
return DEFAULT_DOMAIN_SUFFIXES.some((s) => d === s || d.endsWith(`.${s}`));
|
|
24
|
+
}
|
|
25
|
+
/** A site is "published on its own domain" when its primary domain is a verified, live, non-default domain. */
|
|
26
|
+
export function hasCustomDomain(site) {
|
|
27
|
+
const pd = site?.primary_domain;
|
|
28
|
+
return !!(pd?.domain && pd.is_verified && !pd.is_blocked && !pd.is_deleted && !isDefaultDomain(pd.domain));
|
|
29
|
+
}
|
|
30
|
+
/** Whitelist one subscription row — rows also carry stripe_client_secret, qr_data, virtual_account,
|
|
31
|
+
* infor_bill, phone_number, commissions and nested site/owner, none of which may leave this server. */
|
|
32
|
+
export function sanitizeSubscription(r) {
|
|
33
|
+
return {
|
|
34
|
+
plan_name: r?.package?.name ?? null,
|
|
35
|
+
package_id: r?.package_id ?? null,
|
|
36
|
+
duration: r?.duration ?? null,
|
|
37
|
+
payment_amount: r?.payment_amount ?? null,
|
|
38
|
+
currency: r?.currency ?? null,
|
|
39
|
+
is_paid: !!r?.is_paid,
|
|
40
|
+
is_activated: !!r?.is_activated,
|
|
41
|
+
activated_at: r?.activated_at ?? null,
|
|
42
|
+
expired_at: r?.expired_at ?? null,
|
|
43
|
+
upgrade_from: r?.upgrade_from ?? null,
|
|
44
|
+
inserted_at: r?.inserted_at ?? null,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const ts = (v) => (v ? Date.parse(v) || 0 : 0);
|
|
48
|
+
/** Current plan of a site from its (sanitized) subscription rows. Active = paid && activated && not expired. */
|
|
49
|
+
export function summarizePlan(rows, now = Date.now()) {
|
|
50
|
+
const byExpiry = (a, b) => ts(b.expired_at) - ts(a.expired_at);
|
|
51
|
+
const active = rows.filter((r) => r.is_paid && r.is_activated && ts(r.expired_at) > now).sort(byExpiry)[0];
|
|
52
|
+
const lastPaid = rows.filter((r) => r.is_paid && r.is_activated).sort(byExpiry)[0];
|
|
53
|
+
const latest = [...rows].sort((a, b) => ts(b.inserted_at) - ts(a.inserted_at))[0];
|
|
54
|
+
let status;
|
|
55
|
+
let row;
|
|
56
|
+
if (active)
|
|
57
|
+
[status, row] = ["active", active];
|
|
58
|
+
else if (latest && !(latest.is_paid && latest.is_activated))
|
|
59
|
+
[status, row] = ["pending_payment", latest];
|
|
60
|
+
else if (lastPaid)
|
|
61
|
+
[status, row] = ["expired", lastPaid];
|
|
62
|
+
else
|
|
63
|
+
[status, row] = ["none", null];
|
|
64
|
+
const exp = row ? ts(row.expired_at) : 0;
|
|
65
|
+
const out = {
|
|
66
|
+
plan_name: row?.plan_name ?? null,
|
|
67
|
+
status,
|
|
68
|
+
expired_at: row?.expired_at ?? null,
|
|
69
|
+
days_left: status === "active" && exp ? Math.ceil((exp - now) / DAY) : null,
|
|
70
|
+
};
|
|
71
|
+
if (status === "expired" && exp) {
|
|
72
|
+
out.grace_until = new Date(exp + GRACE_DAYS * DAY).toISOString();
|
|
73
|
+
out.in_grace = now < exp + GRACE_DAYS * DAY;
|
|
74
|
+
}
|
|
75
|
+
if (status === "pending_payment" && lastPaid)
|
|
76
|
+
out.last_expired_at = lastPaid.expired_at;
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
const unwrapSubs = (res) => {
|
|
80
|
+
const s = res?.subscriptions ?? res?.data?.subscriptions;
|
|
81
|
+
return Array.isArray(s?.data) ? s.data : [];
|
|
82
|
+
};
|
|
83
|
+
async function readSitePlan(api, siteId) {
|
|
84
|
+
try {
|
|
85
|
+
return unwrapSubs(await api.getSiteSubscriptions(siteId)).map(sanitizeSubscription);
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
89
|
+
if (msg.includes("API 404")) {
|
|
90
|
+
throw new Error(`Site ${siteId} not found or deleted (in trash). The plan of a deleted site cannot be read — restore it first.`);
|
|
91
|
+
}
|
|
92
|
+
throw e;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/** Run `fn` over items with at most `limit` in flight. */
|
|
96
|
+
async function pool(items, limit, fn) {
|
|
97
|
+
const out = new Array(items.length);
|
|
98
|
+
let i = 0;
|
|
99
|
+
const worker = async () => {
|
|
100
|
+
while (i < items.length) {
|
|
101
|
+
const k = i++;
|
|
102
|
+
out[k] = await fn(items[k]);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
const unwrapSites = (res) => {
|
|
109
|
+
const d = res?.data ?? res ?? {};
|
|
110
|
+
return { sites: Array.isArray(d.sites) ? d.sites : [], total: Number(d.total_entries) || 0 };
|
|
111
|
+
};
|
|
112
|
+
export function registerSitePlanTools(server, api, handle) {
|
|
113
|
+
server.tool("get_site_subscription", `Read a site's plan (gói cước): the current plan_name, status (active | expired | pending_payment | none),
|
|
114
|
+
expired_at and days_left, plus the purchase history (package name, duration, amount, paid/activated, dates).
|
|
115
|
+
Active = paid && activated && expired_at in the future. No row = the site has no plan (free).
|
|
116
|
+
${PLAN_NOTES.join(" ")}
|
|
117
|
+
A site in trash cannot be read (backend 404).`, { site_id: z.string().optional().describe("Site id (default: current site)") }, ({ site_id }) => handle(async () => {
|
|
118
|
+
const id = site_id || api.siteId;
|
|
119
|
+
const rows = await readSitePlan(api, id);
|
|
120
|
+
return { site_id: id, ...summarizePlan(rows), history: rows, notes: PLAN_NOTES };
|
|
121
|
+
}));
|
|
122
|
+
server.tool("count_my_sites", `Count the account's PERSONAL sites: active total, deleted (in trash), active by plan (paid && activated && not expired)
|
|
123
|
+
with a per-plan breakdown, no plan, expired, pending payment, and sites on a verified custom domain.
|
|
124
|
+
Plans are read per site (≤5 in parallel, up to max_sites); beyond that the result says checked/total.
|
|
125
|
+
Notes: "published" is approximated by having a verified, non-blocked custom domain — published_at is set when the
|
|
126
|
+
site is CREATED, so it does not prove the site was published. Team sites (persona_or_team) are NOT included.`, { max_sites: z.number().int().min(1).max(500).default(200).describe("Max sites whose plan is read (default 200)") }, ({ max_sites }) => handle(async () => {
|
|
127
|
+
const all = [];
|
|
128
|
+
let total = 0;
|
|
129
|
+
for (let page = 1; page <= 100; page++) {
|
|
130
|
+
const r = unwrapSites(await api.listMySites({ page, limit: 100, filter: "all" }));
|
|
131
|
+
total = r.total;
|
|
132
|
+
all.push(...r.sites);
|
|
133
|
+
if (!r.sites.length || all.length >= total)
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
const removed = unwrapSites(await api.listMySites({ page: 1, limit: 1, filter: "removed" })).total;
|
|
137
|
+
const checked = all.slice(0, max_sites);
|
|
138
|
+
const now = Date.now();
|
|
139
|
+
const plans = await pool(checked, 5, (s) => readSitePlan(api, s.id).then((rows) => summarizePlan(rows, now), () => null));
|
|
140
|
+
const by_plan_name = {};
|
|
141
|
+
const count = { active: 0, expired: 0, pending_payment: 0, none: 0 };
|
|
142
|
+
let errors = 0;
|
|
143
|
+
for (const p of plans) {
|
|
144
|
+
if (!p) {
|
|
145
|
+
errors++;
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
count[p.status]++;
|
|
149
|
+
if (p.status === "active")
|
|
150
|
+
by_plan_name[p.plan_name || "(unnamed)"] = (by_plan_name[p.plan_name || "(unnamed)"] || 0) + 1;
|
|
151
|
+
}
|
|
152
|
+
return {
|
|
153
|
+
total_active_sites: total || all.length,
|
|
154
|
+
deleted_sites: removed,
|
|
155
|
+
active_by_plan: count.active,
|
|
156
|
+
by_plan_name,
|
|
157
|
+
no_plan: count.none,
|
|
158
|
+
expired: count.expired,
|
|
159
|
+
pending_payment: count.pending_payment,
|
|
160
|
+
custom_domain_sites: all.filter(hasCustomDomain).length,
|
|
161
|
+
checked: checked.length,
|
|
162
|
+
total: total || all.length,
|
|
163
|
+
...(errors && { plan_read_errors: errors }),
|
|
164
|
+
...(checked.length < (total || all.length) && { partial: `Plans checked for ${checked.length}/${total} sites; raise max_sites for full coverage.` }),
|
|
165
|
+
notes: [
|
|
166
|
+
"Team sites are not included (personal sites only).",
|
|
167
|
+
"custom_domain_sites = verified, not blocked/deleted, not *.webcake.me / *.mywebcake.com / *.storecake.net / *.storecake.io. published_at is set at creation, so it is not used.",
|
|
168
|
+
...PLAN_NOTES,
|
|
169
|
+
],
|
|
170
|
+
};
|
|
171
|
+
}));
|
|
172
|
+
server.tool("list_plans", "List the plan catalog (gói cước): id, name, description, attributes. Plan names are free text, not an enum.", {}, () => handle(async () => {
|
|
173
|
+
const res = await api.listPackages();
|
|
174
|
+
const list = res?.packages?.data ?? res?.data?.packages?.data ?? [];
|
|
175
|
+
return list.map((p) => ({
|
|
176
|
+
id: p.id,
|
|
177
|
+
name: p.name,
|
|
178
|
+
description: p.description ?? null,
|
|
179
|
+
package_attributes: p.package_attributes ?? [],
|
|
180
|
+
is_hidden: !!p.is_hidden,
|
|
181
|
+
}));
|
|
182
|
+
}));
|
|
183
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webcake-storefront-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.35.0",
|
|
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",
|