@nextblock-cms/cortex 0.12.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/client.cjs.js +1 -0
- package/client.d.ts +1 -0
- package/client.es.js +4 -0
- package/index.cjs.js +1 -0
- package/index.d.ts +13 -0
- package/index.es.js +135 -0
- package/lib/ai-block-generation.cjs.js +5 -0
- package/lib/ai-block-generation.d.ts +21 -0
- package/lib/ai-block-generation.es.js +195 -0
- package/lib/ai-client.cjs.js +1 -0
- package/lib/ai-client.d.ts +48 -0
- package/lib/ai-client.es.js +141 -0
- package/lib/ai-config.cjs.js +1 -0
- package/lib/ai-config.d.ts +31 -0
- package/lib/ai-config.es.js +72 -0
- package/lib/ai-cortex-widget-builder.cjs.js +1 -0
- package/lib/ai-cortex-widget-builder.d.ts +14 -0
- package/lib/ai-cortex-widget-builder.es.js +72 -0
- package/lib/ai-global-agent-custom-block-tools.cjs.js +1 -0
- package/lib/ai-global-agent-custom-block-tools.d.ts +208 -0
- package/lib/ai-global-agent-custom-block-tools.es.js +220 -0
- package/lib/ai-global-agent-db-tools.cjs.js +1 -0
- package/lib/ai-global-agent-db-tools.d.ts +280 -0
- package/lib/ai-global-agent-db-tools.es.js +879 -0
- package/lib/ai-global-agent-ecommerce.cjs.js +1 -0
- package/lib/ai-global-agent-ecommerce.d.ts +2 -0
- package/lib/ai-global-agent-ecommerce.es.js +7 -0
- package/lib/ai-global-agent-tools.cjs.js +15 -0
- package/lib/ai-global-agent-tools.d.ts +3109 -0
- package/lib/ai-global-agent-tools.es.js +2812 -0
- package/lib/ai-key-crypto.cjs.js +1 -0
- package/lib/ai-key-crypto.d.ts +32 -0
- package/lib/ai-key-crypto.es.js +88 -0
- package/lib/ai-model-catalog.cjs.js +1 -0
- package/lib/ai-model-catalog.d.ts +7 -0
- package/lib/ai-model-catalog.es.js +25 -0
- package/lib/ai-model-registry.cjs.js +3 -0
- package/lib/ai-model-registry.d.ts +79 -0
- package/lib/ai-model-registry.es.js +279 -0
- package/lib/cortex-widget-registry.cjs.js +1 -0
- package/lib/cortex-widget-registry.d.ts +19 -0
- package/lib/cortex-widget-registry.es.js +47 -0
- package/lib/cortex-widget-schema.cjs.js +5 -0
- package/lib/cortex-widget-schema.d.ts +224 -0
- package/lib/cortex-widget-schema.es.js +316 -0
- package/lib/zod-config.cjs.js +1 -0
- package/lib/zod-config.d.ts +2 -0
- package/lib/zod-config.es.js +6 -0
- package/package.json +39 -0
|
@@ -0,0 +1,2812 @@
|
|
|
1
|
+
import { tool as w } from "ai";
|
|
2
|
+
import { createCortexDatabaseAgentTools as St } from "./ai-global-agent-db-tools.es.js";
|
|
3
|
+
import { createCortexCustomBlockTools as Et } from "./ai-global-agent-custom-block-tools.es.js";
|
|
4
|
+
import "./zod-config.es.js";
|
|
5
|
+
import { z as o } from "zod";
|
|
6
|
+
const O = [
|
|
7
|
+
"text",
|
|
8
|
+
"heading",
|
|
9
|
+
"image",
|
|
10
|
+
"button",
|
|
11
|
+
"posts_grid",
|
|
12
|
+
"video_embed",
|
|
13
|
+
"section",
|
|
14
|
+
"form",
|
|
15
|
+
"testimonial",
|
|
16
|
+
"product_grid",
|
|
17
|
+
"featured_product",
|
|
18
|
+
"cart",
|
|
19
|
+
"checkout",
|
|
20
|
+
"product_details"
|
|
21
|
+
], At = 1e4, Pt = {
|
|
22
|
+
arabic: "ar",
|
|
23
|
+
chinese: "zh",
|
|
24
|
+
dutch: "nl",
|
|
25
|
+
english: "en",
|
|
26
|
+
french: "fr",
|
|
27
|
+
francaise: "fr",
|
|
28
|
+
francais: "fr",
|
|
29
|
+
german: "de",
|
|
30
|
+
italian: "it",
|
|
31
|
+
japanese: "ja",
|
|
32
|
+
korean: "ko",
|
|
33
|
+
portuguese: "pt",
|
|
34
|
+
russian: "ru",
|
|
35
|
+
spanish: "es"
|
|
36
|
+
}, Re = o.string().trim().min(1).max(2048).refine(
|
|
37
|
+
(e) => e.startsWith("/") || e.startsWith("#") || e.startsWith("http://") || e.startsWith("https://") || e.startsWith("mailto:") || e.startsWith("tel:"),
|
|
38
|
+
"URL must be a relative path, hash link, http(s) URL, mailto URL, or tel URL."
|
|
39
|
+
), Be = o.strictObject({
|
|
40
|
+
label: o.string().trim().min(1).max(120),
|
|
41
|
+
target: o.enum(["_self", "_blank"]).optional(),
|
|
42
|
+
url: Re
|
|
43
|
+
}), Ge = Be.extend({
|
|
44
|
+
children: o.array(Be).max(20).optional()
|
|
45
|
+
}), Bt = o.strictObject({
|
|
46
|
+
label: o.string().trim().min(1).max(120).optional(),
|
|
47
|
+
url: Re.optional()
|
|
48
|
+
}).refine((e) => !!(e.label || e.url), {
|
|
49
|
+
message: "Navigation item match requires label or url."
|
|
50
|
+
}), ee = o.strictObject({
|
|
51
|
+
items: o.array(Ge).min(1).max(30),
|
|
52
|
+
languageCode: o.string().trim().min(2).max(80).default("en").describe('Locale code or language name, for example "en", "fr", "English", or "French".'),
|
|
53
|
+
match: Bt.optional().describe('For mode "update", identifies the existing navigation item to update.'),
|
|
54
|
+
mode: o.enum(["append", "replace", "update"]).default("append")
|
|
55
|
+
}), te = o.strictObject({
|
|
56
|
+
copyright: o.record(o.string().trim().min(2).max(12), o.string().trim().min(1).max(500)).optional(),
|
|
57
|
+
languageCode: o.string().trim().min(2).max(80).default("en").describe('Locale code or language name, for example "en", "fr", "English", or "French".'),
|
|
58
|
+
links: o.array(Ge).min(1).max(30).optional()
|
|
59
|
+
}), ye = o.strictObject({
|
|
60
|
+
limit: o.number().int().min(1).max(8).default(4),
|
|
61
|
+
query: o.string().trim().min(2).max(300)
|
|
62
|
+
}), ze = o.object({
|
|
63
|
+
currency: o.string().trim().min(3).max(3).optional().describe(
|
|
64
|
+
"Optional currency code for currency-specific monetary reports (e.g., USD, CAD). Do not set this for plain order-status counts unless the user asks for a currency."
|
|
65
|
+
),
|
|
66
|
+
query: o.string().describe("The analytical question about orders, products, or revenue."),
|
|
67
|
+
reportType: o.enum(["revenue", "orders", "products", "general"]).optional().default("general").describe("The focus area of the statistical report."),
|
|
68
|
+
timeRange: o.enum(["today", "this_month", "last_7_days", "last_30_days", "last_month", "last_90_days", "all_time"]).optional().default("all_time").describe("The time period for the report. Use all_time for current order-status counts unless the user names a specific period.")
|
|
69
|
+
}), Ke = o.strictObject({
|
|
70
|
+
contentType: o.enum(["page", "post", "product"]),
|
|
71
|
+
currentEditor: o.strictObject({
|
|
72
|
+
blockId: o.union([o.number().int().positive(), o.string().trim().min(1).max(120)]).nullable().optional(),
|
|
73
|
+
blockType: o.string().trim().min(1).max(80).nullable().optional(),
|
|
74
|
+
field: o.string().trim().min(1).max(120).nullable().optional()
|
|
75
|
+
}).optional(),
|
|
76
|
+
entityId: o.union([o.number().int().positive(), o.string().trim().min(1).max(120)]),
|
|
77
|
+
languageId: o.number().int().positive().nullable().optional(),
|
|
78
|
+
slug: o.string().trim().min(1).max(300).nullable().optional(),
|
|
79
|
+
title: o.string().trim().min(1).max(300).nullable().optional(),
|
|
80
|
+
translationGroupId: o.string().trim().min(1).max(120).nullable().optional()
|
|
81
|
+
}), Ve = o.strictObject({
|
|
82
|
+
includeBlockContent: o.boolean().default(!1),
|
|
83
|
+
includeBlocks: o.boolean().default(!0)
|
|
84
|
+
}), ne = o.strictObject({
|
|
85
|
+
fields: o.strictObject({
|
|
86
|
+
description_json: o.unknown().optional(),
|
|
87
|
+
excerpt: o.string().max(2e3).nullable().optional(),
|
|
88
|
+
feature_image_id: o.string().trim().min(1).max(120).nullable().optional(),
|
|
89
|
+
label: o.string().max(120).nullable().optional(),
|
|
90
|
+
meta_description: o.string().max(500).nullable().optional(),
|
|
91
|
+
meta_title: o.string().max(160).nullable().optional(),
|
|
92
|
+
published_at: o.string().max(80).nullable().optional(),
|
|
93
|
+
short_description: o.string().max(2e3).nullable().optional(),
|
|
94
|
+
slug: o.string().trim().min(1).max(300).optional(),
|
|
95
|
+
status: o.enum(["draft", "published", "active", "archived"]).optional(),
|
|
96
|
+
subtitle: o.string().max(300).nullable().optional(),
|
|
97
|
+
title: o.string().trim().min(1).max(300).optional()
|
|
98
|
+
}).partial()
|
|
99
|
+
}), oe = o.strictObject({
|
|
100
|
+
blockId: o.number().int().positive(),
|
|
101
|
+
blockType: o.enum(O).optional(),
|
|
102
|
+
content: o.record(o.string(), o.unknown())
|
|
103
|
+
}), re = o.strictObject({
|
|
104
|
+
blockIndex: o.number().int().min(0),
|
|
105
|
+
blockType: o.enum(O).optional(),
|
|
106
|
+
columnIndex: o.number().int().min(0),
|
|
107
|
+
content: o.record(o.string(), o.unknown()),
|
|
108
|
+
parentBlockId: o.number().int().positive()
|
|
109
|
+
}), Ft = o.enum(["page", "post", "product"]), ie = o.strictObject({
|
|
110
|
+
contentType: Ft.optional(),
|
|
111
|
+
entityId: o.union([o.number().int().positive(), o.string().trim().min(1).max(120)]).optional(),
|
|
112
|
+
slug: o.string().trim().min(1).max(300).optional(),
|
|
113
|
+
title: o.string().trim().min(1).max(300).optional()
|
|
114
|
+
}), he = o.strictObject({
|
|
115
|
+
blockType: o.enum(O),
|
|
116
|
+
content: o.record(o.string(), o.unknown()),
|
|
117
|
+
order: o.number().int().min(0).optional()
|
|
118
|
+
}), ae = ie.extend({
|
|
119
|
+
anchorBlockId: o.number().int().positive().optional(),
|
|
120
|
+
anchorBlockType: o.enum(O).optional(),
|
|
121
|
+
block: he,
|
|
122
|
+
position: o.enum(["before", "after", "start", "end"]).default("end")
|
|
123
|
+
}), se = o.strictObject({
|
|
124
|
+
blocks: o.array(he).max(20).optional(),
|
|
125
|
+
contactEmail: o.string().email().optional(),
|
|
126
|
+
feature_image_id: o.string().trim().min(1).max(120).nullable().optional(),
|
|
127
|
+
languageCode: o.string().trim().min(2).max(80).optional(),
|
|
128
|
+
meta_description: o.string().max(500).nullable().optional(),
|
|
129
|
+
meta_title: o.string().max(160).nullable().optional(),
|
|
130
|
+
slug: o.string().trim().min(1).max(300).optional(),
|
|
131
|
+
status: o.enum(["draft", "published", "archived"]).default("draft"),
|
|
132
|
+
title: o.string().trim().min(1).max(300),
|
|
133
|
+
translationGroupId: o.string().trim().min(1).max(120).optional()
|
|
134
|
+
}), le = o.strictObject({
|
|
135
|
+
blocks: o.array(he).max(20).optional(),
|
|
136
|
+
excerpt: o.string().max(2e3).nullable().optional(),
|
|
137
|
+
feature_image_id: o.string().trim().min(1).max(120).nullable().optional(),
|
|
138
|
+
label: o.string().max(120).nullable().optional(),
|
|
139
|
+
languageCode: o.string().trim().min(2).max(80).optional(),
|
|
140
|
+
meta_description: o.string().max(500).nullable().optional(),
|
|
141
|
+
meta_title: o.string().max(160).nullable().optional(),
|
|
142
|
+
published_at: o.string().max(80).nullable().optional(),
|
|
143
|
+
slug: o.string().trim().min(1).max(300).optional(),
|
|
144
|
+
status: o.enum(["draft", "published", "archived"]).default("draft"),
|
|
145
|
+
subtitle: o.string().max(300).nullable().optional(),
|
|
146
|
+
title: o.string().trim().min(1).max(300),
|
|
147
|
+
translationGroupId: o.string().trim().min(1).max(120).optional()
|
|
148
|
+
}), ce = o.strictObject({
|
|
149
|
+
description_json: o.unknown().optional(),
|
|
150
|
+
freemius_plan_id: o.string().optional(),
|
|
151
|
+
freemius_product_id: o.string().optional(),
|
|
152
|
+
is_taxable: o.boolean().default(!0),
|
|
153
|
+
languageCode: o.string().trim().min(2).max(80).optional(),
|
|
154
|
+
meta_description: o.string().max(500).nullable().optional(),
|
|
155
|
+
meta_title: o.string().max(160).nullable().optional(),
|
|
156
|
+
payment_provider: o.enum(["stripe", "freemius"]).default("stripe"),
|
|
157
|
+
price: o.number().min(0).default(0),
|
|
158
|
+
prices: o.record(o.string(), o.number().min(0)).optional(),
|
|
159
|
+
product_type: o.enum(["physical", "digital"]).default("physical"),
|
|
160
|
+
sale_price: o.number().min(0).nullable().optional(),
|
|
161
|
+
sale_prices: o.record(o.string(), o.number().min(0).nullable()).optional(),
|
|
162
|
+
short_description: o.string().max(2e3).nullable().optional(),
|
|
163
|
+
sku: o.string().trim().min(1).max(120).optional(),
|
|
164
|
+
slug: o.string().trim().min(1).max(300).optional(),
|
|
165
|
+
status: o.enum(["draft", "active", "archived"]).default("draft"),
|
|
166
|
+
stock: o.number().int().min(0).default(0),
|
|
167
|
+
title: o.string().trim().min(1).max(300),
|
|
168
|
+
trial_period_days: o.number().int().min(0).default(0),
|
|
169
|
+
trial_requires_payment_method: o.boolean().default(!1),
|
|
170
|
+
translationGroupId: o.string().trim().min(1).max(120).optional(),
|
|
171
|
+
upc: o.string().max(120).nullable().optional()
|
|
172
|
+
}), ue = ie.extend({
|
|
173
|
+
currencyCode: o.string().trim().min(3).max(3).optional(),
|
|
174
|
+
endsAt: o.string().max(80).nullable().optional(),
|
|
175
|
+
field: o.string().trim().min(1).max(120),
|
|
176
|
+
startsAt: o.string().max(80).nullable().optional(),
|
|
177
|
+
value: o.unknown()
|
|
178
|
+
}), Je = ie, de = ie, We = o.discriminatedUnion("tool", [
|
|
179
|
+
o.strictObject({ input: se, tool: o.literal("create_cms_page") }),
|
|
180
|
+
o.strictObject({ input: le, tool: o.literal("create_cms_post") }),
|
|
181
|
+
o.strictObject({ input: ce, tool: o.literal("create_cms_product") }),
|
|
182
|
+
o.strictObject({ input: de, tool: o.literal("delete_cms_item") }),
|
|
183
|
+
o.strictObject({ input: ue, tool: o.literal("update_cms_item_field") }),
|
|
184
|
+
o.strictObject({ input: oe, tool: o.literal("update_content_block") }),
|
|
185
|
+
o.strictObject({ input: ae, tool: o.literal("insert_content_block") }),
|
|
186
|
+
o.strictObject({ input: ne, tool: o.literal("update_current_cms_fields") }),
|
|
187
|
+
o.strictObject({ input: te, tool: o.literal("update_footer") }),
|
|
188
|
+
o.strictObject({ input: ee, tool: o.literal("update_navigation_bar") }),
|
|
189
|
+
o.strictObject({ input: re, tool: o.literal("update_section_column_block") })
|
|
190
|
+
]), Nt = o.union([
|
|
191
|
+
se.extend({ tool: o.literal("create_cms_page") }).transform(({ tool: e, ...n }) => ({ input: n, tool: e })),
|
|
192
|
+
le.extend({ tool: o.literal("create_cms_post") }).transform(({ tool: e, ...n }) => ({ input: n, tool: e })),
|
|
193
|
+
ce.extend({ tool: o.literal("create_cms_product") }).transform(({ tool: e, ...n }) => ({ input: n, tool: e })),
|
|
194
|
+
de.extend({ tool: o.literal("delete_cms_item") }).transform(({ tool: e, ...n }) => ({ input: n, tool: e })),
|
|
195
|
+
ue.extend({ tool: o.literal("update_cms_item_field") }).transform(({ tool: e, ...n }) => ({ input: n, tool: e })),
|
|
196
|
+
oe.extend({ tool: o.literal("update_content_block") }).transform(({ tool: e, ...n }) => ({ input: n, tool: e })),
|
|
197
|
+
ae.extend({ tool: o.literal("insert_content_block") }).transform(({ tool: e, ...n }) => ({ input: n, tool: e })),
|
|
198
|
+
ne.extend({ tool: o.literal("update_current_cms_fields") }).transform(({ tool: e, ...n }) => ({ input: n, tool: e })),
|
|
199
|
+
te.extend({ tool: o.literal("update_footer") }).transform(({ tool: e, ...n }) => ({ input: n, tool: e })),
|
|
200
|
+
ee.extend({ tool: o.literal("update_navigation_bar") }).transform(({ tool: e, ...n }) => ({ input: n, tool: e })),
|
|
201
|
+
re.extend({ tool: o.literal("update_section_column_block") }).transform(({ tool: e, ...n }) => ({ input: n, tool: e }))
|
|
202
|
+
]), jt = o.string().transform((e, n) => {
|
|
203
|
+
const t = Mt(e);
|
|
204
|
+
return t.success ? t.action : (n.addIssue({
|
|
205
|
+
code: "custom",
|
|
206
|
+
message: t.message
|
|
207
|
+
}), o.NEVER);
|
|
208
|
+
}), qt = o.union([
|
|
209
|
+
We,
|
|
210
|
+
Nt,
|
|
211
|
+
jt
|
|
212
|
+
]), He = o.strictObject({
|
|
213
|
+
actions: o.array(qt).min(1).max(8),
|
|
214
|
+
summary: o.string().trim().min(1).max(500).optional()
|
|
215
|
+
});
|
|
216
|
+
function Ot(e) {
|
|
217
|
+
const n = [];
|
|
218
|
+
let t = "", r = 0, i = null, a = !1;
|
|
219
|
+
for (const s of e) {
|
|
220
|
+
if (i) {
|
|
221
|
+
t += s, a ? a = !1 : s === "\\" ? a = !0 : s === i && (i = null);
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
if (s === '"' || s === "'") {
|
|
225
|
+
i = s, t += s;
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
if (s === "[" || s === "{" || s === "(") {
|
|
229
|
+
r++, t += s;
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
if (s === "]" || s === "}" || s === ")") {
|
|
233
|
+
r = Math.max(0, r - 1), t += s;
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
if (s === "," && r === 0) {
|
|
237
|
+
t.trim() && n.push(t.trim()), t = "";
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
t += s;
|
|
241
|
+
}
|
|
242
|
+
return t.trim() && n.push(t.trim()), n;
|
|
243
|
+
}
|
|
244
|
+
function Fe(e) {
|
|
245
|
+
let n = "";
|
|
246
|
+
for (let t = 0; t < e.length; t++) {
|
|
247
|
+
const r = e[t];
|
|
248
|
+
if (r !== "'") {
|
|
249
|
+
n += r;
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
let i = "", a = !1;
|
|
253
|
+
for (t++; t < e.length; t++) {
|
|
254
|
+
const s = e[t];
|
|
255
|
+
if (a) {
|
|
256
|
+
i += s, a = !1;
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
if (s === "\\") {
|
|
260
|
+
a = !0;
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
if (s === "'")
|
|
264
|
+
break;
|
|
265
|
+
i += s;
|
|
266
|
+
}
|
|
267
|
+
n += JSON.stringify(i);
|
|
268
|
+
}
|
|
269
|
+
return n.replace(/\bTrue\b/g, "true").replace(/\bFalse\b/g, "false").replace(/\bNone\b/g, "null");
|
|
270
|
+
}
|
|
271
|
+
function Ut(e) {
|
|
272
|
+
const n = e.trim();
|
|
273
|
+
return n.startsWith("'") && n.endsWith("'") || n.startsWith('"') && n.endsWith('"') || n.startsWith("[") || n.startsWith("{") ? JSON.parse(Fe(n)) : /^-?\d+(?:\.\d+)?$/.test(n) ? Number(n) : n === "true" || n === "True" ? !0 : n === "false" || n === "False" ? !1 : n === "null" || n === "None" ? null : n;
|
|
274
|
+
}
|
|
275
|
+
function Dt(e) {
|
|
276
|
+
const n = {};
|
|
277
|
+
for (const t of Ot(e)) {
|
|
278
|
+
const r = t.indexOf("=");
|
|
279
|
+
if (r <= 0)
|
|
280
|
+
throw new Error(`Expected key=value argument, received "${t}".`);
|
|
281
|
+
const i = t.slice(0, r).trim();
|
|
282
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(i))
|
|
283
|
+
throw new Error(`Invalid argument name "${i}".`);
|
|
284
|
+
n[i] = Ut(t.slice(r + 1));
|
|
285
|
+
}
|
|
286
|
+
return n;
|
|
287
|
+
}
|
|
288
|
+
function Mt(e) {
|
|
289
|
+
const t = e.trim().match(/^([a-z_]+)\(([\s\S]*)\)$/);
|
|
290
|
+
if (!t)
|
|
291
|
+
return {
|
|
292
|
+
message: 'Action plan actions must be JSON objects like { "tool": "create_cms_page", "input": { ... } }, not freeform text.',
|
|
293
|
+
success: !1
|
|
294
|
+
};
|
|
295
|
+
const r = t[1];
|
|
296
|
+
let i;
|
|
297
|
+
try {
|
|
298
|
+
i = Dt(t[2]);
|
|
299
|
+
} catch (l) {
|
|
300
|
+
return {
|
|
301
|
+
message: l instanceof Error ? l.message : "Could not parse action-plan command arguments.",
|
|
302
|
+
success: !1
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
const a = { input: i, tool: r }, s = We.safeParse(a);
|
|
306
|
+
return s.success ? {
|
|
307
|
+
action: s.data,
|
|
308
|
+
success: !0
|
|
309
|
+
} : {
|
|
310
|
+
message: `Invalid action-plan command "${r}": ${s.error.issues.map((l) => l.message).join("; ")}`,
|
|
311
|
+
success: !1
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
function Lt(e) {
|
|
315
|
+
return e.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/\s+/g, " ").trim();
|
|
316
|
+
}
|
|
317
|
+
function V(e, n) {
|
|
318
|
+
return n.some((t) => e.includes(t));
|
|
319
|
+
}
|
|
320
|
+
function Yn(e) {
|
|
321
|
+
const n = Lt(e), t = V(n, ["add ", "insert ", "put ", "create "]), r = V(n, [
|
|
322
|
+
"title",
|
|
323
|
+
"heading",
|
|
324
|
+
"description",
|
|
325
|
+
"intro",
|
|
326
|
+
"copy",
|
|
327
|
+
"paragraph"
|
|
328
|
+
]), i = n.includes("form") && V(n, ["above", "before"]), a = n.includes("contact page") || n.includes("contact pages") || n.includes("contact us") || n.includes("contactez-nous"), s = n.includes("english") && V(n, ["french", "francais", "francaise"]);
|
|
329
|
+
return !t || !r || !i || !a || !s ? null : {
|
|
330
|
+
actions: [
|
|
331
|
+
{
|
|
332
|
+
input: {
|
|
333
|
+
anchorBlockType: "form",
|
|
334
|
+
block: {
|
|
335
|
+
blockType: "text",
|
|
336
|
+
content: {
|
|
337
|
+
html_content: "<h2>Let us help you move faster</h2><p>Have a question, project idea, or need help choosing the right next step? Send us a message and the NextBlock team will get back to you soon.</p>"
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
contentType: "page",
|
|
341
|
+
position: "before",
|
|
342
|
+
slug: "contact-us"
|
|
343
|
+
},
|
|
344
|
+
tool: "insert_content_block"
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
input: {
|
|
348
|
+
anchorBlockType: "form",
|
|
349
|
+
block: {
|
|
350
|
+
blockType: "text",
|
|
351
|
+
content: {
|
|
352
|
+
html_content: "<h2>Parlons de votre projet</h2><p>Vous avez une question, une idee de projet ou besoin d'aide pour avancer? Envoyez-nous un message et l'equipe NextBlock vous repondra rapidement.</p>"
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
contentType: "page",
|
|
356
|
+
position: "before",
|
|
357
|
+
slug: "contactez-nous"
|
|
358
|
+
},
|
|
359
|
+
tool: "insert_content_block"
|
|
360
|
+
}
|
|
361
|
+
],
|
|
362
|
+
summary: "Add visible title and description copy above the forms on the English and French Contact pages."
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
const Rt = o.enum(O), Ne = o.object({
|
|
366
|
+
direction: o.string().optional(),
|
|
367
|
+
stops: o.array(o.object({ color: o.string(), position: o.number() })),
|
|
368
|
+
type: o.enum(["linear", "radial"])
|
|
369
|
+
}), Gt = o.object({
|
|
370
|
+
gradient: Ne.optional(),
|
|
371
|
+
image: o.object({
|
|
372
|
+
alt_text: o.string().optional(),
|
|
373
|
+
blur_data_url: o.string().optional(),
|
|
374
|
+
height: o.number().optional(),
|
|
375
|
+
media_id: o.string(),
|
|
376
|
+
object_key: o.string(),
|
|
377
|
+
overlay: o.object({
|
|
378
|
+
gradient: Ne,
|
|
379
|
+
type: o.literal("gradient")
|
|
380
|
+
}).optional(),
|
|
381
|
+
position: o.enum(["center", "top", "bottom", "left", "right"]),
|
|
382
|
+
quality: o.number().nullable().optional(),
|
|
383
|
+
size: o.enum(["cover", "contain"]),
|
|
384
|
+
width: o.number().optional()
|
|
385
|
+
}).optional(),
|
|
386
|
+
min_height: o.string().optional(),
|
|
387
|
+
solid_color: o.string().optional(),
|
|
388
|
+
theme: o.enum(["primary", "secondary", "muted", "accent", "destructive"]).optional(),
|
|
389
|
+
type: o.enum(["none", "theme", "solid", "gradient", "image"])
|
|
390
|
+
}), zt = o.object({
|
|
391
|
+
block_type: Rt,
|
|
392
|
+
content: o.record(o.string(), o.any()),
|
|
393
|
+
temp_id: o.string().optional()
|
|
394
|
+
}), Kt = o.object({
|
|
395
|
+
background: Gt,
|
|
396
|
+
column_blocks: o.array(o.array(zt)),
|
|
397
|
+
column_gap: o.enum(["none", "sm", "md", "lg", "xl"]),
|
|
398
|
+
container_type: o.enum(["full-width", "container", "container-sm", "container-lg", "container-xl"]),
|
|
399
|
+
padding: o.object({
|
|
400
|
+
bottom: o.enum(["none", "sm", "md", "lg", "xl"]),
|
|
401
|
+
top: o.enum(["none", "sm", "md", "lg", "xl"])
|
|
402
|
+
}),
|
|
403
|
+
responsive_columns: o.object({
|
|
404
|
+
desktop: o.union([o.literal(1), o.literal(2), o.literal(3), o.literal(4)]),
|
|
405
|
+
mobile: o.union([o.literal(1), o.literal(2)]),
|
|
406
|
+
tablet: o.union([o.literal(1), o.literal(2), o.literal(3)])
|
|
407
|
+
}),
|
|
408
|
+
vertical_alignment: o.enum(["start", "center", "end", "stretch"]).optional()
|
|
409
|
+
}), Vt = {
|
|
410
|
+
button: o.object({
|
|
411
|
+
position: o.enum(["left", "center", "right"]).optional(),
|
|
412
|
+
size: o.enum(["default", "sm", "lg", "full"]).optional(),
|
|
413
|
+
text: o.string(),
|
|
414
|
+
url: o.string(),
|
|
415
|
+
variant: o.enum(["default", "outline", "secondary", "ghost", "link"]).optional()
|
|
416
|
+
}),
|
|
417
|
+
cart: o.object({}),
|
|
418
|
+
checkout: o.object({}),
|
|
419
|
+
featured_product: o.object({
|
|
420
|
+
imagePosition: o.enum(["left", "right"]).default("left"),
|
|
421
|
+
productId: o.string().min(1),
|
|
422
|
+
showBackground: o.boolean().default(!1)
|
|
423
|
+
}),
|
|
424
|
+
form: o.object({
|
|
425
|
+
fields: o.array(
|
|
426
|
+
o.object({
|
|
427
|
+
field_type: o.enum(["text", "email", "textarea", "select", "radio", "checkbox"]),
|
|
428
|
+
is_required: o.boolean(),
|
|
429
|
+
label: o.string(),
|
|
430
|
+
options: o.array(o.object({ label: o.string(), value: o.string() })).optional(),
|
|
431
|
+
placeholder: o.string().optional(),
|
|
432
|
+
temp_id: o.string()
|
|
433
|
+
})
|
|
434
|
+
),
|
|
435
|
+
recipient_email: o.string().email(),
|
|
436
|
+
submit_button_text: o.string(),
|
|
437
|
+
success_message: o.string()
|
|
438
|
+
}),
|
|
439
|
+
heading: o.object({
|
|
440
|
+
level: o.union([o.literal(1), o.literal(2), o.literal(3), o.literal(4), o.literal(5), o.literal(6)]),
|
|
441
|
+
textAlign: o.enum(["left", "center", "right", "justify"]).optional(),
|
|
442
|
+
textColor: o.enum(["primary", "secondary", "accent", "muted", "destructive", "background"]).optional(),
|
|
443
|
+
text_content: o.string()
|
|
444
|
+
}),
|
|
445
|
+
image: o.object({
|
|
446
|
+
alt_text: o.string().optional(),
|
|
447
|
+
caption: o.string().optional(),
|
|
448
|
+
height: o.number().nullable().optional(),
|
|
449
|
+
media_id: o.string().nullable(),
|
|
450
|
+
object_key: o.string().nullable().optional(),
|
|
451
|
+
width: o.number().nullable().optional()
|
|
452
|
+
}),
|
|
453
|
+
posts_grid: o.object({
|
|
454
|
+
columns: o.number().min(1).max(6),
|
|
455
|
+
postsPerPage: o.number().min(1).max(50),
|
|
456
|
+
showPagination: o.boolean(),
|
|
457
|
+
title: o.string().optional()
|
|
458
|
+
}),
|
|
459
|
+
product_details: o.object({}),
|
|
460
|
+
product_grid: o.object({
|
|
461
|
+
categoryId: o.string().optional(),
|
|
462
|
+
limit: o.number().min(1).max(20).default(6),
|
|
463
|
+
title: o.string().optional(),
|
|
464
|
+
type: o.enum(["latest", "category"]).default("latest")
|
|
465
|
+
}),
|
|
466
|
+
section: Kt,
|
|
467
|
+
testimonial: o.object({
|
|
468
|
+
author_name: o.string().min(1),
|
|
469
|
+
author_title: o.string().optional(),
|
|
470
|
+
image_url: o.string().url().optional().or(o.literal("")),
|
|
471
|
+
quote: o.string().min(1)
|
|
472
|
+
}),
|
|
473
|
+
text: o.object({
|
|
474
|
+
html_content: o.string()
|
|
475
|
+
}),
|
|
476
|
+
video_embed: o.object({
|
|
477
|
+
autoplay: o.boolean().optional(),
|
|
478
|
+
controls: o.boolean().optional(),
|
|
479
|
+
title: o.string().optional(),
|
|
480
|
+
url: o.string()
|
|
481
|
+
})
|
|
482
|
+
};
|
|
483
|
+
function Jt(e) {
|
|
484
|
+
return O.includes(e);
|
|
485
|
+
}
|
|
486
|
+
function Wt(e) {
|
|
487
|
+
return typeof e?.validateBlockContent == "function" ? e.validateBlockContent : null;
|
|
488
|
+
}
|
|
489
|
+
function Ht(e, n, t) {
|
|
490
|
+
const r = Wt(t);
|
|
491
|
+
if (r)
|
|
492
|
+
return r(e, n);
|
|
493
|
+
const i = Vt[e].safeParse(n);
|
|
494
|
+
return i.success ? { errors: [], isValid: !0, warnings: [] } : {
|
|
495
|
+
errors: i.error.issues.map((a) => {
|
|
496
|
+
const s = a.path.join(".");
|
|
497
|
+
return s ? `${s}: ${a.message}` : a.message;
|
|
498
|
+
}),
|
|
499
|
+
isValid: !1,
|
|
500
|
+
warnings: []
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
function Yt() {
|
|
504
|
+
return o.object({
|
|
505
|
+
content: o.array(o.any()).optional(),
|
|
506
|
+
type: o.literal("doc")
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
function ke() {
|
|
510
|
+
try {
|
|
511
|
+
const { revalidatePath: e } = require("next/cache");
|
|
512
|
+
return e;
|
|
513
|
+
} catch {
|
|
514
|
+
return null;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
function h(e) {
|
|
518
|
+
if (!e?.supabase)
|
|
519
|
+
throw new Error("A Supabase service client is required to execute Cortex AI global tools.");
|
|
520
|
+
return e.supabase;
|
|
521
|
+
}
|
|
522
|
+
function Qt(e, n, t) {
|
|
523
|
+
let r;
|
|
524
|
+
const i = new Promise((a) => {
|
|
525
|
+
r = setTimeout(() => a(t()), n);
|
|
526
|
+
});
|
|
527
|
+
return Promise.race([
|
|
528
|
+
e.finally(() => {
|
|
529
|
+
r && clearTimeout(r);
|
|
530
|
+
}),
|
|
531
|
+
i
|
|
532
|
+
]);
|
|
533
|
+
}
|
|
534
|
+
function pe(e) {
|
|
535
|
+
const n = Ke.safeParse(e?.pageContext);
|
|
536
|
+
if (!n.success)
|
|
537
|
+
throw new Error(
|
|
538
|
+
"No current CMS page context is available. Open a page, post, or product edit screen before using this editing tool."
|
|
539
|
+
);
|
|
540
|
+
return n.data;
|
|
541
|
+
}
|
|
542
|
+
function Ye(e) {
|
|
543
|
+
const n = typeof e.entityId == "number" ? e.entityId : Number.parseInt(e.entityId, 10);
|
|
544
|
+
if (!Number.isInteger(n) || n <= 0)
|
|
545
|
+
throw new Error(`Current ${e.contentType} id must be a positive integer.`);
|
|
546
|
+
return n;
|
|
547
|
+
}
|
|
548
|
+
function Xt(e) {
|
|
549
|
+
const n = String(e.entityId || "").trim();
|
|
550
|
+
if (!n)
|
|
551
|
+
throw new Error(`Current ${e.contentType} id is missing.`);
|
|
552
|
+
return n;
|
|
553
|
+
}
|
|
554
|
+
function we(e) {
|
|
555
|
+
return e.contentType === "product" ? Xt(e) : Ye(e);
|
|
556
|
+
}
|
|
557
|
+
function Zt(e) {
|
|
558
|
+
return typeof e == "string" ? e.trim().replace(/^\/+|\/+$/g, "") : "";
|
|
559
|
+
}
|
|
560
|
+
function en(e, n) {
|
|
561
|
+
const t = Zt(n ?? e.slug);
|
|
562
|
+
return t ? e.contentType === "page" ? t === "home" ? "/" : `/${t}` : e.contentType === "post" ? `/article/${t}` : `/product/${t}` : null;
|
|
563
|
+
}
|
|
564
|
+
function tn(e) {
|
|
565
|
+
const n = String(e.entityId);
|
|
566
|
+
return e.contentType === "page" ? `/cms/pages/${n}/edit` : e.contentType === "post" ? `/cms/posts/${n}/edit` : `/cms/products/${n}/edit`;
|
|
567
|
+
}
|
|
568
|
+
function F(e, n, t) {
|
|
569
|
+
const r = e?.revalidatePath ?? ke();
|
|
570
|
+
if (!r)
|
|
571
|
+
return;
|
|
572
|
+
r(tn(n));
|
|
573
|
+
const i = en(n, t);
|
|
574
|
+
i && r(i), n.contentType === "product" && r("/cms/products");
|
|
575
|
+
}
|
|
576
|
+
function Qe(e) {
|
|
577
|
+
const n = e?.revalidatePath ?? ke();
|
|
578
|
+
n && (n("/", "layout"), n("/cms/navigation"));
|
|
579
|
+
}
|
|
580
|
+
function f(e) {
|
|
581
|
+
return e ? typeof e == "object" && "message" in e ? String(e.message || "Unknown database error.") : String(e) : "Unknown database error.";
|
|
582
|
+
}
|
|
583
|
+
async function Ie() {
|
|
584
|
+
return import("./ai-global-agent-ecommerce.es.js");
|
|
585
|
+
}
|
|
586
|
+
function ge(e) {
|
|
587
|
+
return e === null || typeof e != "object" ? JSON.stringify(e) : Array.isArray(e) ? `[${e.map((n) => ge(n)).join(",")}]` : `{${Object.keys(e).filter((n) => n !== "temp_id").sort().map((n) => `${JSON.stringify(n)}:${ge(e[n])}`).join(",")}}`;
|
|
588
|
+
}
|
|
589
|
+
function nn(e) {
|
|
590
|
+
let n = 2166136261;
|
|
591
|
+
const t = ge(e);
|
|
592
|
+
for (let r = 0; r < t.length; r++)
|
|
593
|
+
n ^= t.charCodeAt(r), n = Math.imul(n, 16777619);
|
|
594
|
+
return (n >>> 0).toString(16).padStart(8, "0");
|
|
595
|
+
}
|
|
596
|
+
function fe(e) {
|
|
597
|
+
return e.replace(/\s+/g, " ").trim().toUpperCase();
|
|
598
|
+
}
|
|
599
|
+
function on(e, n, t) {
|
|
600
|
+
return `${fe(`CONFIRM ${e} ${n}`)} #${nn(t)}`;
|
|
601
|
+
}
|
|
602
|
+
function Xe(e) {
|
|
603
|
+
return {
|
|
604
|
+
confirmationPhrase: on(
|
|
605
|
+
e.action,
|
|
606
|
+
e.subject,
|
|
607
|
+
e.payload
|
|
608
|
+
),
|
|
609
|
+
mutationExecuted: !1,
|
|
610
|
+
preview: e.preview,
|
|
611
|
+
requiresConfirmation: !0,
|
|
612
|
+
success: !0
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
function v(e, n) {
|
|
616
|
+
const t = e[n];
|
|
617
|
+
return typeof t == "string" && t.trim() ? t.trim() : null;
|
|
618
|
+
}
|
|
619
|
+
function J(e, n) {
|
|
620
|
+
const t = Number(e[n]);
|
|
621
|
+
return Number.isFinite(t) ? t : null;
|
|
622
|
+
}
|
|
623
|
+
function N(e, n, t = `${n}s`) {
|
|
624
|
+
return `${e} ${e === 1 ? n : t}`;
|
|
625
|
+
}
|
|
626
|
+
function rn(e, n) {
|
|
627
|
+
const t = v(n, "summary");
|
|
628
|
+
if (t)
|
|
629
|
+
return t;
|
|
630
|
+
const r = v(n, "title"), i = v(n, "slug"), a = v(n, "status"), s = v(n, "contentType"), l = v(n, "field"), m = v(n, "mode"), u = v(n, "languageCode"), c = J(n, "blockCount"), d = J(n, "itemCount"), g = J(n, "affectedCount");
|
|
631
|
+
if (e === "create_cms_page" || e === "create_cms_post")
|
|
632
|
+
return `Create ${a || "draft"} ${e === "create_cms_page" ? "page" : "post"} "${r || i || "Untitled"}"${i ? ` at slug "${i}"` : ""}${c !== null ? ` with ${N(c, "content block")}` : ""}.`;
|
|
633
|
+
if (e === "create_cms_product")
|
|
634
|
+
return `Create ${a || "draft"} product "${r || i || "Untitled"}"${i ? ` at slug "${i}"` : ""}.`;
|
|
635
|
+
if (e === "update_cms_item_field")
|
|
636
|
+
return `Update ${l || "one field"} on the ${s || "CMS item"} "${r || i || "selected item"}".`;
|
|
637
|
+
if (e === "update_navigation_bar")
|
|
638
|
+
return `${m === "append" ? "Add" : m === "update" ? "Update" : "Replace"} ${d !== null ? N(d, "navigation item") : "navigation items"} in the ${u || "selected"} header navigation.`;
|
|
639
|
+
if (e === "update_footer") {
|
|
640
|
+
const p = J(n, "linkCount");
|
|
641
|
+
return `Update the ${u || "selected"} footer${p !== null ? ` with ${N(p, "link")}` : ""}.`;
|
|
642
|
+
}
|
|
643
|
+
return e === "update_content_block" ? `Update the selected ${v(n, "blockType") || "content"} block.` : e === "insert_content_block" ? `Insert ${v(n, "blockType") || "content"} block on the ${s || "CMS item"} "${r || i || "selected item"}".` : e === "update_section_column_block" ? `Update the selected nested ${v(n, "nestedBlockType") || "section"} block.` : e === "delete_cms_item" || e === "prepare_delete_cms_item" ? `Delete ${g !== null ? N(g, s || "CMS item") : `the selected ${s || "CMS item"}`}${r || i ? ` for "${r || i}"` : ""}.` : "Complete the requested CMS change.";
|
|
644
|
+
}
|
|
645
|
+
function x(e) {
|
|
646
|
+
if (e.context?.skipConfirmation)
|
|
647
|
+
return null;
|
|
648
|
+
const n = Xe(e), t = fe(e.context?.latestUserMessage || ""), r = fe(n.confirmationPhrase);
|
|
649
|
+
return t.includes(r) ? null : n;
|
|
650
|
+
}
|
|
651
|
+
function Ze(e) {
|
|
652
|
+
const n = e?.actorUserId;
|
|
653
|
+
if (!n)
|
|
654
|
+
throw new Error("A confirmed CMS mutation requires an authenticated admin actor.");
|
|
655
|
+
return n;
|
|
656
|
+
}
|
|
657
|
+
function Ce() {
|
|
658
|
+
return globalThis.crypto?.randomUUID?.() || `id-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
659
|
+
}
|
|
660
|
+
function me(e) {
|
|
661
|
+
return e.toLowerCase().trim().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "").replace(/-+/g, "-").replace(/^-|-$/g, "").slice(0, 300);
|
|
662
|
+
}
|
|
663
|
+
function Te(e) {
|
|
664
|
+
return (e || "USD").trim().toUpperCase();
|
|
665
|
+
}
|
|
666
|
+
function xe(e, n) {
|
|
667
|
+
const r = (/* @__PURE__ */ new Set(["BIF", "CLP", "DJF", "GNF", "JPY", "KMF", "KRW", "MGA", "PYG", "RWF", "UGX", "VND", "VUV", "XAF", "XOF", "XPF"])).has(Te(n)) ? 0 : 2;
|
|
668
|
+
return e / 10 ** r;
|
|
669
|
+
}
|
|
670
|
+
function an(e, n) {
|
|
671
|
+
return typeof e == "number" && Number.isFinite(e) ? xe(e, n) : 0;
|
|
672
|
+
}
|
|
673
|
+
function je(e, n) {
|
|
674
|
+
return !e || typeof e != "object" || Array.isArray(e) ? {} : Object.entries(e).reduce(
|
|
675
|
+
(t, [r, i]) => (typeof i == "number" && Number.isFinite(i) && (t[Te(r || n)] = xe(
|
|
676
|
+
i,
|
|
677
|
+
r || n
|
|
678
|
+
)), t),
|
|
679
|
+
{}
|
|
680
|
+
);
|
|
681
|
+
}
|
|
682
|
+
function G(e, n) {
|
|
683
|
+
if (!R(e))
|
|
684
|
+
throw new Error(`${n} content must be a JSON object.`);
|
|
685
|
+
return JSON.parse(JSON.stringify(e));
|
|
686
|
+
}
|
|
687
|
+
function H(e) {
|
|
688
|
+
return JSON.parse(JSON.stringify(e));
|
|
689
|
+
}
|
|
690
|
+
function R(e) {
|
|
691
|
+
return !!(e && typeof e == "object" && !Array.isArray(e));
|
|
692
|
+
}
|
|
693
|
+
function _e(e, n) {
|
|
694
|
+
const t = H(e);
|
|
695
|
+
for (const [r, i] of Object.entries(n))
|
|
696
|
+
if (i !== void 0) {
|
|
697
|
+
if (R(i) && R(t[r])) {
|
|
698
|
+
t[r] = _e(t[r], i);
|
|
699
|
+
continue;
|
|
700
|
+
}
|
|
701
|
+
t[r] = H(i);
|
|
702
|
+
}
|
|
703
|
+
return t;
|
|
704
|
+
}
|
|
705
|
+
function et(e, n) {
|
|
706
|
+
if (n.contentType === "product")
|
|
707
|
+
throw new Error("Products do not have page/post content blocks in this editor context.");
|
|
708
|
+
const t = Ye(n);
|
|
709
|
+
if ((n.contentType === "page" ? Number(e.page_id) : Number(e.post_id)) !== t)
|
|
710
|
+
throw new Error(
|
|
711
|
+
`Block ${e.id} does not belong to the current ${n.contentType} being edited.`
|
|
712
|
+
);
|
|
713
|
+
}
|
|
714
|
+
function Y(e, n) {
|
|
715
|
+
const t = typeof e == "string" ? e : "";
|
|
716
|
+
if (!Jt(t))
|
|
717
|
+
throw new Error(`${n} has unsupported block type "${t || "unknown"}".`);
|
|
718
|
+
return t;
|
|
719
|
+
}
|
|
720
|
+
function tt(e, n, t) {
|
|
721
|
+
if (e && e !== n)
|
|
722
|
+
throw new Error(
|
|
723
|
+
`${t} is a "${n}" block. Refusing to update it as "${e}".`
|
|
724
|
+
);
|
|
725
|
+
}
|
|
726
|
+
function j(e, n, t, r) {
|
|
727
|
+
const i = Ht(e, n, r);
|
|
728
|
+
if (!i.isValid)
|
|
729
|
+
throw new Error(
|
|
730
|
+
`${t} content is invalid for block type "${e}": ${i.errors.join("; ")}`
|
|
731
|
+
);
|
|
732
|
+
}
|
|
733
|
+
function nt(e) {
|
|
734
|
+
return e === "section";
|
|
735
|
+
}
|
|
736
|
+
function sn(e) {
|
|
737
|
+
return typeof e.html_content == "string" ? "text" : typeof e.text == "string" && typeof e.url == "string" ? "button" : typeof e.text_content == "string" ? "heading" : "media_id" in e || "object_key" in e ? "image" : typeof e.quote == "string" && typeof e.author_name == "string" ? "testimonial" : typeof e.url == "string" && ("controls" in e || "autoplay" in e || "title" in e) ? "video_embed" : Array.isArray(e.fields) || typeof e.recipient_email == "string" ? "form" : "postsPerPage" in e || "showPagination" in e ? "posts_grid" : typeof e.productId == "string" ? "featured_product" : "limit" in e && "type" in e ? "product_grid" : null;
|
|
738
|
+
}
|
|
739
|
+
function Q(e) {
|
|
740
|
+
return `ai-${e}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
741
|
+
}
|
|
742
|
+
function qe(e, n, t) {
|
|
743
|
+
if (!R(e))
|
|
744
|
+
throw new Error(`${n} must be a JSON object.`);
|
|
745
|
+
const r = e.block_type ?? e.blockType, i = Y(r, n);
|
|
746
|
+
if (nt(i))
|
|
747
|
+
throw new Error(`${n} cannot be a nested ${i} block.`);
|
|
748
|
+
const a = at(
|
|
749
|
+
i,
|
|
750
|
+
G(e.content, n),
|
|
751
|
+
n,
|
|
752
|
+
t
|
|
753
|
+
), s = e.temp_id ?? e.tempId, l = typeof s == "string" && s.trim() ? s : Q(i);
|
|
754
|
+
return {
|
|
755
|
+
block_type: i,
|
|
756
|
+
content: a,
|
|
757
|
+
temp_id: l
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
function ln(e, n) {
|
|
761
|
+
const t = [];
|
|
762
|
+
if ("append_block" in e && t.push(qe(e.append_block, "Nested block to append", n)), "append_blocks" in e) {
|
|
763
|
+
const r = e.append_blocks;
|
|
764
|
+
if (!Array.isArray(r))
|
|
765
|
+
throw new Error("append_blocks must be an array of nested block objects.");
|
|
766
|
+
r.forEach((i, a) => {
|
|
767
|
+
t.push(qe(i, `Nested block to append ${a}`, n));
|
|
768
|
+
});
|
|
769
|
+
}
|
|
770
|
+
return t;
|
|
771
|
+
}
|
|
772
|
+
function cn(e, n) {
|
|
773
|
+
if ("append_block" in e || "append_blocks" in e || "background" in e || "column_blocks" in e || "column_gap" in e || "container_type" in e || "padding" in e || "responsive_columns" in e || "vertical_alignment" in e)
|
|
774
|
+
return null;
|
|
775
|
+
const t = sn(e);
|
|
776
|
+
if (!t)
|
|
777
|
+
return null;
|
|
778
|
+
const r = G(e, `Nested ${t} block`);
|
|
779
|
+
return j(t, r, `Nested ${t} block`, n), {
|
|
780
|
+
block_type: t,
|
|
781
|
+
content: r,
|
|
782
|
+
temp_id: Q(t)
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
function un(e, n) {
|
|
786
|
+
const t = e.append_column_index ?? e.column_index;
|
|
787
|
+
if (t === void 0)
|
|
788
|
+
return 0;
|
|
789
|
+
if (typeof t != "number" || !Number.isInteger(t) || t < 0)
|
|
790
|
+
throw new Error("append_column_index must be a non-negative integer.");
|
|
791
|
+
if (n > 0 && t >= n)
|
|
792
|
+
throw new Error(
|
|
793
|
+
`append_column_index ${t} is outside the existing ${n} column(s).`
|
|
794
|
+
);
|
|
795
|
+
return t;
|
|
796
|
+
}
|
|
797
|
+
function dn(e, n, t, r) {
|
|
798
|
+
if (!nt(e))
|
|
799
|
+
return _e(n, t);
|
|
800
|
+
const i = { ...t }, a = ln(i, r), s = cn(i, r);
|
|
801
|
+
s && a.push(s), delete i.append_block, delete i.append_blocks, delete i.append_column_index, delete i.column_index;
|
|
802
|
+
const l = _e(n, i);
|
|
803
|
+
if (a.length > 0) {
|
|
804
|
+
const m = Array.isArray(n.column_blocks) ? H(n.column_blocks) : [], u = un(t, m.length), c = m.length > 0 ? m : [[]];
|
|
805
|
+
for (; c.length <= u; )
|
|
806
|
+
c.push([]);
|
|
807
|
+
c[u] = [
|
|
808
|
+
...c[u] || [],
|
|
809
|
+
...a
|
|
810
|
+
], l.column_blocks = c;
|
|
811
|
+
}
|
|
812
|
+
return l;
|
|
813
|
+
}
|
|
814
|
+
function pn(e, n) {
|
|
815
|
+
return {
|
|
816
|
+
blockType: e.block_type,
|
|
817
|
+
content: n ? e.content : void 0,
|
|
818
|
+
id: e.id,
|
|
819
|
+
languageId: e.language_id,
|
|
820
|
+
order: e.order,
|
|
821
|
+
pageId: e.page_id,
|
|
822
|
+
postId: e.post_id
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
function q(e) {
|
|
826
|
+
return typeof e == "string" ? e.trim().toLowerCase() : "";
|
|
827
|
+
}
|
|
828
|
+
function Oe(e) {
|
|
829
|
+
return typeof e == "string" ? e.trim().toLowerCase() : "";
|
|
830
|
+
}
|
|
831
|
+
function ot(e) {
|
|
832
|
+
return e.reduce((n, t) => n + 1 + (t.children?.length || 0), 0);
|
|
833
|
+
}
|
|
834
|
+
function W(e) {
|
|
835
|
+
return typeof e == "string" ? e.trim().toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "") : "";
|
|
836
|
+
}
|
|
837
|
+
async function U(e, n) {
|
|
838
|
+
const t = n.trim(), r = W(t), i = Pt[r], { data: a, error: s } = await e.from("languages").select("id, code, name, is_active");
|
|
839
|
+
if (s)
|
|
840
|
+
throw new Error(`Failed to load language "${n}": ${f(s)}`);
|
|
841
|
+
const m = (Array.isArray(a) ? a : []).filter((c) => c.is_active !== !1), u = m.find((c) => {
|
|
842
|
+
const d = W(c.code), g = W(c.name);
|
|
843
|
+
return d === r || d === i || g === r;
|
|
844
|
+
});
|
|
845
|
+
if (!u?.id || !u?.code) {
|
|
846
|
+
const c = m.map((d) => d.code).filter(Boolean).join(", ");
|
|
847
|
+
throw new Error(
|
|
848
|
+
`Language "${n}" was not found.${c ? ` Available languages: ${c}.` : ""}`
|
|
849
|
+
);
|
|
850
|
+
}
|
|
851
|
+
return {
|
|
852
|
+
code: String(u.code),
|
|
853
|
+
id: Number(u.id)
|
|
854
|
+
};
|
|
855
|
+
}
|
|
856
|
+
async function $e(e, n) {
|
|
857
|
+
if (n)
|
|
858
|
+
return U(e, n);
|
|
859
|
+
const { data: t, error: r } = await e.from("languages").select("id, code, name, is_active, is_default");
|
|
860
|
+
if (r)
|
|
861
|
+
throw new Error(`Failed to load active languages: ${f(r)}`);
|
|
862
|
+
const i = (Array.isArray(t) ? t : []).filter(
|
|
863
|
+
(s) => s.is_active !== !1
|
|
864
|
+
), a = i.find((s) => s.is_default) || i.find((s) => W(s.code) === "en") || i[0];
|
|
865
|
+
if (!a?.id || !a?.code)
|
|
866
|
+
throw new Error("No active CMS language is available for Cortex AI content creation.");
|
|
867
|
+
return {
|
|
868
|
+
code: String(a.code),
|
|
869
|
+
id: Number(a.id)
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
async function mn(e) {
|
|
873
|
+
try {
|
|
874
|
+
const { data: n, error: t } = await e.from("currencies").select("code, is_default, is_active").eq("is_active", !0);
|
|
875
|
+
if (t)
|
|
876
|
+
return "USD";
|
|
877
|
+
const r = Array.isArray(n) ? n : [], i = r.find((a) => a.is_default) || r[0];
|
|
878
|
+
return Te(i?.code || "USD");
|
|
879
|
+
} catch {
|
|
880
|
+
return "USD";
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
async function gn(e) {
|
|
884
|
+
const n = e.contentType === "page" ? "pages" : e.contentType === "post" ? "posts" : "products";
|
|
885
|
+
let t = "id", r = e.entityId;
|
|
886
|
+
if (r === void 0 && e.slug && (t = "slug", r = e.slug), r === void 0 && e.title && (t = "title", r = e.title), r === void 0)
|
|
887
|
+
throw new Error(`A ${e.contentType} target requires an id, slug, title, or current edit context.`);
|
|
888
|
+
const { data: i, error: a } = await e.supabase.from(n).select("*").eq(t, r);
|
|
889
|
+
if (a)
|
|
890
|
+
throw new Error(`Failed to resolve ${e.contentType}: ${f(a)}`);
|
|
891
|
+
const s = Array.isArray(i) ? i : i ? [i] : [];
|
|
892
|
+
if (s.length !== 1)
|
|
893
|
+
throw new Error(
|
|
894
|
+
s.length === 0 ? `No ${e.contentType} matched ${t} "${String(r)}".` : `Multiple ${e.contentType}s matched ${t} "${String(r)}"; use an exact id.`
|
|
895
|
+
);
|
|
896
|
+
return s[0];
|
|
897
|
+
}
|
|
898
|
+
async function ve(e, n) {
|
|
899
|
+
const t = Ke.safeParse(n?.pageContext).success ? n?.pageContext : null, r = e.contentType || t?.contentType;
|
|
900
|
+
if (!r)
|
|
901
|
+
throw new Error("Target contentType is required when no current CMS edit context exists.");
|
|
902
|
+
const i = e.entityId !== void 0 || !!e.slug || !!e.title, a = e.entityId ?? (i ? void 0 : t?.entityId), s = e.slug ?? (i ? void 0 : t?.slug ?? void 0), l = e.title ?? (i ? void 0 : t?.title ?? void 0), m = await gn({
|
|
903
|
+
contentType: r,
|
|
904
|
+
entityId: a,
|
|
905
|
+
slug: a === void 0 && s || void 0,
|
|
906
|
+
supabase: h(n),
|
|
907
|
+
title: a === void 0 && !s && l || void 0
|
|
908
|
+
});
|
|
909
|
+
return {
|
|
910
|
+
contentType: r,
|
|
911
|
+
item: m
|
|
912
|
+
};
|
|
913
|
+
}
|
|
914
|
+
async function X(e) {
|
|
915
|
+
const n = await _n({
|
|
916
|
+
item: e.item,
|
|
917
|
+
languageId: e.languageId,
|
|
918
|
+
menuKey: e.menuKey,
|
|
919
|
+
supabase: e.supabase
|
|
920
|
+
}), t = {
|
|
921
|
+
label: e.item.label,
|
|
922
|
+
language_id: e.languageId,
|
|
923
|
+
menu_key: e.menuKey,
|
|
924
|
+
order: e.order,
|
|
925
|
+
page_id: n?.pageId ?? null,
|
|
926
|
+
parent_id: e.parentId ?? null,
|
|
927
|
+
...n?.navigationTranslationGroupId ? { translation_group_id: n.navigationTranslationGroupId } : {},
|
|
928
|
+
url: e.item.url
|
|
929
|
+
}, { data: r, error: i } = await e.supabase.from("navigation_items").insert(t).select("id").single();
|
|
930
|
+
if (i)
|
|
931
|
+
throw new Error(`Failed to insert ${e.menuKey} navigation item: ${f(i)}`);
|
|
932
|
+
return Number(r.id);
|
|
933
|
+
}
|
|
934
|
+
function fn(e) {
|
|
935
|
+
const n = e.trim();
|
|
936
|
+
if (!n.startsWith("/") || n.startsWith("//"))
|
|
937
|
+
return null;
|
|
938
|
+
const t = n.split("?")[0]?.split("#")[0] || "", r = t === "/" ? "home" : t.replace(/^\/+|\/+$/g, "");
|
|
939
|
+
return r && !r.includes("/") ? r : null;
|
|
940
|
+
}
|
|
941
|
+
async function _n(e) {
|
|
942
|
+
const n = fn(e.item.url);
|
|
943
|
+
if (!n)
|
|
944
|
+
return null;
|
|
945
|
+
const { data: t, error: r } = await e.supabase.from("pages").select("id, slug, translation_group_id, language_id").eq("slug", n).eq("language_id", e.languageId);
|
|
946
|
+
if (r)
|
|
947
|
+
throw new Error(`Failed to resolve linked page for navigation item: ${f(r)}`);
|
|
948
|
+
const i = Array.isArray(t) ? t[0] : t;
|
|
949
|
+
if (!i?.id)
|
|
950
|
+
return null;
|
|
951
|
+
let a = Ce();
|
|
952
|
+
if (i.translation_group_id) {
|
|
953
|
+
const { data: s, error: l } = await e.supabase.from("pages").select("id").eq("translation_group_id", i.translation_group_id);
|
|
954
|
+
if (l)
|
|
955
|
+
throw new Error(
|
|
956
|
+
`Failed to inspect linked page translations for navigation item: ${f(l)}`
|
|
957
|
+
);
|
|
958
|
+
const m = new Set(
|
|
959
|
+
(Array.isArray(s) ? s : []).map((g) => String(g.id)).filter(Boolean)
|
|
960
|
+
), { data: u, error: c } = await e.supabase.from("navigation_items").select("id, page_id, translation_group_id, menu_key").eq("menu_key", e.menuKey);
|
|
961
|
+
if (c)
|
|
962
|
+
throw new Error(
|
|
963
|
+
`Failed to inspect related navigation translations: ${f(c)}`
|
|
964
|
+
);
|
|
965
|
+
const d = (Array.isArray(u) ? u : []).find((g) => g.translation_group_id && m.has(String(g.page_id)));
|
|
966
|
+
d?.translation_group_id && (a = d.translation_group_id);
|
|
967
|
+
}
|
|
968
|
+
return {
|
|
969
|
+
navigationTranslationGroupId: a,
|
|
970
|
+
pageId: Number(i.id)
|
|
971
|
+
};
|
|
972
|
+
}
|
|
973
|
+
async function rt(e) {
|
|
974
|
+
const n = await U(e.supabase, e.languageCode), { data: t, error: r } = await e.supabase.from("navigation_items").select("id, parent_id").eq("menu_key", e.menuKey).eq("language_id", n.id);
|
|
975
|
+
if (r)
|
|
976
|
+
throw new Error(
|
|
977
|
+
`Failed to inspect existing ${e.menuKey} navigation items: ${f(r)}`
|
|
978
|
+
);
|
|
979
|
+
const i = Array.isArray(t) ? t : [], a = i.filter((u) => u.parent_id == null).length, s = ot(e.items);
|
|
980
|
+
it({
|
|
981
|
+
existingItemCount: i.length,
|
|
982
|
+
existingTopLevelCount: a,
|
|
983
|
+
languageCode: n.code,
|
|
984
|
+
menuKey: e.menuKey,
|
|
985
|
+
replacementItemCount: s
|
|
986
|
+
});
|
|
987
|
+
const { error: l } = await e.supabase.from("navigation_items").delete().eq("menu_key", e.menuKey).eq("language_id", n.id);
|
|
988
|
+
if (l)
|
|
989
|
+
throw new Error(`Failed to clear ${e.menuKey} navigation items: ${f(l)}`);
|
|
990
|
+
let m = 0;
|
|
991
|
+
for (const [u, c] of e.items.entries()) {
|
|
992
|
+
const d = await X({
|
|
993
|
+
item: c,
|
|
994
|
+
languageId: n.id,
|
|
995
|
+
menuKey: e.menuKey,
|
|
996
|
+
order: u,
|
|
997
|
+
supabase: e.supabase
|
|
998
|
+
});
|
|
999
|
+
m++;
|
|
1000
|
+
for (const [g, p] of (c.children ?? []).entries())
|
|
1001
|
+
await X({
|
|
1002
|
+
item: p,
|
|
1003
|
+
languageId: n.id,
|
|
1004
|
+
menuKey: e.menuKey,
|
|
1005
|
+
order: g,
|
|
1006
|
+
parentId: d,
|
|
1007
|
+
supabase: e.supabase
|
|
1008
|
+
}), m++;
|
|
1009
|
+
}
|
|
1010
|
+
return {
|
|
1011
|
+
insertedCount: m,
|
|
1012
|
+
languageCode: n.code,
|
|
1013
|
+
menuKey: e.menuKey,
|
|
1014
|
+
skippedCount: 0,
|
|
1015
|
+
updatedCount: 0
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
1018
|
+
function it(e) {
|
|
1019
|
+
if (!(e.existingItemCount === 0 || e.replacementItemCount >= e.existingItemCount))
|
|
1020
|
+
throw new Error(
|
|
1021
|
+
`Refusing destructive ${e.menuKey} navigation replacement for ${e.languageCode}: existing menu has ${e.existingItemCount} items (${e.existingTopLevelCount} top-level), but the replacement only contains ${e.replacementItemCount}. Use mode "update" for renaming or changing a single link, or provide the full menu.`
|
|
1022
|
+
);
|
|
1023
|
+
}
|
|
1024
|
+
async function bn(e) {
|
|
1025
|
+
const n = await U(e.supabase, e.languageCode), { data: t, error: r } = await e.supabase.from("navigation_items").select("id, parent_id").eq("menu_key", e.menuKey).eq("language_id", n.id);
|
|
1026
|
+
if (r)
|
|
1027
|
+
throw new Error(
|
|
1028
|
+
`Failed to inspect existing ${e.menuKey} navigation items: ${f(r)}`
|
|
1029
|
+
);
|
|
1030
|
+
const i = Array.isArray(t) ? t : [];
|
|
1031
|
+
it({
|
|
1032
|
+
existingItemCount: i.length,
|
|
1033
|
+
existingTopLevelCount: i.filter((a) => a.parent_id == null).length,
|
|
1034
|
+
languageCode: n.code,
|
|
1035
|
+
menuKey: e.menuKey,
|
|
1036
|
+
replacementItemCount: ot(e.items)
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
async function yn(e) {
|
|
1040
|
+
if (e.items.length !== 1)
|
|
1041
|
+
throw new Error('mode "update" requires exactly one navigation item.');
|
|
1042
|
+
const n = await U(e.supabase, e.languageCode), t = e.items[0], r = q(e.match?.url) || q(t.url), i = Oe(e.match?.label), { data: a, error: s } = await e.supabase.from("navigation_items").select("id, label, url, parent_id, order").eq("menu_key", e.menuKey).eq("language_id", n.id);
|
|
1043
|
+
if (s)
|
|
1044
|
+
throw new Error(
|
|
1045
|
+
`Failed to load existing ${e.menuKey} navigation items: ${f(s)}`
|
|
1046
|
+
);
|
|
1047
|
+
const m = (Array.isArray(a) ? a : []).find((c) => {
|
|
1048
|
+
const d = q(c.url), g = Oe(c.label);
|
|
1049
|
+
return !!(r && d === r || i && g === i);
|
|
1050
|
+
});
|
|
1051
|
+
if (!m?.id)
|
|
1052
|
+
throw new Error(
|
|
1053
|
+
`Could not find a ${e.menuKey} navigation item to update in ${n.code}. Use a matching label or url.`
|
|
1054
|
+
);
|
|
1055
|
+
const { error: u } = await e.supabase.from("navigation_items").update({
|
|
1056
|
+
label: t.label,
|
|
1057
|
+
url: t.url
|
|
1058
|
+
}).eq("id", m.id);
|
|
1059
|
+
if (u)
|
|
1060
|
+
throw new Error(`Failed to update ${e.menuKey} navigation item: ${f(u)}`);
|
|
1061
|
+
return {
|
|
1062
|
+
insertedCount: 0,
|
|
1063
|
+
languageCode: n.code,
|
|
1064
|
+
menuKey: e.menuKey,
|
|
1065
|
+
skippedCount: 0,
|
|
1066
|
+
updatedCount: 1
|
|
1067
|
+
};
|
|
1068
|
+
}
|
|
1069
|
+
async function hn(e) {
|
|
1070
|
+
const n = await U(e.supabase, e.languageCode), { data: t, error: r } = await e.supabase.from("navigation_items").select("id, url, parent_id, order").eq("menu_key", e.menuKey).eq("language_id", n.id);
|
|
1071
|
+
if (r)
|
|
1072
|
+
throw new Error(
|
|
1073
|
+
`Failed to load existing ${e.menuKey} navigation items: ${f(r)}`
|
|
1074
|
+
);
|
|
1075
|
+
let i = 0, a = 0;
|
|
1076
|
+
const s = Array.isArray(t) ? t : [], l = new Set(
|
|
1077
|
+
s.map((c) => q(c.url)).filter(Boolean)
|
|
1078
|
+
), m = s.filter((c) => c.parent_id == null).map((c) => Number(c.order)).filter(Number.isFinite);
|
|
1079
|
+
let u = m.length > 0 ? Math.max(...m) + 1 : s.length;
|
|
1080
|
+
for (const c of e.items) {
|
|
1081
|
+
const d = q(c.url);
|
|
1082
|
+
if (d && l.has(d)) {
|
|
1083
|
+
a++;
|
|
1084
|
+
continue;
|
|
1085
|
+
}
|
|
1086
|
+
const g = await X({
|
|
1087
|
+
item: c,
|
|
1088
|
+
languageId: n.id,
|
|
1089
|
+
menuKey: e.menuKey,
|
|
1090
|
+
order: u,
|
|
1091
|
+
supabase: e.supabase
|
|
1092
|
+
});
|
|
1093
|
+
i++, u++, d && l.add(d);
|
|
1094
|
+
let p = 0;
|
|
1095
|
+
for (const _ of c.children ?? []) {
|
|
1096
|
+
const k = q(_.url);
|
|
1097
|
+
if (k && l.has(k)) {
|
|
1098
|
+
a++;
|
|
1099
|
+
continue;
|
|
1100
|
+
}
|
|
1101
|
+
await X({
|
|
1102
|
+
item: _,
|
|
1103
|
+
languageId: n.id,
|
|
1104
|
+
menuKey: e.menuKey,
|
|
1105
|
+
order: p,
|
|
1106
|
+
parentId: g,
|
|
1107
|
+
supabase: e.supabase
|
|
1108
|
+
}), i++, p++, k && l.add(k);
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
return {
|
|
1112
|
+
insertedCount: i,
|
|
1113
|
+
languageCode: n.code,
|
|
1114
|
+
menuKey: e.menuKey,
|
|
1115
|
+
skippedCount: a,
|
|
1116
|
+
updatedCount: 0
|
|
1117
|
+
};
|
|
1118
|
+
}
|
|
1119
|
+
function b(e) {
|
|
1120
|
+
return typeof e == "string" && e.trim() ? e.trim() : "";
|
|
1121
|
+
}
|
|
1122
|
+
function kn(e) {
|
|
1123
|
+
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
1124
|
+
}
|
|
1125
|
+
function wn(e) {
|
|
1126
|
+
const n = b(e.field_type ?? e.fieldType ?? e.type ?? e.input_type).toLowerCase().replace(/\s+/g, "_"), t = b(e.label ?? e.name ?? e.placeholder).toLowerCase();
|
|
1127
|
+
return ["email", "textarea", "select", "radio", "checkbox", "text"].includes(n) ? n : t.includes("email") ? "email" : t.includes("message") || t.includes("comment") || t.includes("details") ? "textarea" : "text";
|
|
1128
|
+
}
|
|
1129
|
+
function In(e) {
|
|
1130
|
+
return (Array.isArray(e) && e.length > 0 ? e : [
|
|
1131
|
+
{ field_type: "text", is_required: !0, label: "Name", placeholder: "Your name" },
|
|
1132
|
+
{ field_type: "email", is_required: !0, label: "Email", placeholder: "you@example.com" },
|
|
1133
|
+
{ field_type: "textarea", is_required: !0, label: "Message", placeholder: "How can we help?" }
|
|
1134
|
+
]).map((t, r) => {
|
|
1135
|
+
const i = R(t) ? t : {}, a = b(i.label ?? i.name) || (r === 0 ? "Name" : r === 1 ? "Email" : "Message"), s = wn({ ...i, label: a }), l = i.is_required ?? i.isRequired ?? i.required;
|
|
1136
|
+
return {
|
|
1137
|
+
field_type: s,
|
|
1138
|
+
is_required: typeof l == "boolean" ? l : !0,
|
|
1139
|
+
label: a,
|
|
1140
|
+
options: Array.isArray(i.options) ? i.options : void 0,
|
|
1141
|
+
placeholder: b(i.placeholder) || void 0,
|
|
1142
|
+
temp_id: b(i.temp_id ?? i.tempId ?? i.id) || `field-${r + 1}`
|
|
1143
|
+
};
|
|
1144
|
+
});
|
|
1145
|
+
}
|
|
1146
|
+
function at(e, n, t, r) {
|
|
1147
|
+
const i = H(n);
|
|
1148
|
+
if (e === "heading" && (i.text_content = b(i.text_content) || b(i.text) || b(i.title) || b(i.heading) || "Untitled", i.level = typeof i.level == "number" ? i.level : 1), e === "text") {
|
|
1149
|
+
const a = b(i.html_content) || b(i.html) || b(i.content) || b(i.text);
|
|
1150
|
+
a && (i.html_content = /<\/?[a-z][\s\S]*>/i.test(a) ? a : `<p>${kn(a)}</p>`);
|
|
1151
|
+
}
|
|
1152
|
+
return e === "button" && (i.text = b(i.text) || b(i.label) || b(i.title) || "Learn More", i.url = b(i.url) || b(i.href) || b(i.link) || "#"), e === "form" && (i.fields = In(i.fields), i.submit_button_text = b(i.submit_button_text ?? i.submitButtonText ?? i.button_text) || "Send Message", i.success_message = b(i.success_message ?? i.successMessage) || "Thanks for reaching out. We will reply as soon as possible."), j(e, i, t, r), i;
|
|
1153
|
+
}
|
|
1154
|
+
function Z(e, n, t) {
|
|
1155
|
+
const r = at(
|
|
1156
|
+
e.blockType,
|
|
1157
|
+
G(e.content, `Block ${n}`),
|
|
1158
|
+
`Block ${n}`,
|
|
1159
|
+
t
|
|
1160
|
+
);
|
|
1161
|
+
return {
|
|
1162
|
+
block_type: e.blockType,
|
|
1163
|
+
content: r,
|
|
1164
|
+
order: e.order ?? n
|
|
1165
|
+
};
|
|
1166
|
+
}
|
|
1167
|
+
function Cn(e, n = "Contact Us", t) {
|
|
1168
|
+
return [
|
|
1169
|
+
Z(
|
|
1170
|
+
{
|
|
1171
|
+
blockType: "section",
|
|
1172
|
+
content: {
|
|
1173
|
+
is_hero: !0,
|
|
1174
|
+
background: { type: "none" },
|
|
1175
|
+
column_blocks: [
|
|
1176
|
+
[
|
|
1177
|
+
{
|
|
1178
|
+
block_type: "heading",
|
|
1179
|
+
content: {
|
|
1180
|
+
level: 1,
|
|
1181
|
+
textAlign: "center",
|
|
1182
|
+
text_content: n
|
|
1183
|
+
},
|
|
1184
|
+
temp_id: Q("heading")
|
|
1185
|
+
},
|
|
1186
|
+
{
|
|
1187
|
+
block_type: "text",
|
|
1188
|
+
content: {
|
|
1189
|
+
html_content: "<p>Have a question, project, or support request? Send us a note and we will get back to you soon.</p>"
|
|
1190
|
+
},
|
|
1191
|
+
temp_id: Q("text")
|
|
1192
|
+
}
|
|
1193
|
+
]
|
|
1194
|
+
],
|
|
1195
|
+
column_gap: "lg",
|
|
1196
|
+
container_type: "container",
|
|
1197
|
+
padding: { bottom: "xl", top: "xl" },
|
|
1198
|
+
responsive_columns: { desktop: 1, mobile: 1, tablet: 1 },
|
|
1199
|
+
vertical_alignment: "center"
|
|
1200
|
+
}
|
|
1201
|
+
},
|
|
1202
|
+
0,
|
|
1203
|
+
t
|
|
1204
|
+
),
|
|
1205
|
+
Z(
|
|
1206
|
+
{
|
|
1207
|
+
blockType: "form",
|
|
1208
|
+
content: {
|
|
1209
|
+
fields: [
|
|
1210
|
+
{
|
|
1211
|
+
field_type: "text",
|
|
1212
|
+
is_required: !0,
|
|
1213
|
+
label: "Name",
|
|
1214
|
+
placeholder: "Your name",
|
|
1215
|
+
temp_id: "field-name"
|
|
1216
|
+
},
|
|
1217
|
+
{
|
|
1218
|
+
field_type: "email",
|
|
1219
|
+
is_required: !0,
|
|
1220
|
+
label: "Email",
|
|
1221
|
+
placeholder: "you@example.com",
|
|
1222
|
+
temp_id: "field-email"
|
|
1223
|
+
},
|
|
1224
|
+
{
|
|
1225
|
+
field_type: "textarea",
|
|
1226
|
+
is_required: !0,
|
|
1227
|
+
label: "Message",
|
|
1228
|
+
placeholder: "How can we help?",
|
|
1229
|
+
temp_id: "field-message"
|
|
1230
|
+
}
|
|
1231
|
+
],
|
|
1232
|
+
recipient_email: e,
|
|
1233
|
+
submit_button_text: "Send Message",
|
|
1234
|
+
success_message: "Thanks for reaching out. We will reply as soon as possible."
|
|
1235
|
+
}
|
|
1236
|
+
},
|
|
1237
|
+
1,
|
|
1238
|
+
t
|
|
1239
|
+
)
|
|
1240
|
+
];
|
|
1241
|
+
}
|
|
1242
|
+
function st(e, n, t, r) {
|
|
1243
|
+
return (!e || e.length === 0) && n ? Cn(n, t, r) : (e || []).map((i, a) => Z(i, a, r));
|
|
1244
|
+
}
|
|
1245
|
+
async function Se(e) {
|
|
1246
|
+
const n = e.contentType === "page" ? "pages" : e.contentType === "post" ? "posts" : "products", { data: t, error: r } = await e.supabase.from(n).select("id, title, slug, language_id").eq("slug", e.slug).eq("language_id", e.languageId);
|
|
1247
|
+
if (r)
|
|
1248
|
+
throw new Error(`Failed to check ${e.contentType} slug uniqueness: ${f(r)}`);
|
|
1249
|
+
const i = Array.isArray(t) ? t : [];
|
|
1250
|
+
return i.length > 0 ? {
|
|
1251
|
+
duplicate: !0,
|
|
1252
|
+
existingItem: i[0],
|
|
1253
|
+
mutationExecuted: !1,
|
|
1254
|
+
success: !1,
|
|
1255
|
+
message: `A ${e.contentType} with slug "${e.slug}" already exists for this language.`
|
|
1256
|
+
} : null;
|
|
1257
|
+
}
|
|
1258
|
+
async function Ee(e) {
|
|
1259
|
+
if (!e.suppliedTranslationGroupId)
|
|
1260
|
+
return {
|
|
1261
|
+
translationGroupId: void 0
|
|
1262
|
+
};
|
|
1263
|
+
const n = e.contentType === "page" ? "pages" : e.contentType === "post" ? "posts" : "products", { data: t, error: r } = await e.supabase.from(n).select("id, title, slug, language_id, translation_group_id").eq("translation_group_id", e.suppliedTranslationGroupId);
|
|
1264
|
+
if (r)
|
|
1265
|
+
throw new Error(
|
|
1266
|
+
`Failed to inspect ${e.contentType} translation group: ${f(r)}`
|
|
1267
|
+
);
|
|
1268
|
+
const i = Array.isArray(t) ? t : [];
|
|
1269
|
+
if (i.length === 0)
|
|
1270
|
+
return {
|
|
1271
|
+
result: {
|
|
1272
|
+
message: `The ${e.contentType} translation group "${e.suppliedTranslationGroupId}" was not found.`,
|
|
1273
|
+
mutationExecuted: !1,
|
|
1274
|
+
success: !1
|
|
1275
|
+
},
|
|
1276
|
+
translationGroupId: e.suppliedTranslationGroupId
|
|
1277
|
+
};
|
|
1278
|
+
const a = i.find(
|
|
1279
|
+
(s) => Number(s.language_id) === e.languageId
|
|
1280
|
+
);
|
|
1281
|
+
return a ? {
|
|
1282
|
+
result: {
|
|
1283
|
+
duplicateTranslation: !0,
|
|
1284
|
+
existingItem: a,
|
|
1285
|
+
message: `A ${e.contentType} translation already exists for ${e.languageCode} in this translation group.`,
|
|
1286
|
+
mutationExecuted: !1,
|
|
1287
|
+
success: !1
|
|
1288
|
+
},
|
|
1289
|
+
translationGroupId: e.suppliedTranslationGroupId
|
|
1290
|
+
} : {
|
|
1291
|
+
translationGroupId: e.suppliedTranslationGroupId
|
|
1292
|
+
};
|
|
1293
|
+
}
|
|
1294
|
+
async function lt(e) {
|
|
1295
|
+
if (e.blocks.length === 0)
|
|
1296
|
+
return [];
|
|
1297
|
+
const n = e.blocks.map((i, a) => ({
|
|
1298
|
+
block_type: i.block_type,
|
|
1299
|
+
content: i.content,
|
|
1300
|
+
language_id: e.languageId,
|
|
1301
|
+
order: i.order ?? a,
|
|
1302
|
+
page_id: e.contentType === "page" ? e.itemId : null,
|
|
1303
|
+
post_id: e.contentType === "post" ? e.itemId : null
|
|
1304
|
+
})), { data: t, error: r } = await e.supabase.from("blocks").insert(n).select("*");
|
|
1305
|
+
if (r)
|
|
1306
|
+
throw new Error(`Failed to insert ${e.contentType} blocks: ${f(r)}`);
|
|
1307
|
+
return Array.isArray(t) ? t : [];
|
|
1308
|
+
}
|
|
1309
|
+
async function ct(e) {
|
|
1310
|
+
const n = e.contentType === "page" ? "pages" : "posts";
|
|
1311
|
+
await e.supabase.from(n).delete().eq("id", e.itemId);
|
|
1312
|
+
}
|
|
1313
|
+
function Ae(e, n) {
|
|
1314
|
+
return e === "page" ? `/cms/pages/${n}/edit` : e === "post" ? `/cms/posts/${n}/edit` : `/cms/products/${n}/edit`;
|
|
1315
|
+
}
|
|
1316
|
+
function Ue(e) {
|
|
1317
|
+
return e === "page" ? "/cms/pages" : e === "post" ? "/cms/posts" : "/cms/products";
|
|
1318
|
+
}
|
|
1319
|
+
async function ut(e, n) {
|
|
1320
|
+
const t = ee.parse(e), r = h(n);
|
|
1321
|
+
t.mode === "replace" && await bn({
|
|
1322
|
+
items: t.items,
|
|
1323
|
+
languageCode: t.languageCode,
|
|
1324
|
+
menuKey: "HEADER",
|
|
1325
|
+
supabase: r
|
|
1326
|
+
});
|
|
1327
|
+
const i = x({
|
|
1328
|
+
action: "UPDATE NAVIGATION",
|
|
1329
|
+
context: n,
|
|
1330
|
+
payload: { input: t, tool: "update_navigation_bar" },
|
|
1331
|
+
preview: {
|
|
1332
|
+
itemCount: t.items.length,
|
|
1333
|
+
languageCode: t.languageCode,
|
|
1334
|
+
mode: t.mode,
|
|
1335
|
+
target: "header navigation"
|
|
1336
|
+
},
|
|
1337
|
+
subject: `${t.mode} header`
|
|
1338
|
+
});
|
|
1339
|
+
if (i)
|
|
1340
|
+
return i;
|
|
1341
|
+
const a = t.mode === "update" ? await yn({
|
|
1342
|
+
items: t.items,
|
|
1343
|
+
languageCode: t.languageCode,
|
|
1344
|
+
match: t.match,
|
|
1345
|
+
menuKey: "HEADER",
|
|
1346
|
+
supabase: r
|
|
1347
|
+
}) : t.mode === "append" ? await hn({
|
|
1348
|
+
items: t.items,
|
|
1349
|
+
languageCode: t.languageCode,
|
|
1350
|
+
menuKey: "HEADER",
|
|
1351
|
+
supabase: r
|
|
1352
|
+
}) : await rt({
|
|
1353
|
+
items: t.items,
|
|
1354
|
+
languageCode: t.languageCode,
|
|
1355
|
+
menuKey: "HEADER",
|
|
1356
|
+
supabase: r
|
|
1357
|
+
});
|
|
1358
|
+
return Qe(n), {
|
|
1359
|
+
...a,
|
|
1360
|
+
mutationExecuted: !0,
|
|
1361
|
+
mode: t.mode,
|
|
1362
|
+
success: !0
|
|
1363
|
+
};
|
|
1364
|
+
}
|
|
1365
|
+
async function dt(e, n) {
|
|
1366
|
+
const t = te.parse(e);
|
|
1367
|
+
if (!t.links?.length && !t.copyright)
|
|
1368
|
+
throw new Error("update_footer requires links or copyright.");
|
|
1369
|
+
const r = h(n), i = x({
|
|
1370
|
+
action: "UPDATE FOOTER",
|
|
1371
|
+
context: n,
|
|
1372
|
+
payload: { input: t, tool: "update_footer" },
|
|
1373
|
+
preview: {
|
|
1374
|
+
copyrightUpdated: !!t.copyright,
|
|
1375
|
+
linkCount: t.links?.length || 0,
|
|
1376
|
+
languageCode: t.languageCode,
|
|
1377
|
+
target: "footer"
|
|
1378
|
+
},
|
|
1379
|
+
subject: t.languageCode
|
|
1380
|
+
});
|
|
1381
|
+
if (i)
|
|
1382
|
+
return i;
|
|
1383
|
+
let a = null;
|
|
1384
|
+
if (t.links?.length && (a = await rt({
|
|
1385
|
+
items: t.links,
|
|
1386
|
+
languageCode: t.languageCode,
|
|
1387
|
+
menuKey: "FOOTER",
|
|
1388
|
+
supabase: r
|
|
1389
|
+
})), t.copyright) {
|
|
1390
|
+
const { error: s } = await r.from("site_settings").upsert({
|
|
1391
|
+
key: "footer_copyright",
|
|
1392
|
+
value: t.copyright
|
|
1393
|
+
});
|
|
1394
|
+
if (s)
|
|
1395
|
+
throw new Error(`Failed to update footer copyright: ${f(s)}`);
|
|
1396
|
+
}
|
|
1397
|
+
return Qe(n), {
|
|
1398
|
+
copyrightUpdated: !!t.copyright,
|
|
1399
|
+
footerNavigation: a,
|
|
1400
|
+
mutationExecuted: !0,
|
|
1401
|
+
success: !0
|
|
1402
|
+
};
|
|
1403
|
+
}
|
|
1404
|
+
function pt(e) {
|
|
1405
|
+
return typeof e == "string" ? e.toLowerCase() : "";
|
|
1406
|
+
}
|
|
1407
|
+
function Tn(e, n) {
|
|
1408
|
+
const t = n.map(pt).join(" ");
|
|
1409
|
+
return e.reduce((r, i) => r + (t.includes(i) ? 1 : 0), 0);
|
|
1410
|
+
}
|
|
1411
|
+
function De(e, n) {
|
|
1412
|
+
return (e.find(
|
|
1413
|
+
(t) => n.some((r) => pt(t).includes(r))
|
|
1414
|
+
) || e.find((t) => t.trim().length > 0) || "No excerpt available.").slice(0, 500);
|
|
1415
|
+
}
|
|
1416
|
+
async function xn(e, n) {
|
|
1417
|
+
const t = ye.parse(e), r = h(n), i = t.query.toLowerCase().split(/\s+/).map((c) => c.trim()).filter(Boolean), [a, s] = await Promise.all([
|
|
1418
|
+
r.from("posts").select("id, title, slug, excerpt, subtitle, meta_description, status, updated_at").eq("status", "published").limit(100),
|
|
1419
|
+
r.from("pages").select("id, title, slug, meta_description, status, updated_at").eq("status", "published").limit(100)
|
|
1420
|
+
]);
|
|
1421
|
+
if (a.error)
|
|
1422
|
+
throw new Error(`Failed to search documentation posts: ${f(a.error)}`);
|
|
1423
|
+
if (s.error)
|
|
1424
|
+
throw new Error(`Failed to search documentation pages: ${f(s.error)}`);
|
|
1425
|
+
const l = (a.data ?? []).map((c) => ({
|
|
1426
|
+
excerpt: De(
|
|
1427
|
+
[c.excerpt, c.subtitle, c.meta_description, c.slug].filter(Boolean),
|
|
1428
|
+
i
|
|
1429
|
+
),
|
|
1430
|
+
source: "post",
|
|
1431
|
+
title: c.title,
|
|
1432
|
+
url: `/article/${c.slug}`
|
|
1433
|
+
})), m = (s.data ?? []).map((c) => ({
|
|
1434
|
+
excerpt: De([c.meta_description, c.slug].filter(Boolean), i),
|
|
1435
|
+
source: "page",
|
|
1436
|
+
title: c.title,
|
|
1437
|
+
url: c.slug === "home" ? "/" : `/${c.slug}`
|
|
1438
|
+
})), u = [...l, ...m].map((c) => ({
|
|
1439
|
+
...c,
|
|
1440
|
+
score: Tn(i, [c.title, c.excerpt, c.url])
|
|
1441
|
+
})).filter((c) => c.score > 0).sort((c, d) => d.score - c.score).slice(0, t.limit).map((c) => ({
|
|
1442
|
+
excerpt: c.excerpt,
|
|
1443
|
+
source: c.source,
|
|
1444
|
+
title: c.title,
|
|
1445
|
+
url: c.url
|
|
1446
|
+
}));
|
|
1447
|
+
return {
|
|
1448
|
+
query: t.query,
|
|
1449
|
+
results: u,
|
|
1450
|
+
success: !0
|
|
1451
|
+
};
|
|
1452
|
+
}
|
|
1453
|
+
async function $n(e, n, t = At) {
|
|
1454
|
+
const r = ye.safeParse(e), i = r.success ? r.data.query : "";
|
|
1455
|
+
return Qt(
|
|
1456
|
+
xn(e, n),
|
|
1457
|
+
t,
|
|
1458
|
+
() => ({
|
|
1459
|
+
message: "Documentation search took too long to respond. Please try again or ask a more specific question.",
|
|
1460
|
+
query: i,
|
|
1461
|
+
results: [],
|
|
1462
|
+
success: !1,
|
|
1463
|
+
timedOut: !0
|
|
1464
|
+
})
|
|
1465
|
+
);
|
|
1466
|
+
}
|
|
1467
|
+
const vn = [
|
|
1468
|
+
"pending",
|
|
1469
|
+
"trial",
|
|
1470
|
+
"paid",
|
|
1471
|
+
"shipped",
|
|
1472
|
+
"cancelled",
|
|
1473
|
+
"refunded",
|
|
1474
|
+
"failed"
|
|
1475
|
+
], Sn = {
|
|
1476
|
+
awaiting: "pending",
|
|
1477
|
+
canceled: "cancelled",
|
|
1478
|
+
cancelled: "cancelled",
|
|
1479
|
+
complete: "paid",
|
|
1480
|
+
completed: "paid",
|
|
1481
|
+
failed: "failed",
|
|
1482
|
+
paid: "paid",
|
|
1483
|
+
payment_pending: "pending",
|
|
1484
|
+
pending: "pending",
|
|
1485
|
+
refund: "refunded",
|
|
1486
|
+
refunded: "refunded",
|
|
1487
|
+
refunds: "refunded",
|
|
1488
|
+
shipped: "shipped",
|
|
1489
|
+
trial: "trial",
|
|
1490
|
+
trials: "trial"
|
|
1491
|
+
};
|
|
1492
|
+
function En(e) {
|
|
1493
|
+
return String(e ?? "unknown").trim().toLowerCase() || "unknown";
|
|
1494
|
+
}
|
|
1495
|
+
function Me(e) {
|
|
1496
|
+
const n = Object.fromEntries(
|
|
1497
|
+
vn.map((t) => [t, 0])
|
|
1498
|
+
);
|
|
1499
|
+
for (const t of e) {
|
|
1500
|
+
const r = En(t.status);
|
|
1501
|
+
n[r] = (n[r] ?? 0) + 1;
|
|
1502
|
+
}
|
|
1503
|
+
return n;
|
|
1504
|
+
}
|
|
1505
|
+
function An(e) {
|
|
1506
|
+
const t = e.toLowerCase().replace(/[^a-z0-9_]+/g, " ").split(/\s+/).filter(Boolean);
|
|
1507
|
+
for (const r of t) {
|
|
1508
|
+
const i = Sn[r];
|
|
1509
|
+
if (i)
|
|
1510
|
+
return i;
|
|
1511
|
+
}
|
|
1512
|
+
return null;
|
|
1513
|
+
}
|
|
1514
|
+
function L(e) {
|
|
1515
|
+
const n = Number(e);
|
|
1516
|
+
return Number.isFinite(n) ? n : 0;
|
|
1517
|
+
}
|
|
1518
|
+
async function Pn(e, n) {
|
|
1519
|
+
const t = ze.parse(e), r = h(n), i = /* @__PURE__ */ new Date();
|
|
1520
|
+
let a = null, s = null;
|
|
1521
|
+
switch (t.timeRange) {
|
|
1522
|
+
case "today":
|
|
1523
|
+
a = new Date(i.getFullYear(), i.getMonth(), i.getDate());
|
|
1524
|
+
break;
|
|
1525
|
+
case "this_month":
|
|
1526
|
+
a = new Date(i.getFullYear(), i.getMonth(), 1);
|
|
1527
|
+
break;
|
|
1528
|
+
case "last_7_days":
|
|
1529
|
+
a = new Date(i.getTime() - 10080 * 60 * 1e3);
|
|
1530
|
+
break;
|
|
1531
|
+
case "last_30_days":
|
|
1532
|
+
a = new Date(i.getTime() - 720 * 60 * 60 * 1e3);
|
|
1533
|
+
break;
|
|
1534
|
+
case "last_month":
|
|
1535
|
+
a = new Date(i.getFullYear(), i.getMonth() - 1, 1), s = new Date(i.getFullYear(), i.getMonth(), 0, 23, 59, 59, 999);
|
|
1536
|
+
break;
|
|
1537
|
+
case "last_90_days":
|
|
1538
|
+
a = new Date(i.getTime() - 2160 * 60 * 60 * 1e3);
|
|
1539
|
+
break;
|
|
1540
|
+
case "all_time":
|
|
1541
|
+
a = null;
|
|
1542
|
+
break;
|
|
1543
|
+
}
|
|
1544
|
+
const l = t.currency?.toUpperCase(), m = An(t.query), u = r.from("orders").select("id, status, total, currency, created_at, paid_at");
|
|
1545
|
+
l && u.eq("currency", l), a && u.gte("created_at", a.toISOString()), s && u.lte("created_at", s.toISOString());
|
|
1546
|
+
const d = t.reportType === "products" || t.reportType === "revenue" || t.reportType === "general" ? r.from("order_items").select(`
|
|
1547
|
+
quantity,
|
|
1548
|
+
price_at_purchase,
|
|
1549
|
+
products!inner (
|
|
1550
|
+
id,
|
|
1551
|
+
title,
|
|
1552
|
+
product_type
|
|
1553
|
+
),
|
|
1554
|
+
orders!inner (
|
|
1555
|
+
id,
|
|
1556
|
+
status,
|
|
1557
|
+
paid_at,
|
|
1558
|
+
currency
|
|
1559
|
+
)
|
|
1560
|
+
`).eq("orders.status", "paid") : null;
|
|
1561
|
+
d && (l && d.eq("orders.currency", l), a && d.gte("orders.paid_at", a.toISOString()), s && d.lte("orders.paid_at", s.toISOString()));
|
|
1562
|
+
const p = t.timeRange !== "all_time" && (t.reportType === "orders" || m) ? r.from("orders").select("id, status, currency") : null;
|
|
1563
|
+
p && l && p.eq("currency", l);
|
|
1564
|
+
const [
|
|
1565
|
+
{ data: _, error: k },
|
|
1566
|
+
{ data: E, error: S },
|
|
1567
|
+
A
|
|
1568
|
+
] = await Promise.all([
|
|
1569
|
+
u,
|
|
1570
|
+
d ?? Promise.resolve({ data: [], error: null }),
|
|
1571
|
+
p ?? Promise.resolve({ data: null, error: null })
|
|
1572
|
+
]);
|
|
1573
|
+
if (k)
|
|
1574
|
+
throw new Error(`Failed to fetch ecommerce stats: ${f(k)}`);
|
|
1575
|
+
if (S)
|
|
1576
|
+
throw new Error(`Failed to fetch ecommerce stats: ${f(S)}`);
|
|
1577
|
+
if (A.error)
|
|
1578
|
+
throw new Error(`Failed to fetch ecommerce stats: ${f(A.error)}`);
|
|
1579
|
+
const y = Array.isArray(_) ? _ : [], I = Array.isArray(E) ? E : [], P = Me(y), $ = Array.isArray(A.data) ? A.data : null, D = $ ? Me($) : null, z = {};
|
|
1580
|
+
for (const C of I) {
|
|
1581
|
+
const T = Array.isArray(C.orders) ? C.orders[0] : C.orders, B = String(T?.currency || l || "unknown").toUpperCase();
|
|
1582
|
+
z[B] = (z[B] ?? 0) + L(C.quantity) * L(C.price_at_purchase) / 100;
|
|
1583
|
+
}
|
|
1584
|
+
const K = {
|
|
1585
|
+
currency: l ?? null,
|
|
1586
|
+
currencyFiltered: !!l,
|
|
1587
|
+
orderStatusCounts: P,
|
|
1588
|
+
paidOrderCount: P.paid ?? 0,
|
|
1589
|
+
query: t.query,
|
|
1590
|
+
reportType: t.reportType,
|
|
1591
|
+
revenueByCurrency: z,
|
|
1592
|
+
timeRange: t.timeRange,
|
|
1593
|
+
totalOrders: y.length,
|
|
1594
|
+
totalRevenue: Object.values(z).reduce(
|
|
1595
|
+
(C, T) => C + T,
|
|
1596
|
+
0
|
|
1597
|
+
)
|
|
1598
|
+
};
|
|
1599
|
+
if (D && (K.allTimeOrderStatusCounts = D), m && (K.matchingOrderStatus = {
|
|
1600
|
+
allTimeCount: D?.[m] ?? P[m] ?? 0,
|
|
1601
|
+
count: P[m] ?? 0,
|
|
1602
|
+
status: m,
|
|
1603
|
+
timeRange: t.timeRange
|
|
1604
|
+
}), t.reportType === "products" || t.reportType === "revenue" || t.reportType === "general") {
|
|
1605
|
+
const C = {};
|
|
1606
|
+
for (const T of I) {
|
|
1607
|
+
const B = Array.isArray(T.products) ? T.products[0] : T.products;
|
|
1608
|
+
if (!B?.id)
|
|
1609
|
+
continue;
|
|
1610
|
+
const M = B.id;
|
|
1611
|
+
C[M] || (C[M] = {
|
|
1612
|
+
id: M,
|
|
1613
|
+
quantity: 0,
|
|
1614
|
+
revenue: 0,
|
|
1615
|
+
title: B.title,
|
|
1616
|
+
type: B.product_type
|
|
1617
|
+
}), C[M].quantity += L(T.quantity), C[M].revenue += L(T.quantity) * L(T.price_at_purchase) / 100;
|
|
1618
|
+
}
|
|
1619
|
+
K.topProducts = Object.values(C).sort((T, B) => B.revenue - T.revenue).slice(0, 10);
|
|
1620
|
+
}
|
|
1621
|
+
return {
|
|
1622
|
+
report: K,
|
|
1623
|
+
success: !0
|
|
1624
|
+
};
|
|
1625
|
+
}
|
|
1626
|
+
async function Bn(e, n) {
|
|
1627
|
+
const t = Ve.parse(e), r = h(n), i = pe(n), a = we(i), s = i.contentType === "page" ? "pages" : i.contentType === "post" ? "posts" : "products", { data: l, error: m } = await r.from(s).select("*").eq("id", a).single();
|
|
1628
|
+
if (m || !l)
|
|
1629
|
+
throw new Error(
|
|
1630
|
+
`Failed to read current ${i.contentType}: ${f(m)}`
|
|
1631
|
+
);
|
|
1632
|
+
let u = [];
|
|
1633
|
+
if (t.includeBlocks && i.contentType !== "product") {
|
|
1634
|
+
const c = i.contentType === "page" ? "page_id" : "post_id", { data: d, error: g } = await r.from("blocks").select("id, page_id, post_id, language_id, block_type, content, order").eq(c, a);
|
|
1635
|
+
if (g)
|
|
1636
|
+
throw new Error(`Failed to read current ${i.contentType} blocks: ${f(g)}`);
|
|
1637
|
+
u = (Array.isArray(d) ? d : []).slice().sort((p, _) => Number(p.order) - Number(_.order)).map((p) => pn(p, t.includeBlockContent));
|
|
1638
|
+
}
|
|
1639
|
+
return {
|
|
1640
|
+
blocks: u,
|
|
1641
|
+
context: i,
|
|
1642
|
+
item: l,
|
|
1643
|
+
success: !0
|
|
1644
|
+
};
|
|
1645
|
+
}
|
|
1646
|
+
const mt = /* @__PURE__ */ new Set([
|
|
1647
|
+
"feature_image_id",
|
|
1648
|
+
"language_id",
|
|
1649
|
+
"meta_description",
|
|
1650
|
+
"meta_title",
|
|
1651
|
+
"slug",
|
|
1652
|
+
"status",
|
|
1653
|
+
"title"
|
|
1654
|
+
]), gt = /* @__PURE__ */ new Set([
|
|
1655
|
+
"excerpt",
|
|
1656
|
+
"feature_image_id",
|
|
1657
|
+
"label",
|
|
1658
|
+
"language_id",
|
|
1659
|
+
"meta_description",
|
|
1660
|
+
"meta_title",
|
|
1661
|
+
"published_at",
|
|
1662
|
+
"slug",
|
|
1663
|
+
"status",
|
|
1664
|
+
"subtitle",
|
|
1665
|
+
"title"
|
|
1666
|
+
]), Fn = /* @__PURE__ */ new Set([
|
|
1667
|
+
"description_json",
|
|
1668
|
+
"language_id",
|
|
1669
|
+
"meta_description",
|
|
1670
|
+
"meta_title",
|
|
1671
|
+
"short_description",
|
|
1672
|
+
"slug",
|
|
1673
|
+
"status",
|
|
1674
|
+
"title"
|
|
1675
|
+
]), Nn = /* @__PURE__ */ new Set([
|
|
1676
|
+
"excerpt",
|
|
1677
|
+
"feature_image_id",
|
|
1678
|
+
"label",
|
|
1679
|
+
"meta_description",
|
|
1680
|
+
"meta_title",
|
|
1681
|
+
"published_at",
|
|
1682
|
+
"short_description",
|
|
1683
|
+
"subtitle"
|
|
1684
|
+
]);
|
|
1685
|
+
function jn(e) {
|
|
1686
|
+
return e === "page" ? mt : e === "post" ? gt : Fn;
|
|
1687
|
+
}
|
|
1688
|
+
function ft(e, n) {
|
|
1689
|
+
return Nn.has(e) && n === "" ? null : n;
|
|
1690
|
+
}
|
|
1691
|
+
function be(e, n) {
|
|
1692
|
+
if (typeof n != "string")
|
|
1693
|
+
return;
|
|
1694
|
+
const t = e === "product" ? ["active", "archived", "draft"] : ["archived", "draft", "published"];
|
|
1695
|
+
if (!t.includes(n))
|
|
1696
|
+
throw new Error(
|
|
1697
|
+
`Status "${n}" is not valid for ${e}. Allowed statuses: ${t.join(", ")}.`
|
|
1698
|
+
);
|
|
1699
|
+
}
|
|
1700
|
+
function qn(e, n) {
|
|
1701
|
+
const t = jn(n.contentType), r = {};
|
|
1702
|
+
for (const [i, a] of Object.entries(e))
|
|
1703
|
+
if (a !== void 0) {
|
|
1704
|
+
if (!t.has(i))
|
|
1705
|
+
throw new Error(
|
|
1706
|
+
`Field "${i}" cannot be updated for ${n.contentType} content.`
|
|
1707
|
+
);
|
|
1708
|
+
i === "status" && be(n.contentType, a), r[i] = ft(i, a);
|
|
1709
|
+
}
|
|
1710
|
+
return r;
|
|
1711
|
+
}
|
|
1712
|
+
async function _t(e, n) {
|
|
1713
|
+
const t = ne.parse(e), r = h(n), i = pe(n), a = we(i), s = qn(t.fields, i), l = Object.keys(s);
|
|
1714
|
+
if (l.length === 0)
|
|
1715
|
+
throw new Error("update_current_cms_fields requires at least one supported field.");
|
|
1716
|
+
const m = x({
|
|
1717
|
+
action: "UPDATE CMS FIELDS",
|
|
1718
|
+
context: n,
|
|
1719
|
+
payload: {
|
|
1720
|
+
contentType: i.contentType,
|
|
1721
|
+
entityId: a,
|
|
1722
|
+
fields: s,
|
|
1723
|
+
tool: "update_current_cms_fields"
|
|
1724
|
+
},
|
|
1725
|
+
preview: {
|
|
1726
|
+
contentType: i.contentType,
|
|
1727
|
+
entityId: a,
|
|
1728
|
+
fields: l,
|
|
1729
|
+
slug: i.slug,
|
|
1730
|
+
title: i.title
|
|
1731
|
+
},
|
|
1732
|
+
subject: `${i.contentType} ${String(a)}`
|
|
1733
|
+
});
|
|
1734
|
+
if (m)
|
|
1735
|
+
return m;
|
|
1736
|
+
const u = i.contentType === "page" ? "pages" : i.contentType === "post" ? "posts" : "products", { data: c, error: d } = await r.from(u).update({
|
|
1737
|
+
...s,
|
|
1738
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1739
|
+
}).eq("id", a).select("id, language_id, slug, status, title").single();
|
|
1740
|
+
if (d || !c)
|
|
1741
|
+
throw new Error(
|
|
1742
|
+
`Failed to update current ${i.contentType}: ${f(d)}`
|
|
1743
|
+
);
|
|
1744
|
+
return F(n, i, c.slug), {
|
|
1745
|
+
contentType: i.contentType,
|
|
1746
|
+
entityId: a,
|
|
1747
|
+
mutationExecuted: !0,
|
|
1748
|
+
slug: c.slug,
|
|
1749
|
+
success: !0,
|
|
1750
|
+
updatedFields: l
|
|
1751
|
+
};
|
|
1752
|
+
}
|
|
1753
|
+
async function bt(e, n) {
|
|
1754
|
+
const t = oe.parse(e), r = h(n), i = pe(n), { data: a, error: s } = await r.from("blocks").select("id, page_id, post_id, language_id, block_type, content, order").eq("id", t.blockId).single();
|
|
1755
|
+
if (s || !a)
|
|
1756
|
+
throw new Error(`Failed to read block ${t.blockId}: ${f(s)}`);
|
|
1757
|
+
et(a, i);
|
|
1758
|
+
const l = Y(a.block_type, `Block ${t.blockId}`);
|
|
1759
|
+
tt(t.blockType, l, `Block ${t.blockId}`);
|
|
1760
|
+
const m = G(a.content, `Block ${t.blockId}`), u = dn(
|
|
1761
|
+
l,
|
|
1762
|
+
m,
|
|
1763
|
+
t.content,
|
|
1764
|
+
n
|
|
1765
|
+
);
|
|
1766
|
+
j(l, u, `Block ${t.blockId}`, n);
|
|
1767
|
+
const c = x({
|
|
1768
|
+
action: "UPDATE CONTENT BLOCK",
|
|
1769
|
+
context: n,
|
|
1770
|
+
payload: {
|
|
1771
|
+
blockId: t.blockId,
|
|
1772
|
+
blockType: l,
|
|
1773
|
+
content: u,
|
|
1774
|
+
tool: "update_content_block"
|
|
1775
|
+
},
|
|
1776
|
+
preview: {
|
|
1777
|
+
blockId: t.blockId,
|
|
1778
|
+
blockType: l,
|
|
1779
|
+
contentType: i.contentType,
|
|
1780
|
+
entityId: we(i)
|
|
1781
|
+
},
|
|
1782
|
+
subject: `${l} block ${t.blockId}`
|
|
1783
|
+
});
|
|
1784
|
+
if (c)
|
|
1785
|
+
return c;
|
|
1786
|
+
const { data: d, error: g } = await r.from("blocks").update({
|
|
1787
|
+
content: u,
|
|
1788
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1789
|
+
}).eq("id", t.blockId).select("id, block_type, order").single();
|
|
1790
|
+
if (g || !d)
|
|
1791
|
+
throw new Error(`Failed to update block ${t.blockId}: ${f(g)}`);
|
|
1792
|
+
return F(n, i), {
|
|
1793
|
+
blockId: d.id,
|
|
1794
|
+
blockType: d.block_type,
|
|
1795
|
+
contentUpdated: !0,
|
|
1796
|
+
mutationExecuted: !0,
|
|
1797
|
+
success: !0
|
|
1798
|
+
};
|
|
1799
|
+
}
|
|
1800
|
+
async function yt(e, n) {
|
|
1801
|
+
const t = ae.parse(e), r = h(n), i = await ve(t, n);
|
|
1802
|
+
if (i.contentType === "product")
|
|
1803
|
+
throw new Error("Products do not have page/post content blocks in this editor context.");
|
|
1804
|
+
const a = Number(i.item.id), s = i.contentType === "page" ? "page_id" : "post_id", l = async () => {
|
|
1805
|
+
const { data: y, error: I } = await r.from("blocks").select("id, page_id, post_id, language_id, block_type, content, order").eq(s, a);
|
|
1806
|
+
if (I)
|
|
1807
|
+
throw new Error(`Failed to read ${i.contentType} blocks: ${f(I)}`);
|
|
1808
|
+
return (Array.isArray(y) ? y : []).sort(
|
|
1809
|
+
(P, $) => Number(P.order) - Number($.order)
|
|
1810
|
+
);
|
|
1811
|
+
}, m = (y) => {
|
|
1812
|
+
if (t.position === "start")
|
|
1813
|
+
return 0;
|
|
1814
|
+
if (t.position === "end") {
|
|
1815
|
+
const $ = y.map((D) => Number(D.order)).filter(Number.isFinite);
|
|
1816
|
+
return $.length > 0 ? Math.max(...$) + 1 : 0;
|
|
1817
|
+
}
|
|
1818
|
+
const I = t.anchorBlockId ? y.find(($) => Number($.id) === t.anchorBlockId) : t.anchorBlockType ? y.find(($) => $.block_type === t.anchorBlockType) : null;
|
|
1819
|
+
if (!I)
|
|
1820
|
+
throw new Error(
|
|
1821
|
+
t.anchorBlockType ? `Could not find a ${t.anchorBlockType} block to insert ${t.position}.` : `Could not find block ${t.anchorBlockId} to insert ${t.position}.`
|
|
1822
|
+
);
|
|
1823
|
+
const P = Number(I.order);
|
|
1824
|
+
return t.position === "before" ? P : P + 1;
|
|
1825
|
+
}, u = Z(t.block, 0, n), c = await l(), d = m(c), g = {
|
|
1826
|
+
contentType: i.contentType,
|
|
1827
|
+
entityId: i.item.id,
|
|
1828
|
+
languageId: i.item.language_id,
|
|
1829
|
+
slug: i.item.slug,
|
|
1830
|
+
title: i.item.title,
|
|
1831
|
+
translationGroupId: i.item.translation_group_id
|
|
1832
|
+
}, p = x({
|
|
1833
|
+
action: "INSERT CONTENT BLOCK",
|
|
1834
|
+
context: n,
|
|
1835
|
+
payload: {
|
|
1836
|
+
block: u,
|
|
1837
|
+
order: d,
|
|
1838
|
+
target: {
|
|
1839
|
+
contentType: i.contentType,
|
|
1840
|
+
id: i.item.id,
|
|
1841
|
+
slug: i.item.slug
|
|
1842
|
+
},
|
|
1843
|
+
tool: "insert_content_block"
|
|
1844
|
+
},
|
|
1845
|
+
preview: {
|
|
1846
|
+
anchorBlockId: t.anchorBlockId,
|
|
1847
|
+
anchorBlockType: t.anchorBlockType,
|
|
1848
|
+
blockType: u.block_type,
|
|
1849
|
+
contentType: i.contentType,
|
|
1850
|
+
entityId: i.item.id,
|
|
1851
|
+
position: t.position,
|
|
1852
|
+
slug: i.item.slug,
|
|
1853
|
+
summary: `Insert ${u.block_type} block ${t.position} ${t.anchorBlockType ? `the first ${t.anchorBlockType} block` : t.anchorBlockId ? `block ${t.anchorBlockId}` : "the content"} on ${i.contentType} "${i.item.title || i.item.slug}".`,
|
|
1854
|
+
title: i.item.title
|
|
1855
|
+
},
|
|
1856
|
+
subject: `${u.block_type} block on ${i.contentType} ${i.item.id}`
|
|
1857
|
+
});
|
|
1858
|
+
if (p)
|
|
1859
|
+
return p;
|
|
1860
|
+
const _ = await l(), k = m(_), E = _.filter((y) => Number(y.order) >= k).sort((y, I) => Number(I.order) - Number(y.order));
|
|
1861
|
+
for (const y of E) {
|
|
1862
|
+
const { error: I } = await r.from("blocks").update({
|
|
1863
|
+
order: Number(y.order) + 1,
|
|
1864
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1865
|
+
}).eq("id", y.id);
|
|
1866
|
+
if (I)
|
|
1867
|
+
throw new Error(`Failed to shift block ${y.id}: ${f(I)}`);
|
|
1868
|
+
}
|
|
1869
|
+
const { data: S, error: A } = await r.from("blocks").insert({
|
|
1870
|
+
block_type: u.block_type,
|
|
1871
|
+
content: u.content,
|
|
1872
|
+
language_id: i.item.language_id,
|
|
1873
|
+
order: k,
|
|
1874
|
+
page_id: i.contentType === "page" ? a : null,
|
|
1875
|
+
post_id: i.contentType === "post" ? a : null
|
|
1876
|
+
}).select("id, block_type, order").single();
|
|
1877
|
+
if (A || !S)
|
|
1878
|
+
throw new Error(`Failed to insert content block: ${f(A)}`);
|
|
1879
|
+
return F(n, g), {
|
|
1880
|
+
blockId: S.id,
|
|
1881
|
+
blockType: S.block_type,
|
|
1882
|
+
contentType: i.contentType,
|
|
1883
|
+
entityId: i.item.id,
|
|
1884
|
+
mutationExecuted: !0,
|
|
1885
|
+
order: S.order,
|
|
1886
|
+
success: !0
|
|
1887
|
+
};
|
|
1888
|
+
}
|
|
1889
|
+
async function ht(e, n) {
|
|
1890
|
+
const t = re.parse(e), r = h(n), i = pe(n), { data: a, error: s } = await r.from("blocks").select("id, page_id, post_id, language_id, block_type, content, order").eq("id", t.parentBlockId).single();
|
|
1891
|
+
if (s || !a)
|
|
1892
|
+
throw new Error(
|
|
1893
|
+
`Failed to read parent block ${t.parentBlockId}: ${f(s)}`
|
|
1894
|
+
);
|
|
1895
|
+
et(a, i);
|
|
1896
|
+
const l = Y(
|
|
1897
|
+
a.block_type,
|
|
1898
|
+
`Parent block ${t.parentBlockId}`
|
|
1899
|
+
);
|
|
1900
|
+
if (l !== "section")
|
|
1901
|
+
throw new Error(
|
|
1902
|
+
`Parent block ${t.parentBlockId} must be a section block, not "${l}".`
|
|
1903
|
+
);
|
|
1904
|
+
const m = G(
|
|
1905
|
+
a.content,
|
|
1906
|
+
`Parent block ${t.parentBlockId}`
|
|
1907
|
+
);
|
|
1908
|
+
j(
|
|
1909
|
+
l,
|
|
1910
|
+
m,
|
|
1911
|
+
`Parent block ${t.parentBlockId}`,
|
|
1912
|
+
n
|
|
1913
|
+
);
|
|
1914
|
+
const c = m.column_blocks?.[t.columnIndex]?.[t.blockIndex];
|
|
1915
|
+
if (!c)
|
|
1916
|
+
throw new Error(
|
|
1917
|
+
`Nested block was not found at column ${t.columnIndex}, index ${t.blockIndex}.`
|
|
1918
|
+
);
|
|
1919
|
+
const d = Y(
|
|
1920
|
+
c.block_type,
|
|
1921
|
+
`Nested block ${t.columnIndex}:${t.blockIndex}`
|
|
1922
|
+
);
|
|
1923
|
+
tt(
|
|
1924
|
+
t.blockType,
|
|
1925
|
+
d,
|
|
1926
|
+
`Nested block ${t.columnIndex}:${t.blockIndex}`
|
|
1927
|
+
), j(
|
|
1928
|
+
d,
|
|
1929
|
+
t.content,
|
|
1930
|
+
`Nested block ${t.columnIndex}:${t.blockIndex}`,
|
|
1931
|
+
n
|
|
1932
|
+
);
|
|
1933
|
+
const g = m.column_blocks.map(
|
|
1934
|
+
(S, A) => A === t.columnIndex ? S.map(
|
|
1935
|
+
(y, I) => I === t.blockIndex ? {
|
|
1936
|
+
...y,
|
|
1937
|
+
content: t.content
|
|
1938
|
+
} : y
|
|
1939
|
+
) : S
|
|
1940
|
+
), p = {
|
|
1941
|
+
...m,
|
|
1942
|
+
column_blocks: g
|
|
1943
|
+
};
|
|
1944
|
+
j(
|
|
1945
|
+
l,
|
|
1946
|
+
p,
|
|
1947
|
+
`Updated parent block ${t.parentBlockId}`,
|
|
1948
|
+
n
|
|
1949
|
+
);
|
|
1950
|
+
const _ = x({
|
|
1951
|
+
action: "UPDATE NESTED BLOCK",
|
|
1952
|
+
context: n,
|
|
1953
|
+
payload: {
|
|
1954
|
+
blockIndex: t.blockIndex,
|
|
1955
|
+
columnIndex: t.columnIndex,
|
|
1956
|
+
content: t.content,
|
|
1957
|
+
nestedBlockType: d,
|
|
1958
|
+
parentBlockId: t.parentBlockId,
|
|
1959
|
+
tool: "update_section_column_block"
|
|
1960
|
+
},
|
|
1961
|
+
preview: {
|
|
1962
|
+
blockIndex: t.blockIndex,
|
|
1963
|
+
columnIndex: t.columnIndex,
|
|
1964
|
+
nestedBlockType: d,
|
|
1965
|
+
parentBlockId: t.parentBlockId,
|
|
1966
|
+
parentBlockType: l
|
|
1967
|
+
},
|
|
1968
|
+
subject: `${d} nested block ${t.columnIndex}:${t.blockIndex}`
|
|
1969
|
+
});
|
|
1970
|
+
if (_)
|
|
1971
|
+
return _;
|
|
1972
|
+
const { data: k, error: E } = await r.from("blocks").update({
|
|
1973
|
+
content: p,
|
|
1974
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1975
|
+
}).eq("id", t.parentBlockId).select("id, block_type").single();
|
|
1976
|
+
if (E || !k)
|
|
1977
|
+
throw new Error(
|
|
1978
|
+
`Failed to update parent block ${t.parentBlockId}: ${f(E)}`
|
|
1979
|
+
);
|
|
1980
|
+
return F(n, i), {
|
|
1981
|
+
blockIndex: t.blockIndex,
|
|
1982
|
+
columnIndex: t.columnIndex,
|
|
1983
|
+
mutationExecuted: !0,
|
|
1984
|
+
nestedBlockType: d,
|
|
1985
|
+
parentBlockId: k.id,
|
|
1986
|
+
parentBlockType: k.block_type,
|
|
1987
|
+
success: !0
|
|
1988
|
+
};
|
|
1989
|
+
}
|
|
1990
|
+
async function kt(e, n) {
|
|
1991
|
+
const t = se.parse(e), r = h(n), i = Ze(n), a = await $e(r, t.languageCode), s = me(t.slug || t.title), l = st(t.blocks, t.contactEmail, t.title, n), m = await Se({
|
|
1992
|
+
contentType: "page",
|
|
1993
|
+
languageId: a.id,
|
|
1994
|
+
slug: s,
|
|
1995
|
+
supabase: r
|
|
1996
|
+
});
|
|
1997
|
+
if (m)
|
|
1998
|
+
return m;
|
|
1999
|
+
const u = await Ee({
|
|
2000
|
+
contentType: "page",
|
|
2001
|
+
languageCode: a.code,
|
|
2002
|
+
languageId: a.id,
|
|
2003
|
+
suppliedTranslationGroupId: t.translationGroupId,
|
|
2004
|
+
supabase: r
|
|
2005
|
+
});
|
|
2006
|
+
if (u.result)
|
|
2007
|
+
return u.result;
|
|
2008
|
+
const c = {
|
|
2009
|
+
blocks: l,
|
|
2010
|
+
item: {
|
|
2011
|
+
feature_image_id: t.feature_image_id ?? null,
|
|
2012
|
+
language_id: a.id,
|
|
2013
|
+
meta_description: t.meta_description ?? null,
|
|
2014
|
+
meta_title: t.meta_title ?? null,
|
|
2015
|
+
slug: s,
|
|
2016
|
+
status: t.status,
|
|
2017
|
+
title: t.title,
|
|
2018
|
+
translation_group_id: u.translationGroupId
|
|
2019
|
+
},
|
|
2020
|
+
tool: "create_cms_page"
|
|
2021
|
+
}, d = x({
|
|
2022
|
+
action: "CREATE PAGE",
|
|
2023
|
+
context: n,
|
|
2024
|
+
payload: c,
|
|
2025
|
+
preview: {
|
|
2026
|
+
blockCount: l.length,
|
|
2027
|
+
languageCode: a.code,
|
|
2028
|
+
slug: s,
|
|
2029
|
+
status: t.status,
|
|
2030
|
+
title: t.title,
|
|
2031
|
+
translationGroupId: u.translationGroupId
|
|
2032
|
+
},
|
|
2033
|
+
subject: s
|
|
2034
|
+
});
|
|
2035
|
+
if (d)
|
|
2036
|
+
return d;
|
|
2037
|
+
const g = u.translationGroupId || Ce(), { data: p, error: _ } = await r.from("pages").insert({
|
|
2038
|
+
...c.item,
|
|
2039
|
+
author_id: i,
|
|
2040
|
+
translation_group_id: g
|
|
2041
|
+
}).select("id, language_id, slug, status, title, translation_group_id").single();
|
|
2042
|
+
if (_ || !p?.id)
|
|
2043
|
+
throw new Error(`Failed to create page: ${f(_)}`);
|
|
2044
|
+
try {
|
|
2045
|
+
await lt({
|
|
2046
|
+
blocks: l,
|
|
2047
|
+
contentType: "page",
|
|
2048
|
+
itemId: Number(p.id),
|
|
2049
|
+
languageId: a.id,
|
|
2050
|
+
supabase: r
|
|
2051
|
+
});
|
|
2052
|
+
} catch (k) {
|
|
2053
|
+
throw await ct({ contentType: "page", itemId: Number(p.id), supabase: r }), k;
|
|
2054
|
+
}
|
|
2055
|
+
return F(
|
|
2056
|
+
n,
|
|
2057
|
+
{ contentType: "page", entityId: Number(p.id), languageId: a.id, slug: s, title: t.title },
|
|
2058
|
+
s
|
|
2059
|
+
), n?.revalidatePath?.("/cms/pages"), {
|
|
2060
|
+
blockCount: l.length,
|
|
2061
|
+
contentType: "page",
|
|
2062
|
+
editPath: Ae("page", p.id),
|
|
2063
|
+
entityId: p.id,
|
|
2064
|
+
mutationExecuted: !0,
|
|
2065
|
+
slug: s,
|
|
2066
|
+
success: !0,
|
|
2067
|
+
title: t.title,
|
|
2068
|
+
translationGroupId: p.translation_group_id
|
|
2069
|
+
};
|
|
2070
|
+
}
|
|
2071
|
+
async function wt(e, n) {
|
|
2072
|
+
const t = le.parse(e), r = h(n), i = Ze(n), a = await $e(r, t.languageCode), s = me(t.slug || t.title), l = st(t.blocks, void 0, void 0, n), m = await Se({
|
|
2073
|
+
contentType: "post",
|
|
2074
|
+
languageId: a.id,
|
|
2075
|
+
slug: s,
|
|
2076
|
+
supabase: r
|
|
2077
|
+
});
|
|
2078
|
+
if (m)
|
|
2079
|
+
return m;
|
|
2080
|
+
const u = await Ee({
|
|
2081
|
+
contentType: "post",
|
|
2082
|
+
languageCode: a.code,
|
|
2083
|
+
languageId: a.id,
|
|
2084
|
+
suppliedTranslationGroupId: t.translationGroupId,
|
|
2085
|
+
supabase: r
|
|
2086
|
+
});
|
|
2087
|
+
if (u.result)
|
|
2088
|
+
return u.result;
|
|
2089
|
+
const c = t.published_at && !Number.isNaN(new Date(t.published_at).getTime()) ? new Date(t.published_at).toISOString() : t.published_at ?? null, d = {
|
|
2090
|
+
blocks: l,
|
|
2091
|
+
item: {
|
|
2092
|
+
excerpt: t.excerpt ?? null,
|
|
2093
|
+
feature_image_id: t.feature_image_id ?? null,
|
|
2094
|
+
label: t.label ?? null,
|
|
2095
|
+
language_id: a.id,
|
|
2096
|
+
meta_description: t.meta_description ?? null,
|
|
2097
|
+
meta_title: t.meta_title ?? null,
|
|
2098
|
+
published_at: c,
|
|
2099
|
+
slug: s,
|
|
2100
|
+
status: t.status,
|
|
2101
|
+
subtitle: t.subtitle ?? null,
|
|
2102
|
+
title: t.title,
|
|
2103
|
+
translation_group_id: u.translationGroupId
|
|
2104
|
+
},
|
|
2105
|
+
tool: "create_cms_post"
|
|
2106
|
+
}, g = x({
|
|
2107
|
+
action: "CREATE POST",
|
|
2108
|
+
context: n,
|
|
2109
|
+
payload: d,
|
|
2110
|
+
preview: {
|
|
2111
|
+
blockCount: l.length,
|
|
2112
|
+
languageCode: a.code,
|
|
2113
|
+
slug: s,
|
|
2114
|
+
status: t.status,
|
|
2115
|
+
title: t.title,
|
|
2116
|
+
translationGroupId: u.translationGroupId
|
|
2117
|
+
},
|
|
2118
|
+
subject: s
|
|
2119
|
+
});
|
|
2120
|
+
if (g)
|
|
2121
|
+
return g;
|
|
2122
|
+
const p = u.translationGroupId || Ce(), { data: _, error: k } = await r.from("posts").insert({
|
|
2123
|
+
...d.item,
|
|
2124
|
+
author_id: i,
|
|
2125
|
+
translation_group_id: p
|
|
2126
|
+
}).select("id, language_id, slug, status, title, translation_group_id").single();
|
|
2127
|
+
if (k || !_?.id)
|
|
2128
|
+
throw new Error(`Failed to create post: ${f(k)}`);
|
|
2129
|
+
try {
|
|
2130
|
+
await lt({
|
|
2131
|
+
blocks: l,
|
|
2132
|
+
contentType: "post",
|
|
2133
|
+
itemId: Number(_.id),
|
|
2134
|
+
languageId: a.id,
|
|
2135
|
+
supabase: r
|
|
2136
|
+
});
|
|
2137
|
+
} catch (E) {
|
|
2138
|
+
throw await ct({ contentType: "post", itemId: Number(_.id), supabase: r }), E;
|
|
2139
|
+
}
|
|
2140
|
+
return F(
|
|
2141
|
+
n,
|
|
2142
|
+
{ contentType: "post", entityId: Number(_.id), languageId: a.id, slug: s, title: t.title },
|
|
2143
|
+
s
|
|
2144
|
+
), n?.revalidatePath?.("/cms/posts"), n?.revalidatePath?.("/articles"), {
|
|
2145
|
+
blockCount: l.length,
|
|
2146
|
+
contentType: "post",
|
|
2147
|
+
editPath: Ae("post", _.id),
|
|
2148
|
+
entityId: _.id,
|
|
2149
|
+
mutationExecuted: !0,
|
|
2150
|
+
slug: s,
|
|
2151
|
+
success: !0,
|
|
2152
|
+
title: t.title,
|
|
2153
|
+
translationGroupId: _.translation_group_id
|
|
2154
|
+
};
|
|
2155
|
+
}
|
|
2156
|
+
function On(e, n) {
|
|
2157
|
+
return (n || me(e) || "product").replace(/-/g, "").slice(0, 24).toUpperCase();
|
|
2158
|
+
}
|
|
2159
|
+
function It(e) {
|
|
2160
|
+
if (e === void 0)
|
|
2161
|
+
return;
|
|
2162
|
+
const n = Yt().safeParse(e);
|
|
2163
|
+
if (!n.success)
|
|
2164
|
+
throw new Error(
|
|
2165
|
+
`Product description_json failed editor document validation: ${n.error.issues.map((t) => t.message).join("; ")}`
|
|
2166
|
+
);
|
|
2167
|
+
return n.data;
|
|
2168
|
+
}
|
|
2169
|
+
async function Ct(e, n) {
|
|
2170
|
+
const t = ce.parse(e), r = h(n), i = await $e(r, t.languageCode), a = me(t.slug || t.title), s = await Se({
|
|
2171
|
+
contentType: "product",
|
|
2172
|
+
languageId: i.id,
|
|
2173
|
+
slug: a,
|
|
2174
|
+
supabase: r
|
|
2175
|
+
});
|
|
2176
|
+
if (s)
|
|
2177
|
+
return s;
|
|
2178
|
+
const l = await Ee({
|
|
2179
|
+
contentType: "product",
|
|
2180
|
+
languageCode: i.code,
|
|
2181
|
+
languageId: i.id,
|
|
2182
|
+
suppliedTranslationGroupId: t.translationGroupId,
|
|
2183
|
+
supabase: r
|
|
2184
|
+
});
|
|
2185
|
+
if (l.result)
|
|
2186
|
+
return l.result;
|
|
2187
|
+
const { createProduct: m, productSchema: u } = await Ie(), d = t.product_type === "digital" && t.payment_provider === "freemius" ? t.trial_period_days : 0, g = u.parse({
|
|
2188
|
+
description_json: It(t.description_json),
|
|
2189
|
+
freemius_plan_id: t.freemius_plan_id || "",
|
|
2190
|
+
freemius_product_id: t.freemius_product_id || "",
|
|
2191
|
+
is_taxable: t.is_taxable,
|
|
2192
|
+
language_id: i.id,
|
|
2193
|
+
meta_description: t.meta_description ?? "",
|
|
2194
|
+
meta_title: t.meta_title ?? "",
|
|
2195
|
+
payment_provider: t.payment_provider,
|
|
2196
|
+
price: t.price,
|
|
2197
|
+
prices: t.prices || {},
|
|
2198
|
+
product_media: [],
|
|
2199
|
+
product_type: t.product_type,
|
|
2200
|
+
sale_price: t.sale_price ?? null,
|
|
2201
|
+
sale_prices: t.sale_prices || {},
|
|
2202
|
+
short_description: t.short_description ?? "",
|
|
2203
|
+
sku: t.sku || On(t.title, a),
|
|
2204
|
+
slug: a,
|
|
2205
|
+
status: t.status,
|
|
2206
|
+
stock: t.stock,
|
|
2207
|
+
title: t.title,
|
|
2208
|
+
trial_period_days: d,
|
|
2209
|
+
trial_requires_payment_method: d > 0 ? t.trial_requires_payment_method : !1,
|
|
2210
|
+
translation_group_id: l.translationGroupId,
|
|
2211
|
+
upc: t.upc ?? "",
|
|
2212
|
+
variation_attributes: [],
|
|
2213
|
+
variants: []
|
|
2214
|
+
}), p = x({
|
|
2215
|
+
action: "CREATE PRODUCT",
|
|
2216
|
+
context: n,
|
|
2217
|
+
payload: { item: g, tool: "create_cms_product" },
|
|
2218
|
+
preview: {
|
|
2219
|
+
languageCode: i.code,
|
|
2220
|
+
price: g.price,
|
|
2221
|
+
sku: g.sku,
|
|
2222
|
+
slug: a,
|
|
2223
|
+
status: g.status,
|
|
2224
|
+
stock: g.stock,
|
|
2225
|
+
title: g.title,
|
|
2226
|
+
translationGroupId: l.translationGroupId
|
|
2227
|
+
},
|
|
2228
|
+
subject: a
|
|
2229
|
+
});
|
|
2230
|
+
if (p)
|
|
2231
|
+
return p;
|
|
2232
|
+
const _ = await m(r, g);
|
|
2233
|
+
if (!_?.id)
|
|
2234
|
+
throw new Error("Failed to create product.");
|
|
2235
|
+
return F(
|
|
2236
|
+
n,
|
|
2237
|
+
{ contentType: "product", entityId: _.id, languageId: i.id, slug: a, title: t.title },
|
|
2238
|
+
a
|
|
2239
|
+
), n?.revalidatePath?.("/cms/products"), {
|
|
2240
|
+
contentType: "product",
|
|
2241
|
+
editPath: Ae("product", _.id),
|
|
2242
|
+
entityId: _.id,
|
|
2243
|
+
mutationExecuted: !0,
|
|
2244
|
+
slug: a,
|
|
2245
|
+
success: !0,
|
|
2246
|
+
title: t.title,
|
|
2247
|
+
translationGroupId: _.translation_group_id
|
|
2248
|
+
};
|
|
2249
|
+
}
|
|
2250
|
+
function Pe(e) {
|
|
2251
|
+
return e.trim().replace(/[\s-]+/g, "_").toLowerCase();
|
|
2252
|
+
}
|
|
2253
|
+
function Un(e, n) {
|
|
2254
|
+
const t = typeof n == "string" ? Pe(n) : n;
|
|
2255
|
+
return e === "product" ? t === "public" || t === "publish" || t === "published" ? "active" : t : t === "public" || t === "active" || t === "publish" ? "published" : t;
|
|
2256
|
+
}
|
|
2257
|
+
function Dn(e) {
|
|
2258
|
+
const n = Pe(e.field);
|
|
2259
|
+
return !!(e.startsAt || e.endsAt || n.includes("start") || n.includes("end") || n.includes("schedule") || n.includes("special_date"));
|
|
2260
|
+
}
|
|
2261
|
+
async function Mn(e, n, t) {
|
|
2262
|
+
const r = await mn(n), { productSchema: i } = await Ie();
|
|
2263
|
+
return i.parse({
|
|
2264
|
+
description_json: t.description_json !== void 0 ? It(t.description_json) : e.description_json || void 0,
|
|
2265
|
+
freemius_plan_id: e.freemius_plan_id || "",
|
|
2266
|
+
freemius_product_id: e.freemius_product_id || "",
|
|
2267
|
+
is_taxable: t.is_taxable ?? e.is_taxable ?? !0,
|
|
2268
|
+
language_id: t.language_id ?? e.language_id,
|
|
2269
|
+
meta_description: t.meta_description ?? e.meta_description ?? "",
|
|
2270
|
+
meta_title: t.meta_title ?? e.meta_title ?? "",
|
|
2271
|
+
payment_provider: t.payment_provider ?? e.payment_provider ?? "stripe",
|
|
2272
|
+
price: t.price !== void 0 ? t.price : an(e.price, r),
|
|
2273
|
+
prices: t.prices ?? je(e.prices, r),
|
|
2274
|
+
product_media: void 0,
|
|
2275
|
+
product_type: t.product_type ?? e.product_type ?? "physical",
|
|
2276
|
+
sale_price: t.sale_price !== void 0 ? t.sale_price : e.sale_price === null || e.sale_price === void 0 ? null : xe(Number(e.sale_price), r),
|
|
2277
|
+
sale_prices: t.sale_prices ?? je(e.sale_prices, r),
|
|
2278
|
+
short_description: t.short_description ?? e.short_description ?? "",
|
|
2279
|
+
sku: t.sku ?? e.sku,
|
|
2280
|
+
slug: t.slug ?? e.slug,
|
|
2281
|
+
status: t.status ?? e.status ?? "draft",
|
|
2282
|
+
stock: t.stock ?? e.stock ?? 0,
|
|
2283
|
+
title: t.title ?? e.title,
|
|
2284
|
+
trial_period_days: t.trial_period_days ?? e.trial_period_days ?? 0,
|
|
2285
|
+
trial_requires_payment_method: t.trial_requires_payment_method ?? e.trial_requires_payment_method ?? !1,
|
|
2286
|
+
upc: t.upc ?? e.upc ?? "",
|
|
2287
|
+
variation_attributes: [],
|
|
2288
|
+
variants: []
|
|
2289
|
+
});
|
|
2290
|
+
}
|
|
2291
|
+
function Ln(e, n) {
|
|
2292
|
+
const t = Pe(e.field), r = t === "status" ? Un(n.contentType, e.value) : e.value, a = {
|
|
2293
|
+
description: "description_json",
|
|
2294
|
+
feature_image: "feature_image_id",
|
|
2295
|
+
feature_image_id: "feature_image_id",
|
|
2296
|
+
language: "language_id",
|
|
2297
|
+
meta_description: "meta_description",
|
|
2298
|
+
meta_title: "meta_title",
|
|
2299
|
+
payment: "payment_provider",
|
|
2300
|
+
provider: "payment_provider",
|
|
2301
|
+
regular_price: "price",
|
|
2302
|
+
sale: "sale_price",
|
|
2303
|
+
sale_price: "sale_price",
|
|
2304
|
+
short_description: "short_description",
|
|
2305
|
+
taxable: "is_taxable",
|
|
2306
|
+
trial: "trial_period_days",
|
|
2307
|
+
trial_days: "trial_period_days",
|
|
2308
|
+
trial_payment_method_required: "trial_requires_payment_method",
|
|
2309
|
+
type: "product_type"
|
|
2310
|
+
}[t] || t;
|
|
2311
|
+
if (n.contentType !== "product") {
|
|
2312
|
+
if (!(n.contentType === "page" ? mt : gt).has(a))
|
|
2313
|
+
throw new Error(`Field "${e.field}" cannot be updated for ${n.contentType}.`);
|
|
2314
|
+
return a === "status" && be(n.contentType, r), {
|
|
2315
|
+
field: a,
|
|
2316
|
+
payload: {
|
|
2317
|
+
[a]: ft(a, r)
|
|
2318
|
+
}
|
|
2319
|
+
};
|
|
2320
|
+
}
|
|
2321
|
+
if (!(/* @__PURE__ */ new Set([
|
|
2322
|
+
"description_json",
|
|
2323
|
+
"freemius_plan_id",
|
|
2324
|
+
"freemius_product_id",
|
|
2325
|
+
"is_taxable",
|
|
2326
|
+
"language_id",
|
|
2327
|
+
"meta_description",
|
|
2328
|
+
"meta_title",
|
|
2329
|
+
"payment_provider",
|
|
2330
|
+
"price",
|
|
2331
|
+
"prices",
|
|
2332
|
+
"product_type",
|
|
2333
|
+
"sale_price",
|
|
2334
|
+
"sale_prices",
|
|
2335
|
+
"short_description",
|
|
2336
|
+
"sku",
|
|
2337
|
+
"slug",
|
|
2338
|
+
"status",
|
|
2339
|
+
"stock",
|
|
2340
|
+
"title",
|
|
2341
|
+
"trial_period_days",
|
|
2342
|
+
"trial_requires_payment_method",
|
|
2343
|
+
"upc"
|
|
2344
|
+
])).has(a))
|
|
2345
|
+
throw new Error(`Field "${e.field}" cannot be updated for product.`);
|
|
2346
|
+
if (a === "status" && be("product", r), (a === "price" || a === "sale_price") && r !== null && (typeof r != "number" || r < 0))
|
|
2347
|
+
throw new Error(`${a} must be a non-negative number or null.`);
|
|
2348
|
+
if (a === "stock" && (!Number.isInteger(r) || Number(r) < 0))
|
|
2349
|
+
throw new Error("stock must be a non-negative integer.");
|
|
2350
|
+
if (a === "trial_period_days" && (!Number.isInteger(r) || Number(r) < 0))
|
|
2351
|
+
throw new Error("trial_period_days must be a non-negative integer.");
|
|
2352
|
+
if (a === "trial_requires_payment_method" && typeof r != "boolean")
|
|
2353
|
+
throw new Error("trial_requires_payment_method must be a boolean.");
|
|
2354
|
+
return {
|
|
2355
|
+
field: a,
|
|
2356
|
+
payload: {
|
|
2357
|
+
[a]: r
|
|
2358
|
+
}
|
|
2359
|
+
};
|
|
2360
|
+
}
|
|
2361
|
+
async function Tt(e, n) {
|
|
2362
|
+
const t = ue.parse(e);
|
|
2363
|
+
if (Dn(t))
|
|
2364
|
+
return {
|
|
2365
|
+
message: "Scheduled product specials are not supported by the current product schema yet. I can set or clear sale_price now, but not start/end dates.",
|
|
2366
|
+
mutationExecuted: !1,
|
|
2367
|
+
success: !1,
|
|
2368
|
+
unsupported: !0
|
|
2369
|
+
};
|
|
2370
|
+
const r = await ve(t, n), i = Ln(t, r), a = i.field;
|
|
2371
|
+
let s = i.payload;
|
|
2372
|
+
if (a === "language_id" && typeof s.language_id == "string") {
|
|
2373
|
+
const d = await U(h(n), s.language_id);
|
|
2374
|
+
s = {
|
|
2375
|
+
...s,
|
|
2376
|
+
language_id: d.id
|
|
2377
|
+
};
|
|
2378
|
+
}
|
|
2379
|
+
const l = x({
|
|
2380
|
+
action: "UPDATE FIELD",
|
|
2381
|
+
context: n,
|
|
2382
|
+
payload: {
|
|
2383
|
+
contentType: r.contentType,
|
|
2384
|
+
entityId: r.item.id,
|
|
2385
|
+
field: a,
|
|
2386
|
+
payload: s,
|
|
2387
|
+
tool: "update_cms_item_field"
|
|
2388
|
+
},
|
|
2389
|
+
preview: {
|
|
2390
|
+
contentType: r.contentType,
|
|
2391
|
+
field: a,
|
|
2392
|
+
from: r.item[a],
|
|
2393
|
+
slug: r.item.slug,
|
|
2394
|
+
title: r.item.title,
|
|
2395
|
+
to: s[a]
|
|
2396
|
+
},
|
|
2397
|
+
subject: `${r.contentType} ${r.item.slug || r.item.id} ${a}`
|
|
2398
|
+
});
|
|
2399
|
+
if (l)
|
|
2400
|
+
return l;
|
|
2401
|
+
if (r.contentType === "product") {
|
|
2402
|
+
const { updateProduct: d } = await Ie(), g = await Mn(r.item, h(n), s), p = await d(h(n), String(r.item.id), g);
|
|
2403
|
+
return F(
|
|
2404
|
+
n,
|
|
2405
|
+
{
|
|
2406
|
+
contentType: "product",
|
|
2407
|
+
entityId: String(r.item.id),
|
|
2408
|
+
languageId: p?.language_id ?? r.item.language_id,
|
|
2409
|
+
slug: p?.slug ?? r.item.slug,
|
|
2410
|
+
title: p?.title ?? r.item.title
|
|
2411
|
+
},
|
|
2412
|
+
p?.slug ?? r.item.slug
|
|
2413
|
+
), {
|
|
2414
|
+
contentType: "product",
|
|
2415
|
+
entityId: r.item.id,
|
|
2416
|
+
field: a,
|
|
2417
|
+
mutationExecuted: !0,
|
|
2418
|
+
slug: p?.slug ?? r.item.slug,
|
|
2419
|
+
success: !0,
|
|
2420
|
+
updatedFields: [a]
|
|
2421
|
+
};
|
|
2422
|
+
}
|
|
2423
|
+
const m = r.contentType === "page" ? "pages" : "posts", { data: u, error: c } = await h(n).from(m).update({
|
|
2424
|
+
...s,
|
|
2425
|
+
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
2426
|
+
}).eq("id", r.item.id).select("id, language_id, slug, status, title").single();
|
|
2427
|
+
if (c || !u)
|
|
2428
|
+
throw new Error(`Failed to update ${r.contentType}: ${f(c)}`);
|
|
2429
|
+
return F(
|
|
2430
|
+
n,
|
|
2431
|
+
{
|
|
2432
|
+
contentType: r.contentType,
|
|
2433
|
+
entityId: Number(u.id),
|
|
2434
|
+
languageId: u.language_id,
|
|
2435
|
+
slug: u.slug,
|
|
2436
|
+
title: u.title
|
|
2437
|
+
},
|
|
2438
|
+
u.slug
|
|
2439
|
+
), {
|
|
2440
|
+
contentType: r.contentType,
|
|
2441
|
+
entityId: u.id,
|
|
2442
|
+
field: a,
|
|
2443
|
+
mutationExecuted: !0,
|
|
2444
|
+
slug: u.slug,
|
|
2445
|
+
success: !0,
|
|
2446
|
+
updatedFields: [a]
|
|
2447
|
+
};
|
|
2448
|
+
}
|
|
2449
|
+
async function xt(e, n) {
|
|
2450
|
+
const t = Je.parse(e), r = await ve(t, n);
|
|
2451
|
+
if (r.contentType === "product")
|
|
2452
|
+
return {
|
|
2453
|
+
affectedCount: 1,
|
|
2454
|
+
collectionPath: Ue("product"),
|
|
2455
|
+
contentType: "product",
|
|
2456
|
+
item: r.item,
|
|
2457
|
+
navigationLinkCount: 0,
|
|
2458
|
+
publicPaths: r.item.slug ? [`/product/${r.item.slug}`] : [],
|
|
2459
|
+
targetIds: [r.item.id]
|
|
2460
|
+
};
|
|
2461
|
+
const i = r.contentType === "page" ? "pages" : "posts", { data: a, error: s } = await h(n).from(i).select("id, slug, title, translation_group_id").eq("translation_group_id", r.item.translation_group_id);
|
|
2462
|
+
if (s)
|
|
2463
|
+
throw new Error(`Failed to inspect related ${r.contentType}s: ${f(s)}`);
|
|
2464
|
+
const l = Array.isArray(a) ? a : [], m = l.map(
|
|
2465
|
+
(p) => r.contentType === "page" ? p.slug === "home" ? "/" : `/${p.slug}` : `/article/${p.slug}`
|
|
2466
|
+
).filter(Boolean), u = new Set(m), { data: c, error: d } = await h(n).from("navigation_items").select("id, url");
|
|
2467
|
+
if (d)
|
|
2468
|
+
throw new Error(`Failed to inspect related navigation links: ${f(d)}`);
|
|
2469
|
+
const g = (Array.isArray(c) ? c : []).filter(
|
|
2470
|
+
(p) => u.has(p.url)
|
|
2471
|
+
).length;
|
|
2472
|
+
return {
|
|
2473
|
+
affectedCount: l.length,
|
|
2474
|
+
collectionPath: Ue(r.contentType),
|
|
2475
|
+
contentType: r.contentType,
|
|
2476
|
+
item: r.item,
|
|
2477
|
+
navigationLinkCount: g,
|
|
2478
|
+
publicPaths: m,
|
|
2479
|
+
targetIds: l.map((p) => p.id)
|
|
2480
|
+
};
|
|
2481
|
+
}
|
|
2482
|
+
function $t(e) {
|
|
2483
|
+
const n = e.item.title || e.item.slug || "selected item", t = e.item.slug ? ` (${e.item.slug})` : "";
|
|
2484
|
+
if (e.contentType === "product")
|
|
2485
|
+
return `Delete product "${n}"${t}.`;
|
|
2486
|
+
const r = [
|
|
2487
|
+
`${N(e.affectedCount, "language version")}`,
|
|
2488
|
+
e.navigationLinkCount > 0 ? `${N(e.navigationLinkCount, "navigation link")}` : null
|
|
2489
|
+
].filter(Boolean);
|
|
2490
|
+
return `Delete ${e.contentType} "${n}"${t}, including ${r.join(" and ")}.`;
|
|
2491
|
+
}
|
|
2492
|
+
async function Rn(e, n) {
|
|
2493
|
+
const t = await xt(e, n);
|
|
2494
|
+
return {
|
|
2495
|
+
...Xe({
|
|
2496
|
+
action: `DELETE ${t.contentType}`,
|
|
2497
|
+
payload: {
|
|
2498
|
+
affectedCount: t.affectedCount,
|
|
2499
|
+
contentType: t.contentType,
|
|
2500
|
+
targetIds: t.targetIds,
|
|
2501
|
+
tool: "delete_cms_item"
|
|
2502
|
+
},
|
|
2503
|
+
preview: {
|
|
2504
|
+
affectedCount: t.affectedCount,
|
|
2505
|
+
collectionPath: t.collectionPath,
|
|
2506
|
+
contentType: t.contentType,
|
|
2507
|
+
navigationLinkCount: t.navigationLinkCount,
|
|
2508
|
+
publicPaths: t.publicPaths,
|
|
2509
|
+
slug: t.item.slug,
|
|
2510
|
+
summary: $t(t),
|
|
2511
|
+
title: t.item.title
|
|
2512
|
+
},
|
|
2513
|
+
subject: `${t.item.id} ${t.item.slug || ""}`
|
|
2514
|
+
}),
|
|
2515
|
+
preparedDelete: !0
|
|
2516
|
+
};
|
|
2517
|
+
}
|
|
2518
|
+
async function vt(e, n) {
|
|
2519
|
+
const t = de.parse(e), r = await xt(t, n), i = x({
|
|
2520
|
+
action: `DELETE ${r.contentType}`,
|
|
2521
|
+
context: n,
|
|
2522
|
+
payload: {
|
|
2523
|
+
affectedCount: r.affectedCount,
|
|
2524
|
+
contentType: r.contentType,
|
|
2525
|
+
targetIds: r.targetIds,
|
|
2526
|
+
tool: "delete_cms_item"
|
|
2527
|
+
},
|
|
2528
|
+
preview: {
|
|
2529
|
+
affectedCount: r.affectedCount,
|
|
2530
|
+
collectionPath: r.collectionPath,
|
|
2531
|
+
contentType: r.contentType,
|
|
2532
|
+
navigationLinkCount: r.navigationLinkCount,
|
|
2533
|
+
publicPaths: r.publicPaths,
|
|
2534
|
+
slug: r.item.slug,
|
|
2535
|
+
summary: $t(r),
|
|
2536
|
+
title: r.item.title
|
|
2537
|
+
},
|
|
2538
|
+
subject: `${r.item.id} ${r.item.slug || ""}`
|
|
2539
|
+
});
|
|
2540
|
+
if (i)
|
|
2541
|
+
return i;
|
|
2542
|
+
const a = h(n);
|
|
2543
|
+
if (r.contentType === "product") {
|
|
2544
|
+
const { error: l } = await a.from("products").delete().eq("id", r.item.id);
|
|
2545
|
+
if (l)
|
|
2546
|
+
throw new Error(`Failed to delete product: ${f(l)}`);
|
|
2547
|
+
} else {
|
|
2548
|
+
for (const u of r.publicPaths)
|
|
2549
|
+
await a.from("navigation_items").delete().eq("url", u);
|
|
2550
|
+
const l = r.contentType === "page" ? "pages" : "posts", { error: m } = await a.from(l).delete().eq("translation_group_id", r.item.translation_group_id);
|
|
2551
|
+
if (m)
|
|
2552
|
+
throw new Error(`Failed to delete ${r.contentType}: ${f(m)}`);
|
|
2553
|
+
}
|
|
2554
|
+
const s = n?.revalidatePath ?? ke();
|
|
2555
|
+
return s && (s(r.collectionPath), s("/cms/navigation"), r.publicPaths.forEach((l) => s(l))), {
|
|
2556
|
+
affectedCount: r.affectedCount,
|
|
2557
|
+
collectionPath: r.collectionPath,
|
|
2558
|
+
contentType: r.contentType,
|
|
2559
|
+
mutationExecuted: !0,
|
|
2560
|
+
redirectPath: r.collectionPath,
|
|
2561
|
+
success: !0
|
|
2562
|
+
};
|
|
2563
|
+
}
|
|
2564
|
+
async function Le(e, n) {
|
|
2565
|
+
switch (e.tool) {
|
|
2566
|
+
case "create_cms_page":
|
|
2567
|
+
return kt(e.input, n);
|
|
2568
|
+
case "create_cms_post":
|
|
2569
|
+
return wt(e.input, n);
|
|
2570
|
+
case "create_cms_product":
|
|
2571
|
+
return Ct(e.input, n);
|
|
2572
|
+
case "delete_cms_item":
|
|
2573
|
+
return vt(e.input, n);
|
|
2574
|
+
case "update_cms_item_field":
|
|
2575
|
+
return Tt(e.input, n);
|
|
2576
|
+
case "update_content_block":
|
|
2577
|
+
return bt(e.input, n);
|
|
2578
|
+
case "insert_content_block":
|
|
2579
|
+
return yt(e.input, n);
|
|
2580
|
+
case "update_current_cms_fields":
|
|
2581
|
+
return _t(e.input, n);
|
|
2582
|
+
case "update_footer":
|
|
2583
|
+
return dt(e.input, n);
|
|
2584
|
+
case "update_navigation_bar":
|
|
2585
|
+
return ut(e.input, n);
|
|
2586
|
+
case "update_section_column_block":
|
|
2587
|
+
return ht(e.input, n);
|
|
2588
|
+
}
|
|
2589
|
+
}
|
|
2590
|
+
function Gn(e, n) {
|
|
2591
|
+
if (e.tool !== "create_cms_page" && e.tool !== "create_cms_post" && e.tool !== "create_cms_product" || e.input.translationGroupId || !e.input.languageCode)
|
|
2592
|
+
return e;
|
|
2593
|
+
const t = n[e.tool];
|
|
2594
|
+
return t ? {
|
|
2595
|
+
...e,
|
|
2596
|
+
input: {
|
|
2597
|
+
...e.input,
|
|
2598
|
+
translationGroupId: t
|
|
2599
|
+
}
|
|
2600
|
+
} : e;
|
|
2601
|
+
}
|
|
2602
|
+
async function zn(e, n) {
|
|
2603
|
+
const t = He.parse(e);
|
|
2604
|
+
if (!n?.skipConfirmation) {
|
|
2605
|
+
const u = [];
|
|
2606
|
+
for (const g of t.actions) {
|
|
2607
|
+
const p = await Le(g, {
|
|
2608
|
+
...n,
|
|
2609
|
+
latestUserMessage: null
|
|
2610
|
+
});
|
|
2611
|
+
if (!p || typeof p != "object")
|
|
2612
|
+
return {
|
|
2613
|
+
message: `Could not prepare action ${u.length + 1}.`,
|
|
2614
|
+
mutationExecuted: !1,
|
|
2615
|
+
success: !1
|
|
2616
|
+
};
|
|
2617
|
+
if (p.success === !1 || p.unsupported === !0)
|
|
2618
|
+
return p;
|
|
2619
|
+
p.requiresConfirmation === !0 && p.preview ? u.push(
|
|
2620
|
+
rn(g.tool, p.preview)
|
|
2621
|
+
) : u.push(`Run ${g.tool.replace(/_/g, " ")}.`);
|
|
2622
|
+
}
|
|
2623
|
+
const c = t.summary || `Complete ${N(t.actions.length, "CMS action")}.`, d = x({
|
|
2624
|
+
action: "EXECUTE CMS ACTION PLAN",
|
|
2625
|
+
context: n,
|
|
2626
|
+
payload: { actions: t.actions, tool: "execute_cms_action_plan" },
|
|
2627
|
+
preview: {
|
|
2628
|
+
actionCount: t.actions.length,
|
|
2629
|
+
actionSummaries: u,
|
|
2630
|
+
summary: c
|
|
2631
|
+
},
|
|
2632
|
+
subject: `${t.actions.length} actions`
|
|
2633
|
+
});
|
|
2634
|
+
if (d)
|
|
2635
|
+
return d;
|
|
2636
|
+
}
|
|
2637
|
+
const r = {
|
|
2638
|
+
...n,
|
|
2639
|
+
skipConfirmation: !0
|
|
2640
|
+
}, i = [];
|
|
2641
|
+
let a = !1, s = null, l = null;
|
|
2642
|
+
const m = {};
|
|
2643
|
+
for (const [u, c] of t.actions.entries()) {
|
|
2644
|
+
const d = Gn(c, m), g = await Le(d, r);
|
|
2645
|
+
if (i.push({ output: g, tool: d.tool }), g && typeof g == "object") {
|
|
2646
|
+
const p = g;
|
|
2647
|
+
if (p.mutationExecuted === !0 && (a = !0), !s && typeof p.editPath == "string" && (s = p.editPath), typeof p.redirectPath == "string" && (l = p.redirectPath), (d.tool === "create_cms_page" || d.tool === "create_cms_post" || d.tool === "create_cms_product") && typeof p.translationGroupId == "string" && (m[d.tool] = p.translationGroupId), p.success === !1 || p.unsupported === !0)
|
|
2648
|
+
return {
|
|
2649
|
+
actionCount: t.actions.length,
|
|
2650
|
+
failedActionIndex: u,
|
|
2651
|
+
failedTool: d.tool,
|
|
2652
|
+
message: typeof p.message == "string" ? p.message : `Action ${u + 1} failed.`,
|
|
2653
|
+
mutationExecuted: a,
|
|
2654
|
+
results: i,
|
|
2655
|
+
success: !1,
|
|
2656
|
+
...s ? { editPath: s } : {},
|
|
2657
|
+
...l ? { redirectPath: l } : {}
|
|
2658
|
+
};
|
|
2659
|
+
}
|
|
2660
|
+
}
|
|
2661
|
+
return {
|
|
2662
|
+
actionCount: t.actions.length,
|
|
2663
|
+
editPath: l ? void 0 : s ?? void 0,
|
|
2664
|
+
mutationExecuted: a,
|
|
2665
|
+
redirectPath: l ?? void 0,
|
|
2666
|
+
results: i,
|
|
2667
|
+
success: !0,
|
|
2668
|
+
summary: t.summary ?? null
|
|
2669
|
+
};
|
|
2670
|
+
}
|
|
2671
|
+
function Qn(e) {
|
|
2672
|
+
return {
|
|
2673
|
+
...St(e),
|
|
2674
|
+
...Et(e),
|
|
2675
|
+
fetch_ecommerce_stats: w({
|
|
2676
|
+
description: "Fetch quantitative ecommerce statistics and reports from the database. Use this to answer questions about revenue, order counts, order status counts such as pending or trial, and top-selling products over a time range. This tool is read-only and does not require confirmation.",
|
|
2677
|
+
execute: (n) => Pn(n, e),
|
|
2678
|
+
inputSchema: ze,
|
|
2679
|
+
strict: !0
|
|
2680
|
+
}),
|
|
2681
|
+
read_current_cms_item: w({
|
|
2682
|
+
description: "Read the CMS item currently being edited. Requires pageContext and returns page/post/product metadata plus page/post block summaries or content.",
|
|
2683
|
+
execute: (n) => Bn(n, e),
|
|
2684
|
+
inputSchema: Ve,
|
|
2685
|
+
strict: !0
|
|
2686
|
+
}),
|
|
2687
|
+
search_documentation: w({
|
|
2688
|
+
description: "Search the NextBlock documentation database and return concise source snippets for factual CMS guidance.",
|
|
2689
|
+
execute: (n) => $n(n, e),
|
|
2690
|
+
inputSchema: ye,
|
|
2691
|
+
strict: !0
|
|
2692
|
+
}),
|
|
2693
|
+
create_cms_page: w({
|
|
2694
|
+
description: "Create a new CMS page with metadata and optional validated page blocks. Mutating: first returns a confirmation phrase; only executes after the user replies with the exact phrase. For translations, pass translationGroupId from the source page/post/product context so the new language is linked to the same backend translation group. For contact pages, provide contactEmail or a form block with recipient_email and fields.",
|
|
2695
|
+
execute: (n) => kt(n, e),
|
|
2696
|
+
inputSchema: se,
|
|
2697
|
+
strict: !0
|
|
2698
|
+
}),
|
|
2699
|
+
create_cms_post: w({
|
|
2700
|
+
description: "Create a new CMS post with metadata and optional validated post blocks. Mutating: first returns a confirmation phrase; only executes after the user replies with the exact phrase. For translations, pass translationGroupId from the source post context so the new language is linked to the same backend translation group.",
|
|
2701
|
+
execute: (n) => wt(n, e),
|
|
2702
|
+
inputSchema: le,
|
|
2703
|
+
strict: !0
|
|
2704
|
+
}),
|
|
2705
|
+
create_cms_product: w({
|
|
2706
|
+
description: "Create a new draft-capable product. Defaults missing product fields safely: physical Stripe product, generated SKU, price 0, stock 0, taxable, draft. For translations, pass translationGroupId from the source product context. Mutating: first returns a confirmation phrase; only executes after exact confirmation.",
|
|
2707
|
+
execute: (n) => Ct(n, e),
|
|
2708
|
+
inputSchema: ce,
|
|
2709
|
+
strict: !0
|
|
2710
|
+
}),
|
|
2711
|
+
delete_cms_item: w({
|
|
2712
|
+
description: "Delete a resolved page, post, or product after exact confirmation. Pages/posts delete all translations in the translation group and related navigation links. Mutating: refuses unless the latest user message includes the exact confirmation phrase.",
|
|
2713
|
+
execute: (n) => vt(n, e),
|
|
2714
|
+
inputSchema: de,
|
|
2715
|
+
strict: !0
|
|
2716
|
+
}),
|
|
2717
|
+
prepare_delete_cms_item: w({
|
|
2718
|
+
description: "Inspect the page, post, or product that would be deleted and return the exact confirmation phrase. This tool does not mutate data.",
|
|
2719
|
+
execute: (n) => Rn(n, e),
|
|
2720
|
+
inputSchema: Je,
|
|
2721
|
+
strict: !0
|
|
2722
|
+
}),
|
|
2723
|
+
update_footer: w({
|
|
2724
|
+
description: "Replace the public footer links and/or footer copyright settings for a locale. Use links for footer navigation and copyright for locale text templates. Mutating: first returns a confirmation phrase; only executes after exact confirmation.",
|
|
2725
|
+
execute: (n) => dt(n, e),
|
|
2726
|
+
inputSchema: te,
|
|
2727
|
+
strict: !0
|
|
2728
|
+
}),
|
|
2729
|
+
update_content_block: w({
|
|
2730
|
+
description: 'Update the JSON content of an existing top-level page/post block that belongs to the current CMS edit context. Content is merged with the existing block before validation. For section blocks, add nested blocks with content.append_block or content.append_blocks using objects like { block_type: "button", content: { text: "Contact Us", url: "/contact" } }; existing column_blocks and layout fields are preserved. Mutating: first returns a confirmation phrase; only executes after exact confirmation.',
|
|
2731
|
+
execute: (n) => bt(n, e),
|
|
2732
|
+
inputSchema: oe,
|
|
2733
|
+
strict: !0
|
|
2734
|
+
}),
|
|
2735
|
+
insert_content_block: w({
|
|
2736
|
+
description: 'Insert a new validated top-level page/post block before or after an existing block, or at the start/end. Use this for visible content additions like adding a rich text title and paragraph above a form. For "above the form", use position "before" with anchorBlockType "form" and blockType "text" containing html_content. Mutating: first returns a confirmation phrase; only executes after exact confirmation.',
|
|
2737
|
+
execute: (n) => yt(n, e),
|
|
2738
|
+
inputSchema: ae,
|
|
2739
|
+
strict: !0
|
|
2740
|
+
}),
|
|
2741
|
+
update_current_cms_fields: w({
|
|
2742
|
+
description: "Update validated metadata fields on the current page, post, or product. For products, description_json must be a valid NextBlock editor document JSON object. Mutating: first returns a confirmation phrase; only executes after exact confirmation.",
|
|
2743
|
+
execute: (n) => _t(n, e),
|
|
2744
|
+
inputSchema: ne,
|
|
2745
|
+
strict: !0
|
|
2746
|
+
}),
|
|
2747
|
+
update_cms_item_field: w({
|
|
2748
|
+
description: "Update one field on a page, post, or product, resolving by current edit context, id, slug, or exact title. Use this for requests like changing price, stock, title, slug, status, sale_price, or meta fields. Interpret public as published for pages/posts and active for products. Scheduled sale date ranges are not supported and will be refused without mutation. Mutating: first returns a confirmation phrase; only executes after exact confirmation.",
|
|
2749
|
+
execute: (n) => Tt(n, e),
|
|
2750
|
+
inputSchema: ue,
|
|
2751
|
+
strict: !0
|
|
2752
|
+
}),
|
|
2753
|
+
update_navigation_bar: w({
|
|
2754
|
+
description: 'Update the public header navigation bar for a locale. Use mode "append" when adding links while preserving existing navigation. Use mode "update" when renaming or changing an existing single link. Use mode "replace" only when the user asks to rebuild the complete header and you provide the full menu; destructive partial replacements are refused. Mutating: first returns a confirmation phrase; only executes after exact confirmation.',
|
|
2755
|
+
execute: (n) => ut(n, e),
|
|
2756
|
+
inputSchema: ee,
|
|
2757
|
+
strict: !0
|
|
2758
|
+
}),
|
|
2759
|
+
update_section_column_block: w({
|
|
2760
|
+
description: "Update the content of one existing nested block inside a section block that belongs to the current CMS edit context. This tool must not change the nested block type. To add a new nested block, update the parent section with update_content_block and preserve existing column_blocks. Mutating: first returns a confirmation phrase; only executes after exact confirmation.",
|
|
2761
|
+
execute: (n) => ht(n, e),
|
|
2762
|
+
inputSchema: re,
|
|
2763
|
+
strict: !0
|
|
2764
|
+
}),
|
|
2765
|
+
execute_cms_action_plan: w({
|
|
2766
|
+
description: "Execute multiple CMS mutations as one confirmed plan. Use this whenever the user asks for more than one change in the same prompt, such as creating a page and adding a navigation link. First returns one combined confirmation preview and Confirm button; after confirmation, runs each action in order and stops on the first failure.",
|
|
2767
|
+
execute: (n) => zn(n, e),
|
|
2768
|
+
inputSchema: He,
|
|
2769
|
+
strict: !0
|
|
2770
|
+
})
|
|
2771
|
+
};
|
|
2772
|
+
}
|
|
2773
|
+
export {
|
|
2774
|
+
O as availableCortexAiBlockTypes,
|
|
2775
|
+
Yn as buildVisibleContactIntroActionPlan,
|
|
2776
|
+
Ke as cortexAiPageContextSchema,
|
|
2777
|
+
se as createCmsPageInputSchema,
|
|
2778
|
+
le as createCmsPostInputSchema,
|
|
2779
|
+
ce as createCmsProductInputSchema,
|
|
2780
|
+
Qn as createCortexGlobalAgentTools,
|
|
2781
|
+
de as deleteCmsItemInputSchema,
|
|
2782
|
+
zn as executeCmsActionPlan,
|
|
2783
|
+
He as executeCmsActionPlanInputSchema,
|
|
2784
|
+
kt as executeCreateCmsPage,
|
|
2785
|
+
wt as executeCreateCmsPost,
|
|
2786
|
+
Ct as executeCreateCmsProduct,
|
|
2787
|
+
vt as executeDeleteCmsItem,
|
|
2788
|
+
Pn as executeFetchEcommerceStats,
|
|
2789
|
+
yt as executeInsertContentBlock,
|
|
2790
|
+
Rn as executePrepareDeleteCmsItem,
|
|
2791
|
+
Bn as executeReadCurrentCmsItem,
|
|
2792
|
+
xn as executeSearchDocumentation,
|
|
2793
|
+
$n as executeSearchDocumentationWithTimeout,
|
|
2794
|
+
Tt as executeUpdateCmsItemField,
|
|
2795
|
+
bt as executeUpdateContentBlock,
|
|
2796
|
+
_t as executeUpdateCurrentCmsFields,
|
|
2797
|
+
dt as executeUpdateFooter,
|
|
2798
|
+
ut as executeUpdateNavigationBar,
|
|
2799
|
+
ht as executeUpdateSectionColumnBlock,
|
|
2800
|
+
ze as fetchEcommerceStatsInputSchema,
|
|
2801
|
+
ae as insertContentBlockInputSchema,
|
|
2802
|
+
Ge as navigationItemInputSchema,
|
|
2803
|
+
Je as prepareDeleteCmsItemInputSchema,
|
|
2804
|
+
Ve as readCurrentCmsItemInputSchema,
|
|
2805
|
+
ye as searchDocumentationInputSchema,
|
|
2806
|
+
ue as updateCmsItemFieldInputSchema,
|
|
2807
|
+
oe as updateContentBlockInputSchema,
|
|
2808
|
+
ne as updateCurrentCmsFieldsInputSchema,
|
|
2809
|
+
te as updateFooterInputSchema,
|
|
2810
|
+
ee as updateNavigationBarInputSchema,
|
|
2811
|
+
re as updateSectionColumnBlockInputSchema
|
|
2812
|
+
};
|