@nextblock-cms/cortex 0.14.3 → 0.14.5
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/lib/ai-global-agent-db-tools.cjs.js +1 -1
- package/lib/ai-global-agent-db-tools.d.ts +8 -8
- package/lib/ai-global-agent-db-tools.es.js +24 -11
- package/lib/ai-global-agent-tools.cjs.js +2 -2
- package/lib/ai-global-agent-tools.d.ts +116 -97
- package/lib/ai-global-agent-tools.es.js +1223 -1181
- package/package.json +4 -4
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { tool as
|
|
2
|
-
import { createCortexDatabaseAgentTools as
|
|
3
|
-
import { createCortexCustomBlockTools as
|
|
4
|
-
import { editorDocumentFromHtml as
|
|
1
|
+
import { tool as v } from "ai";
|
|
2
|
+
import { createCortexDatabaseAgentTools as cn } from "./ai-global-agent-db-tools.es.js";
|
|
3
|
+
import { createCortexCustomBlockTools as ln } from "./ai-global-agent-custom-block-tools.es.js";
|
|
4
|
+
import { editorDocumentFromHtml as gt } from "./editor-document-from-html.es.js";
|
|
5
5
|
import "./zod-config.es.js";
|
|
6
6
|
import { z as i } from "zod";
|
|
7
|
-
const
|
|
7
|
+
const V = [
|
|
8
8
|
"text",
|
|
9
9
|
"heading",
|
|
10
10
|
"image",
|
|
@@ -19,7 +19,25 @@ const K = [
|
|
|
19
19
|
"cart",
|
|
20
20
|
"checkout",
|
|
21
21
|
"product_details"
|
|
22
|
-
]
|
|
22
|
+
];
|
|
23
|
+
async function J(e, t, n) {
|
|
24
|
+
if (e?.recordRevision)
|
|
25
|
+
try {
|
|
26
|
+
return await e.recordRevision({ contentType: t, entityId: n, phase: "capture" });
|
|
27
|
+
} catch (r) {
|
|
28
|
+
console.error("Cortex AI: failed to capture revision baseline", r);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async function G(e, t, n, r) {
|
|
33
|
+
if (!(!e?.recordRevision || r === void 0))
|
|
34
|
+
try {
|
|
35
|
+
await e.recordRevision({ baseline: r, contentType: t, entityId: n, phase: "commit" });
|
|
36
|
+
} catch (o) {
|
|
37
|
+
console.error("Cortex AI: failed to record revision", o);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const un = 1e4, dn = {
|
|
23
41
|
arabic: "ar",
|
|
24
42
|
chinese: "zh",
|
|
25
43
|
dutch: "nl",
|
|
@@ -34,40 +52,40 @@ const K = [
|
|
|
34
52
|
portuguese: "pt",
|
|
35
53
|
russian: "ru",
|
|
36
54
|
spanish: "es"
|
|
37
|
-
},
|
|
55
|
+
}, ft = i.string().trim().min(1).max(2048).refine(
|
|
38
56
|
(e) => e.startsWith("/") || e.startsWith("#") || e.startsWith("http://") || e.startsWith("https://") || e.startsWith("mailto:") || e.startsWith("tel:"),
|
|
39
57
|
"URL must be a relative path, hash link, http(s) URL, mailto URL, or tel URL."
|
|
40
|
-
),
|
|
58
|
+
), Ze = i.strictObject({
|
|
41
59
|
label: i.string().trim().min(1).max(120),
|
|
42
60
|
target: i.enum(["_self", "_blank"]).optional(),
|
|
43
|
-
url:
|
|
44
|
-
}),
|
|
45
|
-
children: i.array(
|
|
46
|
-
}),
|
|
61
|
+
url: ft
|
|
62
|
+
}), ht = Ze.extend({
|
|
63
|
+
children: i.array(Ze).max(20).optional()
|
|
64
|
+
}), pn = i.strictObject({
|
|
47
65
|
label: i.string().trim().min(1).max(120).optional(),
|
|
48
|
-
url:
|
|
66
|
+
url: ft.optional()
|
|
49
67
|
}).refine((e) => !!(e.label || e.url), {
|
|
50
68
|
message: "Navigation item match requires label or url."
|
|
51
|
-
}),
|
|
52
|
-
items: i.array(
|
|
69
|
+
}), ge = i.strictObject({
|
|
70
|
+
items: i.array(ht).min(1).max(30),
|
|
53
71
|
languageCode: i.string().trim().min(2).max(80).default("en").describe('Locale code or language name, for example "en", "fr", "English", or "French".'),
|
|
54
|
-
match:
|
|
72
|
+
match: pn.optional().describe('For mode "update", identifies the existing navigation item to update.'),
|
|
55
73
|
mode: i.enum(["append", "replace", "update"]).default("append")
|
|
56
|
-
}),
|
|
74
|
+
}), fe = i.strictObject({
|
|
57
75
|
copyright: i.record(i.string().trim().min(2).max(12), i.string().trim().min(1).max(500)).optional(),
|
|
58
76
|
languageCode: i.string().trim().min(2).max(80).default("en").describe('Locale code or language name, for example "en", "fr", "English", or "French".'),
|
|
59
|
-
links: i.array(
|
|
60
|
-
}),
|
|
77
|
+
links: i.array(ht).min(1).max(30).optional()
|
|
78
|
+
}), Be = i.strictObject({
|
|
61
79
|
limit: i.number().int().min(1).max(8).default(4),
|
|
62
80
|
query: i.string().trim().min(2).max(300)
|
|
63
|
-
}),
|
|
81
|
+
}), yt = i.object({
|
|
64
82
|
currency: i.string().trim().min(3).max(3).optional().describe(
|
|
65
83
|
"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."
|
|
66
84
|
),
|
|
67
85
|
query: i.string().describe("The analytical question about orders, products, or revenue."),
|
|
68
86
|
reportType: i.enum(["revenue", "orders", "products", "general"]).optional().default("general").describe("The focus area of the statistical report."),
|
|
69
87
|
timeRange: i.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.")
|
|
70
|
-
}),
|
|
88
|
+
}), _t = i.strictObject({
|
|
71
89
|
contentType: i.enum(["page", "post", "product"]),
|
|
72
90
|
currentEditor: i.strictObject({
|
|
73
91
|
blockId: i.union([i.number().int().positive(), i.string().trim().min(1).max(120)]).nullable().optional(),
|
|
@@ -79,10 +97,10 @@ const K = [
|
|
|
79
97
|
slug: i.string().trim().min(1).max(300).nullable().optional(),
|
|
80
98
|
title: i.string().trim().min(1).max(300).nullable().optional(),
|
|
81
99
|
translationGroupId: i.string().trim().min(1).max(120).nullable().optional()
|
|
82
|
-
}),
|
|
100
|
+
}), bt = i.strictObject({
|
|
83
101
|
includeBlockContent: i.boolean().default(!1),
|
|
84
102
|
includeBlocks: i.boolean().default(!0)
|
|
85
|
-
}),
|
|
103
|
+
}), he = i.strictObject({
|
|
86
104
|
fields: i.strictObject({
|
|
87
105
|
// Accepts an HTML string as well as an editor document — see
|
|
88
106
|
// validateProductDescriptionJson.
|
|
@@ -99,36 +117,36 @@ const K = [
|
|
|
99
117
|
subtitle: i.string().max(300).nullable().optional(),
|
|
100
118
|
title: i.string().trim().min(1).max(300).optional()
|
|
101
119
|
}).partial()
|
|
102
|
-
}),
|
|
120
|
+
}), ye = i.strictObject({
|
|
103
121
|
blockId: i.number().int().positive(),
|
|
104
|
-
blockType: i.enum(
|
|
122
|
+
blockType: i.enum(V).optional(),
|
|
105
123
|
content: i.record(i.string(), i.unknown())
|
|
106
|
-
}),
|
|
124
|
+
}), _e = i.strictObject({
|
|
107
125
|
blockIndex: i.number().int().min(0),
|
|
108
|
-
blockType: i.enum(
|
|
126
|
+
blockType: i.enum(V).optional(),
|
|
109
127
|
columnIndex: i.number().int().min(0),
|
|
110
128
|
content: i.record(i.string(), i.unknown()),
|
|
111
129
|
parentBlockId: i.number().int().positive()
|
|
112
|
-
}),
|
|
113
|
-
contentType:
|
|
130
|
+
}), mn = i.enum(["page", "post", "product"]), W = i.strictObject({
|
|
131
|
+
contentType: mn.optional(),
|
|
114
132
|
entityId: i.union([i.number().int().positive(), i.string().trim().min(1).max(120)]).optional(),
|
|
115
133
|
slug: i.string().trim().min(1).max(300).optional(),
|
|
116
134
|
title: i.string().trim().min(1).max(300).optional()
|
|
117
|
-
}),
|
|
118
|
-
blockType: i.enum(
|
|
135
|
+
}), te = i.strictObject({
|
|
136
|
+
blockType: i.enum(V),
|
|
119
137
|
content: i.record(i.string(), i.unknown()),
|
|
120
138
|
order: i.number().int().min(0).optional()
|
|
121
|
-
}),
|
|
139
|
+
}), be = W.extend({
|
|
122
140
|
images: i.array(i.string().trim().min(1).max(2048)).min(1).max(12).describe(
|
|
123
141
|
"External https image URLs (imported into the media library automatically) and/or existing media library ids. The first entry is the feature image (pages/posts) or the main product image (products)."
|
|
124
142
|
)
|
|
125
|
-
}),
|
|
143
|
+
}), we = W.extend({
|
|
126
144
|
anchorBlockId: i.number().int().positive().optional(),
|
|
127
|
-
anchorBlockType: i.enum(
|
|
128
|
-
block:
|
|
145
|
+
anchorBlockType: i.enum(V).optional(),
|
|
146
|
+
block: te,
|
|
129
147
|
position: i.enum(["before", "after", "start", "end"]).default("end")
|
|
130
|
-
}),
|
|
131
|
-
blocks: i.array(
|
|
148
|
+
}), ke = i.strictObject({
|
|
149
|
+
blocks: i.array(te).max(20).optional(),
|
|
132
150
|
contactEmail: i.string().email().optional(),
|
|
133
151
|
feature_image_id: i.string().trim().min(1).max(2048).nullable().optional(),
|
|
134
152
|
languageCode: i.string().trim().min(2).max(80).optional(),
|
|
@@ -138,8 +156,8 @@ const K = [
|
|
|
138
156
|
status: i.enum(["draft", "published", "archived"]).default("draft"),
|
|
139
157
|
title: i.string().trim().min(1).max(300),
|
|
140
158
|
translationGroupId: i.string().trim().min(1).max(120).optional()
|
|
141
|
-
}),
|
|
142
|
-
blocks: i.array(
|
|
159
|
+
}), Ie = i.strictObject({
|
|
160
|
+
blocks: i.array(te).max(20).optional(),
|
|
143
161
|
excerpt: i.string().max(2e3).nullable().optional(),
|
|
144
162
|
feature_image_id: i.string().trim().min(1).max(2048).nullable().optional(),
|
|
145
163
|
label: i.string().max(120).nullable().optional(),
|
|
@@ -152,11 +170,11 @@ const K = [
|
|
|
152
170
|
subtitle: i.string().max(300).nullable().optional(),
|
|
153
171
|
title: i.string().trim().min(1).max(300),
|
|
154
172
|
translationGroupId: i.string().trim().min(1).max(120).optional()
|
|
155
|
-
}),
|
|
173
|
+
}), Te = i.strictObject({
|
|
156
174
|
// Products render "Product Description Blocks" exactly like pages/posts render
|
|
157
175
|
// their blocks (blocks.product_id). This is the richest body and takes
|
|
158
176
|
// precedence over description_html on the public product page.
|
|
159
|
-
blocks: i.array(
|
|
177
|
+
blocks: i.array(te).max(20).optional().describe(
|
|
160
178
|
"Content blocks for the product description area, same block vocabulary as create_cms_page. Rendered on the public product page in place of the plain description."
|
|
161
179
|
),
|
|
162
180
|
// Fallback body input. A plain string is something every model can produce
|
|
@@ -190,53 +208,53 @@ const K = [
|
|
|
190
208
|
trial_requires_payment_method: i.boolean().default(!1),
|
|
191
209
|
translationGroupId: i.string().trim().min(1).max(120).optional(),
|
|
192
210
|
upc: i.string().max(120).nullable().optional()
|
|
193
|
-
}),
|
|
211
|
+
}), xe = W.extend({
|
|
194
212
|
currencyCode: i.string().trim().min(3).max(3).optional(),
|
|
195
213
|
endsAt: i.string().max(80).nullable().optional(),
|
|
196
214
|
field: i.string().trim().min(1).max(120),
|
|
197
215
|
startsAt: i.string().max(80).nullable().optional(),
|
|
198
216
|
value: i.unknown()
|
|
199
|
-
}),
|
|
200
|
-
i.strictObject({ input:
|
|
201
|
-
i.strictObject({ input:
|
|
202
|
-
i.strictObject({ input:
|
|
203
|
-
i.strictObject({ input:
|
|
204
|
-
i.strictObject({ input:
|
|
205
|
-
i.strictObject({ input:
|
|
206
|
-
i.strictObject({ input:
|
|
207
|
-
i.strictObject({ input:
|
|
208
|
-
i.strictObject({ input:
|
|
209
|
-
i.strictObject({ input:
|
|
210
|
-
i.strictObject({ input:
|
|
211
|
-
i.strictObject({ input:
|
|
212
|
-
]),
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
]),
|
|
226
|
-
const n =
|
|
217
|
+
}), wt = W, Ce = W, kt = i.discriminatedUnion("tool", [
|
|
218
|
+
i.strictObject({ input: ke, tool: i.literal("create_cms_page") }),
|
|
219
|
+
i.strictObject({ input: Ie, tool: i.literal("create_cms_post") }),
|
|
220
|
+
i.strictObject({ input: Te, tool: i.literal("create_cms_product") }),
|
|
221
|
+
i.strictObject({ input: Ce, tool: i.literal("delete_cms_item") }),
|
|
222
|
+
i.strictObject({ input: xe, tool: i.literal("update_cms_item_field") }),
|
|
223
|
+
i.strictObject({ input: ye, tool: i.literal("update_content_block") }),
|
|
224
|
+
i.strictObject({ input: we, tool: i.literal("insert_content_block") }),
|
|
225
|
+
i.strictObject({ input: he, tool: i.literal("update_current_cms_fields") }),
|
|
226
|
+
i.strictObject({ input: fe, tool: i.literal("update_footer") }),
|
|
227
|
+
i.strictObject({ input: ge, tool: i.literal("update_navigation_bar") }),
|
|
228
|
+
i.strictObject({ input: _e, tool: i.literal("update_section_column_block") }),
|
|
229
|
+
i.strictObject({ input: be, tool: i.literal("set_content_images") })
|
|
230
|
+
]), gn = i.union([
|
|
231
|
+
ke.extend({ tool: i.literal("create_cms_page") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
|
|
232
|
+
Ie.extend({ tool: i.literal("create_cms_post") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
|
|
233
|
+
Te.extend({ tool: i.literal("create_cms_product") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
|
|
234
|
+
Ce.extend({ tool: i.literal("delete_cms_item") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
|
|
235
|
+
xe.extend({ tool: i.literal("update_cms_item_field") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
|
|
236
|
+
ye.extend({ tool: i.literal("update_content_block") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
|
|
237
|
+
we.extend({ tool: i.literal("insert_content_block") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
|
|
238
|
+
he.extend({ tool: i.literal("update_current_cms_fields") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
|
|
239
|
+
fe.extend({ tool: i.literal("update_footer") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
|
|
240
|
+
ge.extend({ tool: i.literal("update_navigation_bar") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
|
|
241
|
+
_e.extend({ tool: i.literal("update_section_column_block") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e })),
|
|
242
|
+
be.extend({ tool: i.literal("set_content_images") }).transform(({ tool: e, ...t }) => ({ input: t, tool: e }))
|
|
243
|
+
]), fn = i.string().transform((e, t) => {
|
|
244
|
+
const n = wn(e);
|
|
227
245
|
return n.success ? n.action : (t.addIssue({
|
|
228
246
|
code: "custom",
|
|
229
247
|
message: n.message
|
|
230
248
|
}), i.NEVER);
|
|
231
|
-
}),
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
]),
|
|
236
|
-
actions: i.array(
|
|
249
|
+
}), hn = i.union([
|
|
250
|
+
kt,
|
|
251
|
+
gn,
|
|
252
|
+
fn
|
|
253
|
+
]), It = i.strictObject({
|
|
254
|
+
actions: i.array(hn).min(1).max(8),
|
|
237
255
|
summary: i.string().trim().min(1).max(500).optional()
|
|
238
256
|
});
|
|
239
|
-
function
|
|
257
|
+
function yn(e) {
|
|
240
258
|
const t = [];
|
|
241
259
|
let n = "", r = 0, o = null, a = !1;
|
|
242
260
|
for (const s of e) {
|
|
@@ -264,7 +282,7 @@ function fn(e) {
|
|
|
264
282
|
}
|
|
265
283
|
return n.trim() && t.push(n.trim()), t;
|
|
266
284
|
}
|
|
267
|
-
function
|
|
285
|
+
function et(e) {
|
|
268
286
|
let t = "";
|
|
269
287
|
for (let n = 0; n < e.length; n++) {
|
|
270
288
|
const r = e[n];
|
|
@@ -291,24 +309,24 @@ function Qe(e) {
|
|
|
291
309
|
}
|
|
292
310
|
return t.replace(/\bTrue\b/g, "true").replace(/\bFalse\b/g, "false").replace(/\bNone\b/g, "null");
|
|
293
311
|
}
|
|
294
|
-
function
|
|
312
|
+
function _n(e) {
|
|
295
313
|
const t = e.trim();
|
|
296
|
-
return t.startsWith("'") && t.endsWith("'") || t.startsWith('"') && t.endsWith('"') || t.startsWith("[") || t.startsWith("{") ? JSON.parse(
|
|
314
|
+
return t.startsWith("'") && t.endsWith("'") || t.startsWith('"') && t.endsWith('"') || t.startsWith("[") || t.startsWith("{") ? JSON.parse(et(t)) : /^-?\d+(?:\.\d+)?$/.test(t) ? Number(t) : t === "true" || t === "True" ? !0 : t === "false" || t === "False" ? !1 : t === "null" || t === "None" ? null : t;
|
|
297
315
|
}
|
|
298
|
-
function
|
|
316
|
+
function bn(e) {
|
|
299
317
|
const t = {};
|
|
300
|
-
for (const n of
|
|
318
|
+
for (const n of yn(e)) {
|
|
301
319
|
const r = n.indexOf("=");
|
|
302
320
|
if (r <= 0)
|
|
303
321
|
throw new Error(`Expected key=value argument, received "${n}".`);
|
|
304
322
|
const o = n.slice(0, r).trim();
|
|
305
323
|
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(o))
|
|
306
324
|
throw new Error(`Invalid argument name "${o}".`);
|
|
307
|
-
t[o] =
|
|
325
|
+
t[o] = _n(n.slice(r + 1));
|
|
308
326
|
}
|
|
309
327
|
return t;
|
|
310
328
|
}
|
|
311
|
-
function
|
|
329
|
+
function wn(e) {
|
|
312
330
|
const n = e.trim().match(/^([a-z_]+)\(([\s\S]*)\)$/);
|
|
313
331
|
if (!n)
|
|
314
332
|
return {
|
|
@@ -318,37 +336,37 @@ function _n(e) {
|
|
|
318
336
|
const r = n[1];
|
|
319
337
|
let o;
|
|
320
338
|
try {
|
|
321
|
-
o =
|
|
322
|
-
} catch (
|
|
339
|
+
o = bn(n[2]);
|
|
340
|
+
} catch (c) {
|
|
323
341
|
return {
|
|
324
|
-
message:
|
|
342
|
+
message: c instanceof Error ? c.message : "Could not parse action-plan command arguments.",
|
|
325
343
|
success: !1
|
|
326
344
|
};
|
|
327
345
|
}
|
|
328
|
-
const a = { input: o, tool: r }, s =
|
|
346
|
+
const a = { input: o, tool: r }, s = kt.safeParse(a);
|
|
329
347
|
return s.success ? {
|
|
330
348
|
action: s.data,
|
|
331
349
|
success: !0
|
|
332
350
|
} : {
|
|
333
|
-
message: `Invalid action-plan command "${r}": ${s.error.issues.map((
|
|
351
|
+
message: `Invalid action-plan command "${r}": ${s.error.issues.map((c) => c.message).join("; ")}`,
|
|
334
352
|
success: !1
|
|
335
353
|
};
|
|
336
354
|
}
|
|
337
|
-
function
|
|
355
|
+
function kn(e) {
|
|
338
356
|
return e.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/\s+/g, " ").trim();
|
|
339
357
|
}
|
|
340
|
-
function
|
|
358
|
+
function ie(e, t) {
|
|
341
359
|
return t.some((n) => e.includes(n));
|
|
342
360
|
}
|
|
343
|
-
function
|
|
344
|
-
const t =
|
|
361
|
+
function lo(e) {
|
|
362
|
+
const t = kn(e), n = ie(t, ["add ", "insert ", "put ", "create "]), r = ie(t, [
|
|
345
363
|
"title",
|
|
346
364
|
"heading",
|
|
347
365
|
"description",
|
|
348
366
|
"intro",
|
|
349
367
|
"copy",
|
|
350
368
|
"paragraph"
|
|
351
|
-
]), o = t.includes("form") &&
|
|
369
|
+
]), o = t.includes("form") && ie(t, ["above", "before"]), a = t.includes("contact page") || t.includes("contact pages") || t.includes("contact us") || t.includes("contactez-nous"), s = t.includes("english") && ie(t, ["french", "francais", "francaise"]);
|
|
352
370
|
return !n || !r || !o || !a || !s ? null : {
|
|
353
371
|
actions: [
|
|
354
372
|
{
|
|
@@ -385,12 +403,12 @@ function so(e) {
|
|
|
385
403
|
summary: "Add visible title and description copy above the forms on the English and French Contact pages."
|
|
386
404
|
};
|
|
387
405
|
}
|
|
388
|
-
const
|
|
406
|
+
const In = i.enum(V), tt = i.object({
|
|
389
407
|
direction: i.string().optional(),
|
|
390
408
|
stops: i.array(i.object({ color: i.string(), position: i.number() })),
|
|
391
409
|
type: i.enum(["linear", "radial"])
|
|
392
|
-
}),
|
|
393
|
-
gradient:
|
|
410
|
+
}), Tn = i.object({
|
|
411
|
+
gradient: tt.optional(),
|
|
394
412
|
image: i.object({
|
|
395
413
|
alt_text: i.string().optional(),
|
|
396
414
|
blur_data_url: i.string().optional(),
|
|
@@ -399,7 +417,7 @@ const kn = i.enum(K), Ze = i.object({
|
|
|
399
417
|
media_id: i.string().optional(),
|
|
400
418
|
object_key: i.string().optional(),
|
|
401
419
|
overlay: i.object({
|
|
402
|
-
gradient:
|
|
420
|
+
gradient: tt,
|
|
403
421
|
type: i.literal("gradient")
|
|
404
422
|
}).optional(),
|
|
405
423
|
position: i.enum(["center", "top", "bottom", "left", "right"]),
|
|
@@ -411,13 +429,13 @@ const kn = i.enum(K), Ze = i.object({
|
|
|
411
429
|
solid_color: i.string().optional(),
|
|
412
430
|
theme: i.enum(["primary", "secondary", "muted", "accent", "destructive"]).optional(),
|
|
413
431
|
type: i.enum(["none", "theme", "solid", "gradient", "image"])
|
|
414
|
-
}),
|
|
415
|
-
block_type:
|
|
432
|
+
}), xn = i.object({
|
|
433
|
+
block_type: In,
|
|
416
434
|
content: i.record(i.string(), i.any()),
|
|
417
435
|
temp_id: i.string().optional()
|
|
418
|
-
}),
|
|
419
|
-
background:
|
|
420
|
-
column_blocks: i.array(i.array(
|
|
436
|
+
}), Cn = i.object({
|
|
437
|
+
background: Tn,
|
|
438
|
+
column_blocks: i.array(i.array(xn)),
|
|
421
439
|
column_gap: i.enum(["none", "sm", "md", "lg", "xl"]),
|
|
422
440
|
container_type: i.enum(["full-width", "container", "container-sm", "container-lg", "container-xl"]),
|
|
423
441
|
padding: i.object({
|
|
@@ -430,7 +448,7 @@ const kn = i.enum(K), Ze = i.object({
|
|
|
430
448
|
tablet: i.union([i.literal(1), i.literal(2), i.literal(3)])
|
|
431
449
|
}),
|
|
432
450
|
vertical_alignment: i.enum(["start", "center", "end", "stretch"]).optional()
|
|
433
|
-
}),
|
|
451
|
+
}), vn = {
|
|
434
452
|
button: i.object({
|
|
435
453
|
position: i.enum(["left", "center", "right"]).optional(),
|
|
436
454
|
size: i.enum(["default", "sm", "lg", "full"]).optional(),
|
|
@@ -501,7 +519,7 @@ const kn = i.enum(K), Ze = i.object({
|
|
|
501
519
|
title: i.string().optional(),
|
|
502
520
|
type: i.enum(["latest", "category", "manual"]).default("latest")
|
|
503
521
|
}),
|
|
504
|
-
section:
|
|
522
|
+
section: Cn,
|
|
505
523
|
testimonial: i.object({
|
|
506
524
|
author_name: i.string().min(1),
|
|
507
525
|
author_title: i.string().optional(),
|
|
@@ -518,17 +536,17 @@ const kn = i.enum(K), Ze = i.object({
|
|
|
518
536
|
url: i.string()
|
|
519
537
|
})
|
|
520
538
|
};
|
|
521
|
-
function Cn(e) {
|
|
522
|
-
return K.includes(e);
|
|
523
|
-
}
|
|
524
539
|
function Sn(e) {
|
|
540
|
+
return V.includes(e);
|
|
541
|
+
}
|
|
542
|
+
function En(e) {
|
|
525
543
|
return typeof e?.validateBlockContent == "function" ? e.validateBlockContent : null;
|
|
526
544
|
}
|
|
527
|
-
function
|
|
528
|
-
const r =
|
|
545
|
+
function $n(e, t, n) {
|
|
546
|
+
const r = En(n);
|
|
529
547
|
if (r)
|
|
530
548
|
return r(e, t);
|
|
531
|
-
const o =
|
|
549
|
+
const o = vn[e].safeParse(t);
|
|
532
550
|
return o.success ? { errors: [], isValid: !0, warnings: [] } : {
|
|
533
551
|
errors: o.error.issues.map((a) => {
|
|
534
552
|
const s = a.path.join(".");
|
|
@@ -538,13 +556,13 @@ function vn(e, t, n) {
|
|
|
538
556
|
warnings: []
|
|
539
557
|
};
|
|
540
558
|
}
|
|
541
|
-
function
|
|
559
|
+
function nt() {
|
|
542
560
|
return i.object({
|
|
543
561
|
content: i.array(i.any()).optional(),
|
|
544
562
|
type: i.literal("doc")
|
|
545
563
|
});
|
|
546
564
|
}
|
|
547
|
-
function
|
|
565
|
+
function Re() {
|
|
548
566
|
try {
|
|
549
567
|
const { revalidatePath: e } = require("next/cache");
|
|
550
568
|
return e;
|
|
@@ -557,7 +575,7 @@ function C(e) {
|
|
|
557
575
|
throw new Error("A Supabase service client is required to execute Cortex AI global tools.");
|
|
558
576
|
return e.supabase;
|
|
559
577
|
}
|
|
560
|
-
function
|
|
578
|
+
function An(e, t, n) {
|
|
561
579
|
let r;
|
|
562
580
|
const o = new Promise((a) => {
|
|
563
581
|
r = setTimeout(() => a(n()), t);
|
|
@@ -569,38 +587,38 @@ function En(e, t, n) {
|
|
|
569
587
|
o
|
|
570
588
|
]);
|
|
571
589
|
}
|
|
572
|
-
function
|
|
573
|
-
const t =
|
|
590
|
+
function Y(e) {
|
|
591
|
+
const t = _t.safeParse(e?.pageContext);
|
|
574
592
|
if (!t.success)
|
|
575
593
|
throw new Error(
|
|
576
594
|
"No current CMS page context is available. Open a page, post, or product edit screen before using this editing tool."
|
|
577
595
|
);
|
|
578
596
|
return t.data;
|
|
579
597
|
}
|
|
580
|
-
function
|
|
598
|
+
function qe(e) {
|
|
581
599
|
const t = typeof e.entityId == "number" ? e.entityId : Number.parseInt(e.entityId, 10);
|
|
582
600
|
if (!Number.isInteger(t) || t <= 0)
|
|
583
601
|
throw new Error(`Current ${e.contentType} id must be a positive integer.`);
|
|
584
602
|
return t;
|
|
585
603
|
}
|
|
586
|
-
function
|
|
604
|
+
function Tt(e) {
|
|
587
605
|
const t = String(e.entityId || "").trim();
|
|
588
606
|
if (!t)
|
|
589
607
|
throw new Error(`Current ${e.contentType} id is missing.`);
|
|
590
608
|
return t;
|
|
591
609
|
}
|
|
592
|
-
function
|
|
593
|
-
return e.contentType === "product" ?
|
|
610
|
+
function q(e) {
|
|
611
|
+
return e.contentType === "product" ? Tt(e) : qe(e);
|
|
594
612
|
}
|
|
595
|
-
const
|
|
596
|
-
async function
|
|
613
|
+
const Pn = /^https?:\/\//i, Nn = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
614
|
+
async function ne(e, t, n) {
|
|
597
615
|
if (typeof e != "string")
|
|
598
616
|
return null;
|
|
599
617
|
const r = e.trim();
|
|
600
618
|
if (!r)
|
|
601
619
|
return null;
|
|
602
|
-
if (
|
|
603
|
-
if (
|
|
620
|
+
if (!Pn.test(r)) {
|
|
621
|
+
if (Nn.test(r))
|
|
604
622
|
return r;
|
|
605
623
|
throw new Error(
|
|
606
624
|
`"${r}" is not a usable image reference — provide an https:// image URL or a media library id.`
|
|
@@ -616,10 +634,10 @@ async function Z(e, t, n) {
|
|
|
616
634
|
throw new Error(`I could not import the image from that URL: ${a.error}`);
|
|
617
635
|
return a.id;
|
|
618
636
|
}
|
|
619
|
-
async function
|
|
637
|
+
async function xt(e, t, n) {
|
|
620
638
|
const r = [];
|
|
621
639
|
for (let o = 0; o < e.length; o += 1) {
|
|
622
|
-
const a = await
|
|
640
|
+
const a = await ne(
|
|
623
641
|
e[o],
|
|
624
642
|
t,
|
|
625
643
|
`${n} image ${o + 1}`
|
|
@@ -628,11 +646,11 @@ async function It(e, t, n) {
|
|
|
628
646
|
}
|
|
629
647
|
return r;
|
|
630
648
|
}
|
|
631
|
-
async function
|
|
649
|
+
async function Un(e) {
|
|
632
650
|
const t = [...new Set(e.mediaIds)], { error: n } = await e.supabase.from("product_media").delete().eq("product_id", e.productId);
|
|
633
651
|
if (n)
|
|
634
652
|
throw new Error(
|
|
635
|
-
`Could not clear the product's existing images: ${
|
|
653
|
+
`Could not clear the product's existing images: ${y(n)}`
|
|
636
654
|
);
|
|
637
655
|
if (t.length > 0) {
|
|
638
656
|
const { error: r } = await e.supabase.from("product_media").insert(
|
|
@@ -643,79 +661,79 @@ async function Pn(e) {
|
|
|
643
661
|
}))
|
|
644
662
|
);
|
|
645
663
|
if (r)
|
|
646
|
-
throw new Error(`Could not save the product images: ${
|
|
664
|
+
throw new Error(`Could not save the product images: ${y(r)}`);
|
|
647
665
|
}
|
|
648
666
|
return t;
|
|
649
667
|
}
|
|
650
|
-
async function
|
|
668
|
+
async function ve(e) {
|
|
651
669
|
if (!e.productId)
|
|
652
670
|
return !1;
|
|
653
671
|
const { data: t, error: n } = await e.supabase.from("product_drafts").select("id, blocks, meta").eq("product_id", e.productId).maybeSingle();
|
|
654
672
|
if (n || !t)
|
|
655
673
|
return !1;
|
|
656
674
|
const r = e.patch({
|
|
657
|
-
blocks: Array.isArray(t.blocks) ?
|
|
658
|
-
meta:
|
|
675
|
+
blocks: Array.isArray(t.blocks) ? K(t.blocks) : [],
|
|
676
|
+
meta: E(t.meta) ? K(t.meta) : {}
|
|
659
677
|
}), o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
660
678
|
if (r.blocks && (o.blocks = r.blocks), r.meta && (o.meta = r.meta), Object.keys(o).length === 1)
|
|
661
679
|
return !1;
|
|
662
680
|
const { error: a } = await e.supabase.from("product_drafts").update(o).eq("id", t.id);
|
|
663
681
|
if (a)
|
|
664
682
|
throw new Error(
|
|
665
|
-
`The product was updated, but its open draft could not be kept in sync: ${
|
|
683
|
+
`The product was updated, but its open draft could not be kept in sync: ${y(
|
|
666
684
|
a
|
|
667
685
|
)}. Publishing that draft would undo this change — publish or discard it in the product editor first.`
|
|
668
686
|
);
|
|
669
687
|
return !0;
|
|
670
688
|
}
|
|
671
|
-
function
|
|
689
|
+
function Ct(e) {
|
|
672
690
|
return typeof e == "string" ? e.trim().replace(/^\/+|\/+$/g, "") : "";
|
|
673
691
|
}
|
|
674
|
-
function
|
|
675
|
-
const n =
|
|
692
|
+
function On(e, t) {
|
|
693
|
+
const n = Ct(t ?? e.slug);
|
|
676
694
|
return n ? e.contentType === "page" ? n === "home" ? "/" : `/${n}` : e.contentType === "post" ? `/article/${n}` : `/product/${n}` : null;
|
|
677
695
|
}
|
|
678
|
-
function
|
|
696
|
+
function Fn(e) {
|
|
679
697
|
const t = String(e.entityId);
|
|
680
698
|
return e.contentType === "page" ? `/cms/pages/${t}/edit` : e.contentType === "post" ? `/cms/posts/${t}/edit` : `/cms/products/${t}/edit`;
|
|
681
699
|
}
|
|
682
|
-
function
|
|
683
|
-
const r = e?.revalidatePath ??
|
|
700
|
+
function O(e, t, n) {
|
|
701
|
+
const r = e?.revalidatePath ?? Re();
|
|
684
702
|
if (!r)
|
|
685
703
|
return;
|
|
686
|
-
r(
|
|
687
|
-
const o =
|
|
704
|
+
r(Fn(t));
|
|
705
|
+
const o = On(t, n);
|
|
688
706
|
o && r(o), t.contentType === "page" && o !== "/" && r("/"), t.contentType === "product" && r("/cms/products");
|
|
689
707
|
}
|
|
690
|
-
function
|
|
691
|
-
const t = e?.revalidatePath ??
|
|
708
|
+
function vt(e) {
|
|
709
|
+
const t = e?.revalidatePath ?? Re();
|
|
692
710
|
t && (t("/", "layout"), t("/cms/navigation"));
|
|
693
711
|
}
|
|
694
|
-
function
|
|
712
|
+
function y(e) {
|
|
695
713
|
return e ? typeof e == "object" && "message" in e ? String(e.message || "Unknown database error.") : String(e) : "Unknown database error.";
|
|
696
714
|
}
|
|
697
|
-
async function
|
|
715
|
+
async function jn() {
|
|
698
716
|
return import("./ai-global-agent-ecommerce.es.js");
|
|
699
717
|
}
|
|
700
|
-
function
|
|
701
|
-
return e === null || typeof e != "object" ? JSON.stringify(e) : Array.isArray(e) ? `[${e.map((t) =>
|
|
718
|
+
function Ae(e) {
|
|
719
|
+
return e === null || typeof e != "object" ? JSON.stringify(e) : Array.isArray(e) ? `[${e.map((t) => Ae(t)).join(",")}]` : `{${Object.keys(e).filter((t) => t !== "temp_id").sort().map((t) => `${JSON.stringify(t)}:${Ae(e[t])}`).join(",")}}`;
|
|
702
720
|
}
|
|
703
|
-
function
|
|
721
|
+
function Ln(e) {
|
|
704
722
|
let t = 2166136261;
|
|
705
|
-
const n =
|
|
723
|
+
const n = Ae(e);
|
|
706
724
|
for (let r = 0; r < n.length; r++)
|
|
707
725
|
t ^= n.charCodeAt(r), t = Math.imul(t, 16777619);
|
|
708
726
|
return (t >>> 0).toString(16).padStart(8, "0");
|
|
709
727
|
}
|
|
710
|
-
function
|
|
728
|
+
function Pe(e) {
|
|
711
729
|
return e.replace(/\s+/g, " ").trim().toUpperCase();
|
|
712
730
|
}
|
|
713
|
-
function
|
|
714
|
-
return `${
|
|
731
|
+
function Bn(e, t, n) {
|
|
732
|
+
return `${Pe(`CONFIRM ${e} ${t}`)} #${Ln(n)}`;
|
|
715
733
|
}
|
|
716
|
-
function
|
|
734
|
+
function St(e) {
|
|
717
735
|
return {
|
|
718
|
-
confirmationPhrase:
|
|
736
|
+
confirmationPhrase: Bn(
|
|
719
737
|
e.action,
|
|
720
738
|
e.subject,
|
|
721
739
|
e.payload
|
|
@@ -726,63 +744,63 @@ function Ct(e) {
|
|
|
726
744
|
success: !0
|
|
727
745
|
};
|
|
728
746
|
}
|
|
729
|
-
function
|
|
747
|
+
function F(e, t) {
|
|
730
748
|
const n = e[t];
|
|
731
749
|
return typeof n == "string" && n.trim() ? n.trim() : null;
|
|
732
750
|
}
|
|
733
|
-
function
|
|
751
|
+
function D(e, t) {
|
|
734
752
|
const n = Number(e[t]);
|
|
735
753
|
return Number.isFinite(n) ? n : null;
|
|
736
754
|
}
|
|
737
|
-
function
|
|
755
|
+
function U(e, t, n = `${t}s`) {
|
|
738
756
|
return `${e} ${e === 1 ? t : n}`;
|
|
739
757
|
}
|
|
740
|
-
function
|
|
741
|
-
const n =
|
|
758
|
+
function Rn(e, t) {
|
|
759
|
+
const n = F(t, "summary");
|
|
742
760
|
if (n)
|
|
743
761
|
return n;
|
|
744
|
-
const r =
|
|
762
|
+
const r = F(t, "title"), o = F(t, "slug"), a = F(t, "status"), s = F(t, "contentType"), c = F(t, "field"), u = F(t, "mode"), d = F(t, "languageCode"), l = D(t, "blockCount"), m = D(t, "itemCount"), h = D(t, "affectedCount");
|
|
745
763
|
if (e === "create_cms_page" || e === "create_cms_post")
|
|
746
|
-
return `Create ${a || "draft"} ${e === "create_cms_page" ? "page" : "post"} "${r || o || "Untitled"}"${o ? ` at slug "${o}"` : ""}${
|
|
764
|
+
return `Create ${a || "draft"} ${e === "create_cms_page" ? "page" : "post"} "${r || o || "Untitled"}"${o ? ` at slug "${o}"` : ""}${l !== null ? ` with ${U(l, "content block")}` : ""}.`;
|
|
747
765
|
if (e === "create_cms_product") {
|
|
748
|
-
const p =
|
|
749
|
-
p ?
|
|
750
|
-
|
|
766
|
+
const p = D(t, "imageCount"), f = D(t, "blockCount"), g = [
|
|
767
|
+
p ? U(p, "image") : null,
|
|
768
|
+
f ? U(f, "description block") : D(t, "descriptionLength") ? "a full description" : null
|
|
751
769
|
].filter(Boolean);
|
|
752
|
-
return `Create ${a || "draft"} product "${r || o || "Untitled"}"${o ? ` at slug "${o}"` : ""}${
|
|
770
|
+
return `Create ${a || "draft"} product "${r || o || "Untitled"}"${o ? ` at slug "${o}"` : ""}${g.length ? ` with ${g.join(" and ")}` : ""}.`;
|
|
753
771
|
}
|
|
754
772
|
if (e === "update_cms_item_field")
|
|
755
|
-
return `Update ${
|
|
773
|
+
return `Update ${c || "one field"} on the ${s || "CMS item"} "${r || o || "selected item"}".`;
|
|
756
774
|
if (e === "update_navigation_bar")
|
|
757
|
-
return `${u === "append" ? "Add" : u === "update" ? "Update" : "Replace"} ${m !== null ?
|
|
775
|
+
return `${u === "append" ? "Add" : u === "update" ? "Update" : "Replace"} ${m !== null ? U(m, "navigation item") : "navigation items"} in the ${d || "selected"} header navigation.`;
|
|
758
776
|
if (e === "update_footer") {
|
|
759
|
-
const p =
|
|
760
|
-
return `Update the ${d || "selected"} footer${p !== null ? ` with ${
|
|
777
|
+
const p = D(t, "linkCount");
|
|
778
|
+
return `Update the ${d || "selected"} footer${p !== null ? ` with ${U(p, "link")}` : ""}.`;
|
|
761
779
|
}
|
|
762
|
-
return e === "update_content_block" ? `Update the selected ${
|
|
780
|
+
return e === "update_content_block" ? `Update the selected ${F(t, "blockType") || "content"} block.` : e === "insert_content_block" ? `Insert ${F(t, "blockType") || "content"} block on the ${s || "CMS item"} "${r || o || "selected item"}".` : e === "update_section_column_block" ? `Update the selected nested ${F(t, "nestedBlockType") || "section"} block.` : e === "delete_cms_item" || e === "prepare_delete_cms_item" ? `Delete ${h !== null ? U(h, s || "CMS item") : `the selected ${s || "CMS item"}`}${r || o ? ` for "${r || o}"` : ""}.` : "Complete the requested CMS change.";
|
|
763
781
|
}
|
|
764
|
-
function
|
|
782
|
+
function N(e) {
|
|
765
783
|
if (e.context?.skipConfirmation)
|
|
766
784
|
return null;
|
|
767
|
-
const t =
|
|
785
|
+
const t = St(e), n = Pe(e.context?.latestUserMessage || ""), r = Pe(t.confirmationPhrase);
|
|
768
786
|
return n.includes(r) ? null : t;
|
|
769
787
|
}
|
|
770
|
-
function
|
|
788
|
+
function Me(e) {
|
|
771
789
|
const t = e?.actorUserId;
|
|
772
790
|
if (!t)
|
|
773
791
|
throw new Error("A confirmed CMS mutation requires an authenticated admin actor.");
|
|
774
792
|
return t;
|
|
775
793
|
}
|
|
776
|
-
function
|
|
794
|
+
function De() {
|
|
777
795
|
return globalThis.crypto?.randomUUID?.() || `id-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
778
796
|
}
|
|
779
|
-
function
|
|
797
|
+
function M(e) {
|
|
780
798
|
return e.toLowerCase().trim().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "").replace(/-+/g, "-").replace(/^-|-$/g, "").slice(0, 300);
|
|
781
799
|
}
|
|
782
|
-
function
|
|
800
|
+
function ze(e) {
|
|
783
801
|
return (e || "USD").trim().toUpperCase();
|
|
784
802
|
}
|
|
785
|
-
const
|
|
803
|
+
const qn = /* @__PURE__ */ new Set([
|
|
786
804
|
"BIF",
|
|
787
805
|
"CLP",
|
|
788
806
|
"DJF",
|
|
@@ -800,131 +818,131 @@ const Bn = /* @__PURE__ */ new Set([
|
|
|
800
818
|
"XOF",
|
|
801
819
|
"XPF"
|
|
802
820
|
]);
|
|
803
|
-
function
|
|
804
|
-
return
|
|
821
|
+
function Mn(e) {
|
|
822
|
+
return qn.has(ze(e)) ? 0 : 2;
|
|
805
823
|
}
|
|
806
|
-
function
|
|
807
|
-
return Math.round(e * 10 **
|
|
824
|
+
function Et(e, t) {
|
|
825
|
+
return Math.round(e * 10 ** Mn(t));
|
|
808
826
|
}
|
|
809
|
-
function
|
|
827
|
+
function Dn(e, t) {
|
|
810
828
|
return !e || typeof e != "object" || Array.isArray(e) ? {} : Object.entries(e).reduce(
|
|
811
829
|
(n, [r, o]) => {
|
|
812
830
|
if (typeof o == "number" && Number.isFinite(o) && o >= 0) {
|
|
813
|
-
const a =
|
|
814
|
-
n[a] =
|
|
831
|
+
const a = ze(r || t);
|
|
832
|
+
n[a] = Et(o, a);
|
|
815
833
|
}
|
|
816
834
|
return n;
|
|
817
835
|
},
|
|
818
836
|
{}
|
|
819
837
|
);
|
|
820
838
|
}
|
|
821
|
-
function
|
|
822
|
-
if (
|
|
839
|
+
function re(e, t) {
|
|
840
|
+
if (!E(e))
|
|
823
841
|
throw new Error(`${t} content must be a JSON object.`);
|
|
824
842
|
return JSON.parse(JSON.stringify(e));
|
|
825
843
|
}
|
|
826
|
-
function
|
|
844
|
+
function K(e) {
|
|
827
845
|
return JSON.parse(JSON.stringify(e));
|
|
828
846
|
}
|
|
829
|
-
function
|
|
847
|
+
function E(e) {
|
|
830
848
|
return !!(e && typeof e == "object" && !Array.isArray(e));
|
|
831
849
|
}
|
|
832
|
-
function
|
|
833
|
-
const n =
|
|
850
|
+
function Ne(e, t) {
|
|
851
|
+
const n = K(e);
|
|
834
852
|
for (const [r, o] of Object.entries(t))
|
|
835
853
|
if (o !== void 0) {
|
|
836
|
-
if (
|
|
837
|
-
n[r] =
|
|
854
|
+
if (E(o) && E(n[r])) {
|
|
855
|
+
n[r] = Ne(n[r], o);
|
|
838
856
|
continue;
|
|
839
857
|
}
|
|
840
|
-
n[r] =
|
|
858
|
+
n[r] = K(o);
|
|
841
859
|
}
|
|
842
860
|
return n;
|
|
843
861
|
}
|
|
844
|
-
function
|
|
862
|
+
function $t(e, t) {
|
|
845
863
|
if (t.contentType === "product") {
|
|
846
|
-
if (String(e.product_id ?? "") !== String(
|
|
864
|
+
if (String(e.product_id ?? "") !== String(Tt(t)))
|
|
847
865
|
throw new Error(`Block ${e.id} does not belong to the current product being edited.`);
|
|
848
866
|
return;
|
|
849
867
|
}
|
|
850
|
-
const n =
|
|
868
|
+
const n = qe(t);
|
|
851
869
|
if ((t.contentType === "page" ? Number(e.page_id) : Number(e.post_id)) !== n)
|
|
852
870
|
throw new Error(
|
|
853
871
|
`Block ${e.id} does not belong to the current ${t.contentType} being edited.`
|
|
854
872
|
);
|
|
855
873
|
}
|
|
856
|
-
function
|
|
874
|
+
function le(e, t) {
|
|
857
875
|
const n = typeof e == "string" ? e : "";
|
|
858
|
-
if (!
|
|
876
|
+
if (!Sn(n))
|
|
859
877
|
throw new Error(`${t} has unsupported block type "${n || "unknown"}".`);
|
|
860
878
|
return n;
|
|
861
879
|
}
|
|
862
|
-
function
|
|
880
|
+
function At(e, t, n) {
|
|
863
881
|
if (e && e !== t)
|
|
864
882
|
throw new Error(
|
|
865
883
|
`${n} is a "${t}" block. Refusing to update it as "${e}".`
|
|
866
884
|
);
|
|
867
885
|
}
|
|
868
|
-
function
|
|
869
|
-
const o =
|
|
886
|
+
function z(e, t, n, r) {
|
|
887
|
+
const o = $n(e, t, r);
|
|
870
888
|
if (!o.isValid)
|
|
871
889
|
throw new Error(
|
|
872
890
|
`${n} content is invalid for block type "${e}": ${o.errors.join("; ")}`
|
|
873
891
|
);
|
|
874
892
|
}
|
|
875
|
-
function
|
|
893
|
+
function Pt(e) {
|
|
876
894
|
return e === "section";
|
|
877
895
|
}
|
|
878
|
-
function
|
|
896
|
+
function zn(e) {
|
|
879
897
|
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 || "external_url" 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;
|
|
880
898
|
}
|
|
881
|
-
function
|
|
899
|
+
function ue(e) {
|
|
882
900
|
return `ai-${e}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
883
901
|
}
|
|
884
|
-
function
|
|
885
|
-
if (
|
|
902
|
+
function Ue(e, t, n) {
|
|
903
|
+
if (!E(e))
|
|
886
904
|
throw new Error(`${t} must be a JSON object.`);
|
|
887
|
-
const r = e.block_type ?? e.blockType, o =
|
|
888
|
-
if (
|
|
905
|
+
const r = e.block_type ?? e.blockType, o = le(r, t);
|
|
906
|
+
if (Pt(o))
|
|
889
907
|
throw new Error(`${t} cannot be a nested ${o} block.`);
|
|
890
|
-
const a =
|
|
908
|
+
const a = Ft(
|
|
891
909
|
o,
|
|
892
|
-
|
|
910
|
+
re(e.content, t),
|
|
893
911
|
t,
|
|
894
912
|
n
|
|
895
|
-
), s = e.temp_id ?? e.tempId,
|
|
913
|
+
), s = e.temp_id ?? e.tempId, c = typeof s == "string" && s.trim() ? s : ue(o);
|
|
896
914
|
return {
|
|
897
915
|
block_type: o,
|
|
898
916
|
content: a,
|
|
899
|
-
temp_id:
|
|
917
|
+
temp_id: c
|
|
900
918
|
};
|
|
901
919
|
}
|
|
902
|
-
function
|
|
920
|
+
function Gn(e, t) {
|
|
903
921
|
const n = [];
|
|
904
|
-
if ("append_block" in e && n.push(
|
|
922
|
+
if ("append_block" in e && n.push(Ue(e.append_block, "Nested block to append", t)), "append_blocks" in e) {
|
|
905
923
|
const r = e.append_blocks;
|
|
906
924
|
if (!Array.isArray(r))
|
|
907
925
|
throw new Error("append_blocks must be an array of nested block objects.");
|
|
908
926
|
r.forEach((o, a) => {
|
|
909
|
-
n.push(
|
|
927
|
+
n.push(Ue(o, `Nested block to append ${a}`, t));
|
|
910
928
|
});
|
|
911
929
|
}
|
|
912
930
|
return n;
|
|
913
931
|
}
|
|
914
|
-
function
|
|
932
|
+
function Kn(e, t) {
|
|
915
933
|
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)
|
|
916
934
|
return null;
|
|
917
|
-
const n =
|
|
935
|
+
const n = zn(e);
|
|
918
936
|
if (!n)
|
|
919
937
|
return null;
|
|
920
|
-
const r =
|
|
921
|
-
return
|
|
938
|
+
const r = re(e, `Nested ${n} block`);
|
|
939
|
+
return z(n, r, `Nested ${n} block`, t), {
|
|
922
940
|
block_type: n,
|
|
923
941
|
content: r,
|
|
924
|
-
temp_id:
|
|
942
|
+
temp_id: ue(n)
|
|
925
943
|
};
|
|
926
944
|
}
|
|
927
|
-
function
|
|
945
|
+
function Hn(e, t) {
|
|
928
946
|
const n = e.append_column_index ?? e.column_index;
|
|
929
947
|
if (n === void 0)
|
|
930
948
|
return 0;
|
|
@@ -936,24 +954,24 @@ function Gn(e, t) {
|
|
|
936
954
|
);
|
|
937
955
|
return n;
|
|
938
956
|
}
|
|
939
|
-
function
|
|
940
|
-
if (
|
|
941
|
-
return
|
|
942
|
-
const o = { ...n }, a =
|
|
957
|
+
function Vn(e, t, n, r) {
|
|
958
|
+
if (!Pt(e))
|
|
959
|
+
return Ne(t, n);
|
|
960
|
+
const o = { ...n }, a = Gn(o, r), s = Kn(o, r);
|
|
943
961
|
s && a.push(s), delete o.append_block, delete o.append_blocks, delete o.append_column_index, delete o.column_index;
|
|
944
|
-
const
|
|
962
|
+
const c = Ne(t, o);
|
|
945
963
|
if (a.length > 0) {
|
|
946
|
-
const u = Array.isArray(t.column_blocks) ?
|
|
947
|
-
for (;
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
...
|
|
964
|
+
const u = Array.isArray(t.column_blocks) ? K(t.column_blocks) : [], d = Hn(n, u.length), l = u.length > 0 ? u : [[]];
|
|
965
|
+
for (; l.length <= d; )
|
|
966
|
+
l.push([]);
|
|
967
|
+
l[d] = [
|
|
968
|
+
...l[d] || [],
|
|
951
969
|
...a
|
|
952
|
-
],
|
|
970
|
+
], c.column_blocks = l;
|
|
953
971
|
}
|
|
954
|
-
return
|
|
972
|
+
return c;
|
|
955
973
|
}
|
|
956
|
-
function
|
|
974
|
+
function Jn(e, t) {
|
|
957
975
|
return {
|
|
958
976
|
blockType: e.block_type,
|
|
959
977
|
content: t ? e.content : void 0,
|
|
@@ -964,30 +982,30 @@ function Hn(e, t) {
|
|
|
964
982
|
postId: e.post_id
|
|
965
983
|
};
|
|
966
984
|
}
|
|
967
|
-
function
|
|
985
|
+
function H(e) {
|
|
968
986
|
return typeof e == "string" ? e.trim().toLowerCase() : "";
|
|
969
987
|
}
|
|
970
|
-
function
|
|
988
|
+
function rt(e) {
|
|
971
989
|
return typeof e == "string" ? e.trim().toLowerCase() : "";
|
|
972
990
|
}
|
|
973
|
-
function
|
|
991
|
+
function Nt(e) {
|
|
974
992
|
return e.reduce((t, n) => t + 1 + (n.children?.length || 0), 0);
|
|
975
993
|
}
|
|
976
|
-
function
|
|
994
|
+
function ce(e) {
|
|
977
995
|
return typeof e == "string" ? e.trim().toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "") : "";
|
|
978
996
|
}
|
|
979
|
-
async function
|
|
980
|
-
const n = t.trim(), r =
|
|
997
|
+
async function X(e, t) {
|
|
998
|
+
const n = t.trim(), r = ce(n), o = dn[r], { data: a, error: s } = await e.from("languages").select("id, code, name, is_active");
|
|
981
999
|
if (s)
|
|
982
|
-
throw new Error(`Failed to load language "${t}": ${
|
|
983
|
-
const u = (Array.isArray(a) ? a : []).filter((
|
|
984
|
-
const m =
|
|
1000
|
+
throw new Error(`Failed to load language "${t}": ${y(s)}`);
|
|
1001
|
+
const u = (Array.isArray(a) ? a : []).filter((l) => l.is_active !== !1), d = u.find((l) => {
|
|
1002
|
+
const m = ce(l.code), h = ce(l.name);
|
|
985
1003
|
return m === r || m === o || h === r;
|
|
986
1004
|
});
|
|
987
1005
|
if (!d?.id || !d?.code) {
|
|
988
|
-
const
|
|
1006
|
+
const l = u.map((m) => m.code).filter(Boolean).join(", ");
|
|
989
1007
|
throw new Error(
|
|
990
|
-
`Language "${t}" was not found.${
|
|
1008
|
+
`Language "${t}" was not found.${l ? ` Available languages: ${l}.` : ""}`
|
|
991
1009
|
);
|
|
992
1010
|
}
|
|
993
1011
|
return {
|
|
@@ -995,15 +1013,15 @@ async function J(e, t) {
|
|
|
995
1013
|
id: Number(d.id)
|
|
996
1014
|
};
|
|
997
1015
|
}
|
|
998
|
-
async function
|
|
1016
|
+
async function Se(e, t) {
|
|
999
1017
|
if (t)
|
|
1000
|
-
return
|
|
1018
|
+
return X(e, t);
|
|
1001
1019
|
const { data: n, error: r } = await e.from("languages").select("id, code, name, is_active, is_default");
|
|
1002
1020
|
if (r)
|
|
1003
|
-
throw new Error(`Failed to load active languages: ${
|
|
1021
|
+
throw new Error(`Failed to load active languages: ${y(r)}`);
|
|
1004
1022
|
const o = (Array.isArray(n) ? n : []).filter(
|
|
1005
1023
|
(s) => s.is_active !== !1
|
|
1006
|
-
), a = o.find((s) => s.is_default) || o.find((s) =>
|
|
1024
|
+
), a = o.find((s) => s.is_default) || o.find((s) => ce(s.code) === "en") || o[0];
|
|
1007
1025
|
if (!a?.id || !a?.code)
|
|
1008
1026
|
throw new Error("No active CMS language is available for Cortex AI content creation.");
|
|
1009
1027
|
return {
|
|
@@ -1011,25 +1029,25 @@ async function Ce(e, t) {
|
|
|
1011
1029
|
id: Number(a.id)
|
|
1012
1030
|
};
|
|
1013
1031
|
}
|
|
1014
|
-
async function
|
|
1032
|
+
async function ot(e) {
|
|
1015
1033
|
try {
|
|
1016
1034
|
const { data: t, error: n } = await e.from("currencies").select("code, is_default, is_active").eq("is_active", !0);
|
|
1017
1035
|
if (n)
|
|
1018
1036
|
return "USD";
|
|
1019
1037
|
const r = Array.isArray(t) ? t : [], o = r.find((a) => a.is_default) || r[0];
|
|
1020
|
-
return
|
|
1038
|
+
return ze(o?.code || "USD");
|
|
1021
1039
|
} catch {
|
|
1022
1040
|
return "USD";
|
|
1023
1041
|
}
|
|
1024
1042
|
}
|
|
1025
|
-
async function
|
|
1043
|
+
async function Wn(e) {
|
|
1026
1044
|
const t = e.contentType === "page" ? "pages" : e.contentType === "post" ? "posts" : "products";
|
|
1027
1045
|
let n = "id", r = e.entityId;
|
|
1028
1046
|
if (r === void 0 && e.slug && (n = "slug", r = e.slug), r === void 0 && e.title && (n = "title", r = e.title), r === void 0)
|
|
1029
1047
|
throw new Error(`A ${e.contentType} target requires an id, slug, title, or current edit context.`);
|
|
1030
1048
|
const { data: o, error: a } = await e.supabase.from(t).select("*").eq(n, r);
|
|
1031
1049
|
if (a)
|
|
1032
|
-
throw new Error(`Failed to resolve ${e.contentType}: ${
|
|
1050
|
+
throw new Error(`Failed to resolve ${e.contentType}: ${y(a)}`);
|
|
1033
1051
|
const s = Array.isArray(o) ? o : o ? [o] : [];
|
|
1034
1052
|
if (s.length !== 1)
|
|
1035
1053
|
throw new Error(
|
|
@@ -1037,24 +1055,24 @@ async function Vn(e) {
|
|
|
1037
1055
|
);
|
|
1038
1056
|
return s[0];
|
|
1039
1057
|
}
|
|
1040
|
-
async function
|
|
1041
|
-
const n =
|
|
1058
|
+
async function oe(e, t) {
|
|
1059
|
+
const n = _t.safeParse(t?.pageContext).success ? t?.pageContext : null, r = e.contentType || n?.contentType;
|
|
1042
1060
|
if (!r)
|
|
1043
1061
|
throw new Error("Target contentType is required when no current CMS edit context exists.");
|
|
1044
|
-
const o = e.entityId !== void 0 || !!e.slug || !!e.title, a = e.entityId ?? (o ? void 0 : n?.entityId), s = e.slug ?? (o ? void 0 : n?.slug ?? void 0),
|
|
1062
|
+
const o = e.entityId !== void 0 || !!e.slug || !!e.title, a = e.entityId ?? (o ? void 0 : n?.entityId), s = e.slug ?? (o ? void 0 : n?.slug ?? void 0), c = e.title ?? (o ? void 0 : n?.title ?? void 0), u = await Wn({
|
|
1045
1063
|
contentType: r,
|
|
1046
1064
|
entityId: a,
|
|
1047
1065
|
slug: a === void 0 && s || void 0,
|
|
1048
1066
|
supabase: C(t),
|
|
1049
|
-
title: a === void 0 && !s &&
|
|
1067
|
+
title: a === void 0 && !s && c || void 0
|
|
1050
1068
|
});
|
|
1051
1069
|
return {
|
|
1052
1070
|
contentType: r,
|
|
1053
1071
|
item: u
|
|
1054
1072
|
};
|
|
1055
1073
|
}
|
|
1056
|
-
async function
|
|
1057
|
-
const t = await
|
|
1074
|
+
async function de(e) {
|
|
1075
|
+
const t = await Xn({
|
|
1058
1076
|
item: e.item,
|
|
1059
1077
|
languageId: e.languageId,
|
|
1060
1078
|
menuKey: e.menuKey,
|
|
@@ -1070,39 +1088,39 @@ async function le(e) {
|
|
|
1070
1088
|
url: e.item.url
|
|
1071
1089
|
}, { data: r, error: o } = await e.supabase.from("navigation_items").insert(n).select("id").single();
|
|
1072
1090
|
if (o)
|
|
1073
|
-
throw new Error(`Failed to insert ${e.menuKey} navigation item: ${
|
|
1091
|
+
throw new Error(`Failed to insert ${e.menuKey} navigation item: ${y(o)}`);
|
|
1074
1092
|
return Number(r.id);
|
|
1075
1093
|
}
|
|
1076
|
-
function
|
|
1094
|
+
function Yn(e) {
|
|
1077
1095
|
const t = e.trim();
|
|
1078
1096
|
if (!t.startsWith("/") || t.startsWith("//"))
|
|
1079
1097
|
return null;
|
|
1080
1098
|
const n = t.split("?")[0]?.split("#")[0] || "", r = n === "/" ? "home" : n.replace(/^\/+|\/+$/g, "");
|
|
1081
1099
|
return r && !r.includes("/") ? r : null;
|
|
1082
1100
|
}
|
|
1083
|
-
async function
|
|
1084
|
-
const t =
|
|
1101
|
+
async function Xn(e) {
|
|
1102
|
+
const t = Yn(e.item.url);
|
|
1085
1103
|
if (!t)
|
|
1086
1104
|
return null;
|
|
1087
1105
|
const { data: n, error: r } = await e.supabase.from("pages").select("id, slug, translation_group_id, language_id").eq("slug", t).eq("language_id", e.languageId);
|
|
1088
1106
|
if (r)
|
|
1089
|
-
throw new Error(`Failed to resolve linked page for navigation item: ${
|
|
1107
|
+
throw new Error(`Failed to resolve linked page for navigation item: ${y(r)}`);
|
|
1090
1108
|
const o = Array.isArray(n) ? n[0] : n;
|
|
1091
1109
|
if (!o?.id)
|
|
1092
1110
|
return null;
|
|
1093
|
-
let a =
|
|
1111
|
+
let a = De();
|
|
1094
1112
|
if (o.translation_group_id) {
|
|
1095
|
-
const { data: s, error:
|
|
1096
|
-
if (
|
|
1113
|
+
const { data: s, error: c } = await e.supabase.from("pages").select("id").eq("translation_group_id", o.translation_group_id);
|
|
1114
|
+
if (c)
|
|
1097
1115
|
throw new Error(
|
|
1098
|
-
`Failed to inspect linked page translations for navigation item: ${
|
|
1116
|
+
`Failed to inspect linked page translations for navigation item: ${y(c)}`
|
|
1099
1117
|
);
|
|
1100
1118
|
const u = new Set(
|
|
1101
1119
|
(Array.isArray(s) ? s : []).map((h) => String(h.id)).filter(Boolean)
|
|
1102
|
-
), { data: d, error:
|
|
1103
|
-
if (
|
|
1120
|
+
), { data: d, error: l } = await e.supabase.from("navigation_items").select("id, page_id, translation_group_id, menu_key").eq("menu_key", e.menuKey);
|
|
1121
|
+
if (l)
|
|
1104
1122
|
throw new Error(
|
|
1105
|
-
`Failed to inspect related navigation translations: ${
|
|
1123
|
+
`Failed to inspect related navigation translations: ${y(l)}`
|
|
1106
1124
|
);
|
|
1107
1125
|
const m = (Array.isArray(d) ? d : []).find((h) => h.translation_group_id && u.has(String(h.page_id)));
|
|
1108
1126
|
m?.translation_group_id && (a = m.translation_group_id);
|
|
@@ -1112,35 +1130,35 @@ async function Wn(e) {
|
|
|
1112
1130
|
pageId: Number(o.id)
|
|
1113
1131
|
};
|
|
1114
1132
|
}
|
|
1115
|
-
async function
|
|
1116
|
-
const t = await
|
|
1133
|
+
async function Ut(e) {
|
|
1134
|
+
const t = await X(e.supabase, e.languageCode), { data: n, error: r } = await e.supabase.from("navigation_items").select("id, parent_id").eq("menu_key", e.menuKey).eq("language_id", t.id);
|
|
1117
1135
|
if (r)
|
|
1118
1136
|
throw new Error(
|
|
1119
|
-
`Failed to inspect existing ${e.menuKey} navigation items: ${
|
|
1137
|
+
`Failed to inspect existing ${e.menuKey} navigation items: ${y(r)}`
|
|
1120
1138
|
);
|
|
1121
|
-
const o = Array.isArray(n) ? n : [], a = o.filter((d) => d.parent_id == null).length, s =
|
|
1122
|
-
|
|
1139
|
+
const o = Array.isArray(n) ? n : [], a = o.filter((d) => d.parent_id == null).length, s = Nt(e.items);
|
|
1140
|
+
Ot({
|
|
1123
1141
|
existingItemCount: o.length,
|
|
1124
1142
|
existingTopLevelCount: a,
|
|
1125
1143
|
languageCode: t.code,
|
|
1126
1144
|
menuKey: e.menuKey,
|
|
1127
1145
|
replacementItemCount: s
|
|
1128
1146
|
});
|
|
1129
|
-
const { error:
|
|
1130
|
-
if (
|
|
1131
|
-
throw new Error(`Failed to clear ${e.menuKey} navigation items: ${
|
|
1147
|
+
const { error: c } = await e.supabase.from("navigation_items").delete().eq("menu_key", e.menuKey).eq("language_id", t.id);
|
|
1148
|
+
if (c)
|
|
1149
|
+
throw new Error(`Failed to clear ${e.menuKey} navigation items: ${y(c)}`);
|
|
1132
1150
|
let u = 0;
|
|
1133
|
-
for (const [d,
|
|
1134
|
-
const m = await
|
|
1135
|
-
item:
|
|
1151
|
+
for (const [d, l] of e.items.entries()) {
|
|
1152
|
+
const m = await de({
|
|
1153
|
+
item: l,
|
|
1136
1154
|
languageId: t.id,
|
|
1137
1155
|
menuKey: e.menuKey,
|
|
1138
1156
|
order: d,
|
|
1139
1157
|
supabase: e.supabase
|
|
1140
1158
|
});
|
|
1141
1159
|
u++;
|
|
1142
|
-
for (const [h, p] of (
|
|
1143
|
-
await
|
|
1160
|
+
for (const [h, p] of (l.children ?? []).entries())
|
|
1161
|
+
await de({
|
|
1144
1162
|
item: p,
|
|
1145
1163
|
languageId: t.id,
|
|
1146
1164
|
menuKey: e.menuKey,
|
|
@@ -1157,37 +1175,37 @@ async function Pt(e) {
|
|
|
1157
1175
|
updatedCount: 0
|
|
1158
1176
|
};
|
|
1159
1177
|
}
|
|
1160
|
-
function
|
|
1178
|
+
function Ot(e) {
|
|
1161
1179
|
if (!(e.existingItemCount === 0 || e.replacementItemCount >= e.existingItemCount))
|
|
1162
1180
|
throw new Error(
|
|
1163
1181
|
`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.`
|
|
1164
1182
|
);
|
|
1165
1183
|
}
|
|
1166
|
-
async function
|
|
1167
|
-
const t = await
|
|
1184
|
+
async function Qn(e) {
|
|
1185
|
+
const t = await X(e.supabase, e.languageCode), { data: n, error: r } = await e.supabase.from("navigation_items").select("id, parent_id").eq("menu_key", e.menuKey).eq("language_id", t.id);
|
|
1168
1186
|
if (r)
|
|
1169
1187
|
throw new Error(
|
|
1170
|
-
`Failed to inspect existing ${e.menuKey} navigation items: ${
|
|
1188
|
+
`Failed to inspect existing ${e.menuKey} navigation items: ${y(r)}`
|
|
1171
1189
|
);
|
|
1172
1190
|
const o = Array.isArray(n) ? n : [];
|
|
1173
|
-
|
|
1191
|
+
Ot({
|
|
1174
1192
|
existingItemCount: o.length,
|
|
1175
1193
|
existingTopLevelCount: o.filter((a) => a.parent_id == null).length,
|
|
1176
1194
|
languageCode: t.code,
|
|
1177
1195
|
menuKey: e.menuKey,
|
|
1178
|
-
replacementItemCount:
|
|
1196
|
+
replacementItemCount: Nt(e.items)
|
|
1179
1197
|
});
|
|
1180
1198
|
}
|
|
1181
|
-
async function
|
|
1199
|
+
async function Zn(e) {
|
|
1182
1200
|
if (e.items.length !== 1)
|
|
1183
1201
|
throw new Error('mode "update" requires exactly one navigation item.');
|
|
1184
|
-
const t = await
|
|
1202
|
+
const t = await X(e.supabase, e.languageCode), n = e.items[0], r = H(e.match?.url) || H(n.url), o = rt(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", t.id);
|
|
1185
1203
|
if (s)
|
|
1186
1204
|
throw new Error(
|
|
1187
|
-
`Failed to load existing ${e.menuKey} navigation items: ${
|
|
1205
|
+
`Failed to load existing ${e.menuKey} navigation items: ${y(s)}`
|
|
1188
1206
|
);
|
|
1189
|
-
const u = (Array.isArray(a) ? a : []).find((
|
|
1190
|
-
const m =
|
|
1207
|
+
const u = (Array.isArray(a) ? a : []).find((l) => {
|
|
1208
|
+
const m = H(l.url), h = rt(l.label);
|
|
1191
1209
|
return !!(r && m === r || o && h === o);
|
|
1192
1210
|
});
|
|
1193
1211
|
if (!u?.id)
|
|
@@ -1199,7 +1217,7 @@ async function Xn(e) {
|
|
|
1199
1217
|
url: n.url
|
|
1200
1218
|
}).eq("id", u.id);
|
|
1201
1219
|
if (d)
|
|
1202
|
-
throw new Error(`Failed to update ${e.menuKey} navigation item: ${
|
|
1220
|
+
throw new Error(`Failed to update ${e.menuKey} navigation item: ${y(d)}`);
|
|
1203
1221
|
return {
|
|
1204
1222
|
insertedCount: 0,
|
|
1205
1223
|
languageCode: t.code,
|
|
@@ -1208,46 +1226,46 @@ async function Xn(e) {
|
|
|
1208
1226
|
updatedCount: 1
|
|
1209
1227
|
};
|
|
1210
1228
|
}
|
|
1211
|
-
async function
|
|
1212
|
-
const t = await
|
|
1229
|
+
async function er(e) {
|
|
1230
|
+
const t = await X(e.supabase, e.languageCode), { data: n, error: r } = await e.supabase.from("navigation_items").select("id, url, parent_id, order").eq("menu_key", e.menuKey).eq("language_id", t.id);
|
|
1213
1231
|
if (r)
|
|
1214
1232
|
throw new Error(
|
|
1215
|
-
`Failed to load existing ${e.menuKey} navigation items: ${
|
|
1233
|
+
`Failed to load existing ${e.menuKey} navigation items: ${y(r)}`
|
|
1216
1234
|
);
|
|
1217
1235
|
let o = 0, a = 0;
|
|
1218
|
-
const s = Array.isArray(n) ? n : [],
|
|
1219
|
-
s.map((
|
|
1220
|
-
), u = s.filter((
|
|
1236
|
+
const s = Array.isArray(n) ? n : [], c = new Set(
|
|
1237
|
+
s.map((l) => H(l.url)).filter(Boolean)
|
|
1238
|
+
), u = s.filter((l) => l.parent_id == null).map((l) => Number(l.order)).filter(Number.isFinite);
|
|
1221
1239
|
let d = u.length > 0 ? Math.max(...u) + 1 : s.length;
|
|
1222
|
-
for (const
|
|
1223
|
-
const m =
|
|
1224
|
-
if (m &&
|
|
1240
|
+
for (const l of e.items) {
|
|
1241
|
+
const m = H(l.url);
|
|
1242
|
+
if (m && c.has(m)) {
|
|
1225
1243
|
a++;
|
|
1226
1244
|
continue;
|
|
1227
1245
|
}
|
|
1228
|
-
const h = await
|
|
1229
|
-
item:
|
|
1246
|
+
const h = await de({
|
|
1247
|
+
item: l,
|
|
1230
1248
|
languageId: t.id,
|
|
1231
1249
|
menuKey: e.menuKey,
|
|
1232
1250
|
order: d,
|
|
1233
1251
|
supabase: e.supabase
|
|
1234
1252
|
});
|
|
1235
|
-
o++, d++, m &&
|
|
1253
|
+
o++, d++, m && c.add(m);
|
|
1236
1254
|
let p = 0;
|
|
1237
|
-
for (const
|
|
1238
|
-
const
|
|
1239
|
-
if (
|
|
1255
|
+
for (const f of l.children ?? []) {
|
|
1256
|
+
const g = H(f.url);
|
|
1257
|
+
if (g && c.has(g)) {
|
|
1240
1258
|
a++;
|
|
1241
1259
|
continue;
|
|
1242
1260
|
}
|
|
1243
|
-
await
|
|
1244
|
-
item:
|
|
1261
|
+
await de({
|
|
1262
|
+
item: f,
|
|
1245
1263
|
languageId: t.id,
|
|
1246
1264
|
menuKey: e.menuKey,
|
|
1247
1265
|
order: p,
|
|
1248
1266
|
parentId: h,
|
|
1249
1267
|
supabase: e.supabase
|
|
1250
|
-
}), o++, p++,
|
|
1268
|
+
}), o++, p++, g && c.add(g);
|
|
1251
1269
|
}
|
|
1252
1270
|
}
|
|
1253
1271
|
return {
|
|
@@ -1258,76 +1276,76 @@ async function Qn(e) {
|
|
|
1258
1276
|
updatedCount: 0
|
|
1259
1277
|
};
|
|
1260
1278
|
}
|
|
1261
|
-
function
|
|
1279
|
+
function S(e) {
|
|
1262
1280
|
return typeof e == "string" && e.trim() ? e.trim() : "";
|
|
1263
1281
|
}
|
|
1264
|
-
function
|
|
1282
|
+
function tr(e) {
|
|
1265
1283
|
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
1266
1284
|
}
|
|
1267
|
-
function
|
|
1268
|
-
const t =
|
|
1285
|
+
function nr(e) {
|
|
1286
|
+
const t = S(e.field_type ?? e.fieldType ?? e.type ?? e.input_type).toLowerCase().replace(/\s+/g, "_"), n = S(e.label ?? e.name ?? e.placeholder).toLowerCase();
|
|
1269
1287
|
return ["email", "textarea", "select", "radio", "checkbox", "text"].includes(t) ? t : n.includes("email") ? "email" : n.includes("message") || n.includes("comment") || n.includes("details") ? "textarea" : "text";
|
|
1270
1288
|
}
|
|
1271
|
-
function
|
|
1289
|
+
function rr(e) {
|
|
1272
1290
|
return (Array.isArray(e) && e.length > 0 ? e : [
|
|
1273
1291
|
{ field_type: "text", is_required: !0, label: "Name", placeholder: "Your name" },
|
|
1274
1292
|
{ field_type: "email", is_required: !0, label: "Email", placeholder: "you@example.com" },
|
|
1275
1293
|
{ field_type: "textarea", is_required: !0, label: "Message", placeholder: "How can we help?" }
|
|
1276
1294
|
]).map((n, r) => {
|
|
1277
|
-
const o =
|
|
1295
|
+
const o = E(n) ? n : {}, a = S(o.label ?? o.name) || (r === 0 ? "Name" : r === 1 ? "Email" : "Message"), s = nr({ ...o, label: a }), c = o.is_required ?? o.isRequired ?? o.required;
|
|
1278
1296
|
return {
|
|
1279
1297
|
field_type: s,
|
|
1280
|
-
is_required: typeof
|
|
1298
|
+
is_required: typeof c == "boolean" ? c : !0,
|
|
1281
1299
|
label: a,
|
|
1282
1300
|
options: Array.isArray(o.options) ? o.options : void 0,
|
|
1283
|
-
placeholder:
|
|
1284
|
-
temp_id:
|
|
1301
|
+
placeholder: S(o.placeholder) || void 0,
|
|
1302
|
+
temp_id: S(o.temp_id ?? o.tempId ?? o.id) || `field-${r + 1}`
|
|
1285
1303
|
};
|
|
1286
1304
|
});
|
|
1287
1305
|
}
|
|
1288
|
-
const
|
|
1306
|
+
const or = /* @__PURE__ */ new Set(["none", "sm", "md", "lg", "xl"]), it = /* @__PURE__ */ new Set(["none", "sm", "md", "lg", "xl"]), ir = /* @__PURE__ */ new Set([
|
|
1289
1307
|
"full-width",
|
|
1290
1308
|
"container",
|
|
1291
1309
|
"container-sm",
|
|
1292
1310
|
"container-lg",
|
|
1293
1311
|
"container-xl"
|
|
1294
|
-
]),
|
|
1295
|
-
function
|
|
1312
|
+
]), ar = /* @__PURE__ */ new Set(["start", "center", "end", "stretch"]), sr = /* @__PURE__ */ new Set(["none", "theme", "solid", "gradient", "image"]), cr = /* @__PURE__ */ new Set(["primary", "secondary", "muted", "accent", "destructive"]), lr = /* @__PURE__ */ new Set(["center", "top", "bottom", "left", "right"]);
|
|
1313
|
+
function ur(e) {
|
|
1296
1314
|
return typeof e == "string" && /^https?:\/\//i.test(e.trim());
|
|
1297
1315
|
}
|
|
1298
|
-
function
|
|
1316
|
+
function R(e, t, n) {
|
|
1299
1317
|
return typeof e == "string" && t.has(e) ? e : n;
|
|
1300
1318
|
}
|
|
1301
|
-
function
|
|
1319
|
+
function dr(e) {
|
|
1302
1320
|
return Number.isFinite(e) ? Math.min(4, Math.max(1, Math.round(e))) : 1;
|
|
1303
1321
|
}
|
|
1304
|
-
function
|
|
1322
|
+
function pr(e) {
|
|
1305
1323
|
const t = [
|
|
1306
1324
|
{ color: "#1e3a8a", position: 0 },
|
|
1307
1325
|
{ color: "#3b82f6", position: 100 }
|
|
1308
1326
|
];
|
|
1309
|
-
if (
|
|
1327
|
+
if (!E(e))
|
|
1310
1328
|
return { direction: "to bottom right", stops: t, type: "linear" };
|
|
1311
1329
|
const n = e.type === "radial" ? "radial" : "linear", r = Array.isArray(e.stops) && e.stops.length >= 2 ? e.stops : t;
|
|
1312
1330
|
return { direction: typeof e.direction == "string" && e.direction.trim() ? e.direction : n === "radial" ? "circle at center" : "to bottom right", stops: r, type: n };
|
|
1313
1331
|
}
|
|
1314
|
-
function
|
|
1315
|
-
if (
|
|
1332
|
+
function mr(e) {
|
|
1333
|
+
if (!E(e))
|
|
1316
1334
|
return { type: "none" };
|
|
1317
|
-
const t =
|
|
1335
|
+
const t = R(e.type, sr, "none"), n = typeof e.min_height == "string" && e.min_height.trim() ? { min_height: e.min_height } : {};
|
|
1318
1336
|
if (t === "theme")
|
|
1319
|
-
return { theme:
|
|
1337
|
+
return { theme: R(e.theme, cr, "muted"), type: t, ...n };
|
|
1320
1338
|
if (t === "solid")
|
|
1321
1339
|
return typeof e.solid_color == "string" && e.solid_color.trim() ? { solid_color: e.solid_color, type: t, ...n } : { type: "none" };
|
|
1322
1340
|
if (t === "gradient")
|
|
1323
|
-
return { gradient:
|
|
1341
|
+
return { gradient: pr(e.gradient), type: t, ...n };
|
|
1324
1342
|
if (t === "image") {
|
|
1325
|
-
const r =
|
|
1343
|
+
const r = E(e.image) ? e.image : null, o = r && ur(r.external_url) ? r.external_url.trim() : null, a = !!(r && typeof r.media_id == "string" && r.media_id.trim() && typeof r.object_key == "string" && r.object_key.trim());
|
|
1326
1344
|
return r && (o || a) ? {
|
|
1327
1345
|
image: {
|
|
1328
1346
|
...r,
|
|
1329
1347
|
...o ? { external_url: o } : {},
|
|
1330
|
-
position:
|
|
1348
|
+
position: R(r.position, lr, "center"),
|
|
1331
1349
|
size: r.size === "contain" ? "contain" : "cover"
|
|
1332
1350
|
},
|
|
1333
1351
|
type: t,
|
|
@@ -1336,47 +1354,47 @@ function dr(e) {
|
|
|
1336
1354
|
}
|
|
1337
1355
|
return { type: "none", ...n };
|
|
1338
1356
|
}
|
|
1339
|
-
function
|
|
1357
|
+
function gr(e, t, n) {
|
|
1340
1358
|
const r = e.is_hero === !0;
|
|
1341
1359
|
let o = Array.isArray(e.column_blocks) ? e.column_blocks : [];
|
|
1342
|
-
o.length > 0 && o.every((
|
|
1343
|
-
const a = o.map((
|
|
1344
|
-
(w,
|
|
1345
|
-
)), s = a.length > 0 ? a : [[]],
|
|
1360
|
+
o.length > 0 && o.every((g) => E(g) && !Array.isArray(g)) && (o = [o]);
|
|
1361
|
+
const a = o.map((g, b) => (Array.isArray(g) ? g : []).map(
|
|
1362
|
+
(w, k) => Ue(w, `${t} column ${b} block ${k}`, n)
|
|
1363
|
+
)), s = a.length > 0 ? a : [[]], c = dr(s.length), u = E(e.responsive_columns) ? e.responsive_columns : {}, d = Number(u.tablet), l = Number(u.mobile), m = Number.isFinite(d) ? Math.min(3, Math.max(1, Math.min(c, d))) : Math.min(3, c), h = Number.isFinite(l) ? Math.min(2, Math.max(1, l)) : 1, p = E(e.padding) ? e.padding : {}, f = {
|
|
1346
1364
|
...e,
|
|
1347
|
-
background:
|
|
1365
|
+
background: mr(e.background),
|
|
1348
1366
|
column_blocks: s,
|
|
1349
|
-
column_gap:
|
|
1350
|
-
container_type:
|
|
1367
|
+
column_gap: R(e.column_gap, or, "lg"),
|
|
1368
|
+
container_type: R(e.container_type, ir, "container"),
|
|
1351
1369
|
padding: {
|
|
1352
|
-
bottom:
|
|
1353
|
-
top:
|
|
1370
|
+
bottom: R(p.bottom, it, "xl"),
|
|
1371
|
+
top: R(p.top, it, "xl")
|
|
1354
1372
|
},
|
|
1355
|
-
responsive_columns: { desktop:
|
|
1356
|
-
vertical_alignment:
|
|
1373
|
+
responsive_columns: { desktop: c, mobile: h, tablet: m },
|
|
1374
|
+
vertical_alignment: R(
|
|
1357
1375
|
e.vertical_alignment,
|
|
1358
|
-
|
|
1376
|
+
ar,
|
|
1359
1377
|
r ? "center" : "start"
|
|
1360
1378
|
)
|
|
1361
1379
|
};
|
|
1362
|
-
return
|
|
1380
|
+
return f.slider === !0 && !(Array.isArray(f.slides) && f.slides.length > 0) && (f.slider = !1), f;
|
|
1363
1381
|
}
|
|
1364
|
-
function
|
|
1382
|
+
function Ft(e, t, n, r) {
|
|
1365
1383
|
if (e === "section") {
|
|
1366
|
-
const a =
|
|
1367
|
-
return
|
|
1384
|
+
const a = gr(t, n, r);
|
|
1385
|
+
return z(e, a, n, r), a;
|
|
1368
1386
|
}
|
|
1369
|
-
const o =
|
|
1370
|
-
if (e === "heading" && (o.text_content =
|
|
1371
|
-
const a =
|
|
1372
|
-
a && (o.html_content = /<\/?[a-z][\s\S]*>/i.test(a) ? a : `<p>${
|
|
1387
|
+
const o = K(t);
|
|
1388
|
+
if (e === "heading" && (o.text_content = S(o.text_content) || S(o.text) || S(o.title) || S(o.heading) || "Untitled", o.level = typeof o.level == "number" ? o.level : 1), e === "text") {
|
|
1389
|
+
const a = S(o.html_content) || S(o.html) || S(o.content) || S(o.text);
|
|
1390
|
+
a && (o.html_content = /<\/?[a-z][\s\S]*>/i.test(a) ? a : `<p>${tr(a)}</p>`);
|
|
1373
1391
|
}
|
|
1374
|
-
return e === "button" && (o.text =
|
|
1392
|
+
return e === "button" && (o.text = S(o.text) || S(o.label) || S(o.title) || "Learn More", o.url = S(o.url) || S(o.href) || S(o.link) || "#"), e === "form" && (o.fields = rr(o.fields), o.submit_button_text = S(o.submit_button_text ?? o.submitButtonText ?? o.button_text) || "Send Message", o.success_message = S(o.success_message ?? o.successMessage) || "Thanks for reaching out. We will reply as soon as possible."), z(e, o, n, r), o;
|
|
1375
1393
|
}
|
|
1376
|
-
function
|
|
1377
|
-
const r =
|
|
1394
|
+
function pe(e, t, n) {
|
|
1395
|
+
const r = Ft(
|
|
1378
1396
|
e.blockType,
|
|
1379
|
-
|
|
1397
|
+
re(e.content, `Block ${t}`),
|
|
1380
1398
|
`Block ${t}`,
|
|
1381
1399
|
n
|
|
1382
1400
|
);
|
|
@@ -1386,9 +1404,9 @@ function ce(e, t, n) {
|
|
|
1386
1404
|
order: e.order ?? t
|
|
1387
1405
|
};
|
|
1388
1406
|
}
|
|
1389
|
-
function
|
|
1407
|
+
function fr(e, t = "Contact Us", n) {
|
|
1390
1408
|
return [
|
|
1391
|
-
|
|
1409
|
+
pe(
|
|
1392
1410
|
{
|
|
1393
1411
|
blockType: "section",
|
|
1394
1412
|
content: {
|
|
@@ -1403,14 +1421,14 @@ function mr(e, t = "Contact Us", n) {
|
|
|
1403
1421
|
textAlign: "center",
|
|
1404
1422
|
text_content: t
|
|
1405
1423
|
},
|
|
1406
|
-
temp_id:
|
|
1424
|
+
temp_id: ue("heading")
|
|
1407
1425
|
},
|
|
1408
1426
|
{
|
|
1409
1427
|
block_type: "text",
|
|
1410
1428
|
content: {
|
|
1411
1429
|
html_content: "<p>Have a question, project, or support request? Send us a note and we will get back to you soon.</p>"
|
|
1412
1430
|
},
|
|
1413
|
-
temp_id:
|
|
1431
|
+
temp_id: ue("text")
|
|
1414
1432
|
}
|
|
1415
1433
|
]
|
|
1416
1434
|
],
|
|
@@ -1424,7 +1442,7 @@ function mr(e, t = "Contact Us", n) {
|
|
|
1424
1442
|
0,
|
|
1425
1443
|
n
|
|
1426
1444
|
),
|
|
1427
|
-
|
|
1445
|
+
pe(
|
|
1428
1446
|
{
|
|
1429
1447
|
blockType: "form",
|
|
1430
1448
|
content: {
|
|
@@ -1461,13 +1479,13 @@ function mr(e, t = "Contact Us", n) {
|
|
|
1461
1479
|
)
|
|
1462
1480
|
];
|
|
1463
1481
|
}
|
|
1464
|
-
function
|
|
1465
|
-
return (!e || e.length === 0) && t ?
|
|
1482
|
+
function Ee(e, t, n, r) {
|
|
1483
|
+
return (!e || e.length === 0) && t ? fr(t, n, r) : (e || []).map((o, a) => pe(o, a, r));
|
|
1466
1484
|
}
|
|
1467
|
-
async function
|
|
1485
|
+
async function Ge(e) {
|
|
1468
1486
|
const t = e.contentType === "page" ? "pages" : e.contentType === "post" ? "posts" : "products", { data: n, error: r } = await e.supabase.from(t).select("id, title, slug, language_id").eq("slug", e.slug).eq("language_id", e.languageId);
|
|
1469
1487
|
if (r)
|
|
1470
|
-
throw new Error(`Failed to check ${e.contentType} slug uniqueness: ${
|
|
1488
|
+
throw new Error(`Failed to check ${e.contentType} slug uniqueness: ${y(r)}`);
|
|
1471
1489
|
const o = Array.isArray(n) ? n : [];
|
|
1472
1490
|
return o.length > 0 ? {
|
|
1473
1491
|
duplicate: !0,
|
|
@@ -1477,7 +1495,7 @@ async function De(e) {
|
|
|
1477
1495
|
message: `A ${e.contentType} with slug "${e.slug}" already exists for this language.`
|
|
1478
1496
|
} : null;
|
|
1479
1497
|
}
|
|
1480
|
-
async function
|
|
1498
|
+
async function Ke(e) {
|
|
1481
1499
|
if (!e.suppliedTranslationGroupId)
|
|
1482
1500
|
return {
|
|
1483
1501
|
translationGroupId: void 0
|
|
@@ -1485,7 +1503,7 @@ async function ze(e) {
|
|
|
1485
1503
|
const t = e.contentType === "page" ? "pages" : e.contentType === "post" ? "posts" : "products", { data: n, error: r } = await e.supabase.from(t).select("id, title, slug, language_id, translation_group_id").eq("translation_group_id", e.suppliedTranslationGroupId);
|
|
1486
1504
|
if (r)
|
|
1487
1505
|
throw new Error(
|
|
1488
|
-
`Failed to inspect ${e.contentType} translation group: ${
|
|
1506
|
+
`Failed to inspect ${e.contentType} translation group: ${y(r)}`
|
|
1489
1507
|
);
|
|
1490
1508
|
const o = Array.isArray(n) ? n : [];
|
|
1491
1509
|
if (o.length === 0)
|
|
@@ -1513,7 +1531,7 @@ async function ze(e) {
|
|
|
1513
1531
|
translationGroupId: e.suppliedTranslationGroupId
|
|
1514
1532
|
};
|
|
1515
1533
|
}
|
|
1516
|
-
async function
|
|
1534
|
+
async function He(e) {
|
|
1517
1535
|
if (e.blocks.length === 0)
|
|
1518
1536
|
return [];
|
|
1519
1537
|
const t = e.blocks.map((o, a) => ({
|
|
@@ -1526,28 +1544,28 @@ async function Ge(e) {
|
|
|
1526
1544
|
product_id: e.contentType === "product" ? e.itemId : null
|
|
1527
1545
|
})), { data: n, error: r } = await e.supabase.from("blocks").insert(t).select("*");
|
|
1528
1546
|
if (r)
|
|
1529
|
-
throw new Error(`Failed to insert ${e.contentType} blocks: ${
|
|
1530
|
-
return
|
|
1547
|
+
throw new Error(`Failed to insert ${e.contentType} blocks: ${y(r)}`);
|
|
1548
|
+
return $e(e.blocks, e.supabase), Array.isArray(n) ? n : [];
|
|
1531
1549
|
}
|
|
1532
|
-
async function
|
|
1550
|
+
async function Ve(e) {
|
|
1533
1551
|
const t = e.contentType === "page" ? "pages" : e.contentType === "post" ? "posts" : "products";
|
|
1534
1552
|
await e.supabase.from(t).delete().eq("id", e.itemId);
|
|
1535
1553
|
}
|
|
1536
|
-
function
|
|
1554
|
+
function Je(e, t) {
|
|
1537
1555
|
return e === "page" ? `/cms/pages/${t}/edit` : e === "post" ? `/cms/posts/${t}/edit` : `/cms/products/${t}/edit`;
|
|
1538
1556
|
}
|
|
1539
|
-
function
|
|
1557
|
+
function at(e) {
|
|
1540
1558
|
return e === "page" ? "/cms/pages" : e === "post" ? "/cms/posts" : "/cms/products";
|
|
1541
1559
|
}
|
|
1542
|
-
async function
|
|
1543
|
-
const n =
|
|
1544
|
-
n.mode === "replace" && await
|
|
1560
|
+
async function jt(e, t) {
|
|
1561
|
+
const n = ge.parse(e), r = C(t);
|
|
1562
|
+
n.mode === "replace" && await Qn({
|
|
1545
1563
|
items: n.items,
|
|
1546
1564
|
languageCode: n.languageCode,
|
|
1547
1565
|
menuKey: "HEADER",
|
|
1548
1566
|
supabase: r
|
|
1549
1567
|
});
|
|
1550
|
-
const o =
|
|
1568
|
+
const o = N({
|
|
1551
1569
|
action: "UPDATE NAVIGATION",
|
|
1552
1570
|
context: t,
|
|
1553
1571
|
payload: { input: n, tool: "update_navigation_bar" },
|
|
@@ -1561,35 +1579,35 @@ async function Ot(e, t) {
|
|
|
1561
1579
|
});
|
|
1562
1580
|
if (o)
|
|
1563
1581
|
return o;
|
|
1564
|
-
const a = n.mode === "update" ? await
|
|
1582
|
+
const a = n.mode === "update" ? await Zn({
|
|
1565
1583
|
items: n.items,
|
|
1566
1584
|
languageCode: n.languageCode,
|
|
1567
1585
|
match: n.match,
|
|
1568
1586
|
menuKey: "HEADER",
|
|
1569
1587
|
supabase: r
|
|
1570
|
-
}) : n.mode === "append" ? await
|
|
1588
|
+
}) : n.mode === "append" ? await er({
|
|
1571
1589
|
items: n.items,
|
|
1572
1590
|
languageCode: n.languageCode,
|
|
1573
1591
|
menuKey: "HEADER",
|
|
1574
1592
|
supabase: r
|
|
1575
|
-
}) : await
|
|
1593
|
+
}) : await Ut({
|
|
1576
1594
|
items: n.items,
|
|
1577
1595
|
languageCode: n.languageCode,
|
|
1578
1596
|
menuKey: "HEADER",
|
|
1579
1597
|
supabase: r
|
|
1580
1598
|
});
|
|
1581
|
-
return
|
|
1599
|
+
return vt(t), {
|
|
1582
1600
|
...a,
|
|
1583
1601
|
mutationExecuted: !0,
|
|
1584
1602
|
mode: n.mode,
|
|
1585
1603
|
success: !0
|
|
1586
1604
|
};
|
|
1587
1605
|
}
|
|
1588
|
-
async function
|
|
1589
|
-
const n =
|
|
1606
|
+
async function Lt(e, t) {
|
|
1607
|
+
const n = fe.parse(e);
|
|
1590
1608
|
if (!n.links?.length && !n.copyright)
|
|
1591
1609
|
throw new Error("update_footer requires links or copyright.");
|
|
1592
|
-
const r = C(t), o =
|
|
1610
|
+
const r = C(t), o = N({
|
|
1593
1611
|
action: "UPDATE FOOTER",
|
|
1594
1612
|
context: t,
|
|
1595
1613
|
payload: { input: n, tool: "update_footer" },
|
|
@@ -1604,7 +1622,7 @@ async function Ft(e, t) {
|
|
|
1604
1622
|
if (o)
|
|
1605
1623
|
return o;
|
|
1606
1624
|
let a = null;
|
|
1607
|
-
if (n.links?.length && (a = await
|
|
1625
|
+
if (n.links?.length && (a = await Ut({
|
|
1608
1626
|
items: n.links,
|
|
1609
1627
|
languageCode: n.languageCode,
|
|
1610
1628
|
menuKey: "FOOTER",
|
|
@@ -1615,57 +1633,57 @@ async function Ft(e, t) {
|
|
|
1615
1633
|
value: n.copyright
|
|
1616
1634
|
});
|
|
1617
1635
|
if (s)
|
|
1618
|
-
throw new Error(`Failed to update footer copyright: ${
|
|
1636
|
+
throw new Error(`Failed to update footer copyright: ${y(s)}`);
|
|
1619
1637
|
}
|
|
1620
|
-
return
|
|
1638
|
+
return vt(t), {
|
|
1621
1639
|
copyrightUpdated: !!n.copyright,
|
|
1622
1640
|
footerNavigation: a,
|
|
1623
1641
|
mutationExecuted: !0,
|
|
1624
1642
|
success: !0
|
|
1625
1643
|
};
|
|
1626
1644
|
}
|
|
1627
|
-
function
|
|
1645
|
+
function Bt(e) {
|
|
1628
1646
|
return typeof e == "string" ? e.toLowerCase() : "";
|
|
1629
1647
|
}
|
|
1630
|
-
function
|
|
1631
|
-
const n = t.map(
|
|
1648
|
+
function hr(e, t) {
|
|
1649
|
+
const n = t.map(Bt).join(" ");
|
|
1632
1650
|
return e.reduce((r, o) => r + (n.includes(o) ? 1 : 0), 0);
|
|
1633
1651
|
}
|
|
1634
|
-
function
|
|
1652
|
+
function st(e, t) {
|
|
1635
1653
|
return (e.find(
|
|
1636
|
-
(n) => t.some((r) =>
|
|
1654
|
+
(n) => t.some((r) => Bt(n).includes(r))
|
|
1637
1655
|
) || e.find((n) => n.trim().length > 0) || "No excerpt available.").slice(0, 500);
|
|
1638
1656
|
}
|
|
1639
|
-
async function
|
|
1640
|
-
const n =
|
|
1657
|
+
async function yr(e, t) {
|
|
1658
|
+
const n = Be.parse(e), r = C(t), o = n.query.toLowerCase().split(/\s+/).map((l) => l.trim()).filter(Boolean), [a, s] = await Promise.all([
|
|
1641
1659
|
r.from("posts").select("id, title, slug, excerpt, subtitle, meta_description, status, updated_at").eq("status", "published").limit(100),
|
|
1642
1660
|
r.from("pages").select("id, title, slug, meta_description, status, updated_at").eq("status", "published").limit(100)
|
|
1643
1661
|
]);
|
|
1644
1662
|
if (a.error)
|
|
1645
|
-
throw new Error(`Failed to search documentation posts: ${
|
|
1663
|
+
throw new Error(`Failed to search documentation posts: ${y(a.error)}`);
|
|
1646
1664
|
if (s.error)
|
|
1647
|
-
throw new Error(`Failed to search documentation pages: ${
|
|
1648
|
-
const
|
|
1649
|
-
excerpt:
|
|
1650
|
-
[
|
|
1665
|
+
throw new Error(`Failed to search documentation pages: ${y(s.error)}`);
|
|
1666
|
+
const c = (a.data ?? []).map((l) => ({
|
|
1667
|
+
excerpt: st(
|
|
1668
|
+
[l.excerpt, l.subtitle, l.meta_description, l.slug].filter(Boolean),
|
|
1651
1669
|
o
|
|
1652
1670
|
),
|
|
1653
1671
|
source: "post",
|
|
1654
|
-
title:
|
|
1655
|
-
url: `/article/${
|
|
1656
|
-
})), u = (s.data ?? []).map((
|
|
1657
|
-
excerpt:
|
|
1672
|
+
title: l.title,
|
|
1673
|
+
url: `/article/${l.slug}`
|
|
1674
|
+
})), u = (s.data ?? []).map((l) => ({
|
|
1675
|
+
excerpt: st([l.meta_description, l.slug].filter(Boolean), o),
|
|
1658
1676
|
source: "page",
|
|
1659
|
-
title:
|
|
1660
|
-
url:
|
|
1661
|
-
})), d = [...
|
|
1662
|
-
...
|
|
1663
|
-
score:
|
|
1664
|
-
})).filter((
|
|
1665
|
-
excerpt:
|
|
1666
|
-
source:
|
|
1667
|
-
title:
|
|
1668
|
-
url:
|
|
1677
|
+
title: l.title,
|
|
1678
|
+
url: l.slug === "home" ? "/" : `/${l.slug}`
|
|
1679
|
+
})), d = [...c, ...u].map((l) => ({
|
|
1680
|
+
...l,
|
|
1681
|
+
score: hr(o, [l.title, l.excerpt, l.url])
|
|
1682
|
+
})).filter((l) => l.score > 0).sort((l, m) => m.score - l.score).slice(0, n.limit).map((l) => ({
|
|
1683
|
+
excerpt: l.excerpt,
|
|
1684
|
+
source: l.source,
|
|
1685
|
+
title: l.title,
|
|
1686
|
+
url: l.url
|
|
1669
1687
|
}));
|
|
1670
1688
|
return {
|
|
1671
1689
|
query: n.query,
|
|
@@ -1673,10 +1691,10 @@ async function fr(e, t) {
|
|
|
1673
1691
|
success: !0
|
|
1674
1692
|
};
|
|
1675
1693
|
}
|
|
1676
|
-
async function
|
|
1677
|
-
const r =
|
|
1678
|
-
return
|
|
1679
|
-
|
|
1694
|
+
async function _r(e, t, n = un) {
|
|
1695
|
+
const r = Be.safeParse(e), o = r.success ? r.data.query : "";
|
|
1696
|
+
return An(
|
|
1697
|
+
yr(e, t),
|
|
1680
1698
|
n,
|
|
1681
1699
|
() => ({
|
|
1682
1700
|
message: "Documentation search took too long to respond. Please try again or ask a more specific question.",
|
|
@@ -1687,7 +1705,7 @@ async function hr(e, t, n = ln) {
|
|
|
1687
1705
|
})
|
|
1688
1706
|
);
|
|
1689
1707
|
}
|
|
1690
|
-
const
|
|
1708
|
+
const br = [
|
|
1691
1709
|
"pending",
|
|
1692
1710
|
"trial",
|
|
1693
1711
|
"paid",
|
|
@@ -1695,7 +1713,7 @@ const yr = [
|
|
|
1695
1713
|
"cancelled",
|
|
1696
1714
|
"refunded",
|
|
1697
1715
|
"failed"
|
|
1698
|
-
],
|
|
1716
|
+
], wr = {
|
|
1699
1717
|
awaiting: "pending",
|
|
1700
1718
|
canceled: "cancelled",
|
|
1701
1719
|
cancelled: "cancelled",
|
|
@@ -1712,34 +1730,34 @@ const yr = [
|
|
|
1712
1730
|
trial: "trial",
|
|
1713
1731
|
trials: "trial"
|
|
1714
1732
|
};
|
|
1715
|
-
function
|
|
1733
|
+
function kr(e) {
|
|
1716
1734
|
return String(e ?? "unknown").trim().toLowerCase() || "unknown";
|
|
1717
1735
|
}
|
|
1718
|
-
function
|
|
1736
|
+
function ct(e) {
|
|
1719
1737
|
const t = Object.fromEntries(
|
|
1720
|
-
|
|
1738
|
+
br.map((n) => [n, 0])
|
|
1721
1739
|
);
|
|
1722
1740
|
for (const n of e) {
|
|
1723
|
-
const r =
|
|
1741
|
+
const r = kr(n.status);
|
|
1724
1742
|
t[r] = (t[r] ?? 0) + 1;
|
|
1725
1743
|
}
|
|
1726
1744
|
return t;
|
|
1727
1745
|
}
|
|
1728
|
-
function
|
|
1746
|
+
function Ir(e) {
|
|
1729
1747
|
const n = e.toLowerCase().replace(/[^a-z0-9_]+/g, " ").split(/\s+/).filter(Boolean);
|
|
1730
1748
|
for (const r of n) {
|
|
1731
|
-
const o =
|
|
1749
|
+
const o = wr[r];
|
|
1732
1750
|
if (o)
|
|
1733
1751
|
return o;
|
|
1734
1752
|
}
|
|
1735
1753
|
return null;
|
|
1736
1754
|
}
|
|
1737
|
-
function
|
|
1755
|
+
function ee(e) {
|
|
1738
1756
|
const t = Number(e);
|
|
1739
1757
|
return Number.isFinite(t) ? t : 0;
|
|
1740
1758
|
}
|
|
1741
|
-
async function
|
|
1742
|
-
const n =
|
|
1759
|
+
async function Tr(e, t) {
|
|
1760
|
+
const n = yt.parse(e), r = C(t), o = /* @__PURE__ */ new Date();
|
|
1743
1761
|
let a = null, s = null;
|
|
1744
1762
|
switch (n.timeRange) {
|
|
1745
1763
|
case "today":
|
|
@@ -1764,8 +1782,8 @@ async function wr(e, t) {
|
|
|
1764
1782
|
a = null;
|
|
1765
1783
|
break;
|
|
1766
1784
|
}
|
|
1767
|
-
const
|
|
1768
|
-
|
|
1785
|
+
const c = n.currency?.toUpperCase(), u = Ir(n.query), d = r.from("orders").select("id, status, total, currency, created_at, paid_at");
|
|
1786
|
+
c && d.eq("currency", c), a && d.gte("created_at", a.toISOString()), s && d.lte("created_at", s.toISOString());
|
|
1769
1787
|
const m = n.reportType === "products" || n.reportType === "revenue" || n.reportType === "general" ? r.from("order_items").select(`
|
|
1770
1788
|
quantity,
|
|
1771
1789
|
price_at_purchase,
|
|
@@ -1781,92 +1799,92 @@ async function wr(e, t) {
|
|
|
1781
1799
|
currency
|
|
1782
1800
|
)
|
|
1783
1801
|
`).eq("orders.status", "paid") : null;
|
|
1784
|
-
m && (
|
|
1802
|
+
m && (c && m.eq("orders.currency", c), a && m.gte("orders.paid_at", a.toISOString()), s && m.lte("orders.paid_at", s.toISOString()));
|
|
1785
1803
|
const p = n.timeRange !== "all_time" && (n.reportType === "orders" || u) ? r.from("orders").select("id, status, currency") : null;
|
|
1786
|
-
p &&
|
|
1804
|
+
p && c && p.eq("currency", c);
|
|
1787
1805
|
const [
|
|
1788
|
-
{ data:
|
|
1789
|
-
{ data:
|
|
1806
|
+
{ data: f, error: g },
|
|
1807
|
+
{ data: b, error: _ },
|
|
1790
1808
|
w
|
|
1791
1809
|
] = await Promise.all([
|
|
1792
1810
|
d,
|
|
1793
1811
|
m ?? Promise.resolve({ data: [], error: null }),
|
|
1794
1812
|
p ?? Promise.resolve({ data: null, error: null })
|
|
1795
1813
|
]);
|
|
1796
|
-
if (
|
|
1797
|
-
throw new Error(`Failed to fetch ecommerce stats: ${
|
|
1798
|
-
if (
|
|
1799
|
-
throw new Error(`Failed to fetch ecommerce stats: ${_
|
|
1814
|
+
if (g)
|
|
1815
|
+
throw new Error(`Failed to fetch ecommerce stats: ${y(g)}`);
|
|
1816
|
+
if (_)
|
|
1817
|
+
throw new Error(`Failed to fetch ecommerce stats: ${y(_)}`);
|
|
1800
1818
|
if (w.error)
|
|
1801
|
-
throw new Error(`Failed to fetch ecommerce stats: ${
|
|
1802
|
-
const
|
|
1803
|
-
for (const
|
|
1804
|
-
const A = Array.isArray(
|
|
1805
|
-
|
|
1819
|
+
throw new Error(`Failed to fetch ecommerce stats: ${y(w.error)}`);
|
|
1820
|
+
const k = Array.isArray(f) ? f : [], T = Array.isArray(b) ? b : [], I = ct(k), $ = Array.isArray(w.data) ? w.data : null, P = $ ? ct($) : null, L = {};
|
|
1821
|
+
for (const x of T) {
|
|
1822
|
+
const A = Array.isArray(x.orders) ? x.orders[0] : x.orders, B = String(A?.currency || c || "unknown").toUpperCase();
|
|
1823
|
+
L[B] = (L[B] ?? 0) + ee(x.quantity) * ee(x.price_at_purchase) / 100;
|
|
1806
1824
|
}
|
|
1807
|
-
const
|
|
1808
|
-
currency:
|
|
1809
|
-
currencyFiltered: !!
|
|
1810
|
-
orderStatusCounts:
|
|
1811
|
-
paidOrderCount:
|
|
1825
|
+
const Q = {
|
|
1826
|
+
currency: c ?? null,
|
|
1827
|
+
currencyFiltered: !!c,
|
|
1828
|
+
orderStatusCounts: I,
|
|
1829
|
+
paidOrderCount: I.paid ?? 0,
|
|
1812
1830
|
query: n.query,
|
|
1813
1831
|
reportType: n.reportType,
|
|
1814
|
-
revenueByCurrency:
|
|
1832
|
+
revenueByCurrency: L,
|
|
1815
1833
|
timeRange: n.timeRange,
|
|
1816
|
-
totalOrders:
|
|
1817
|
-
totalRevenue: Object.values(
|
|
1818
|
-
(
|
|
1834
|
+
totalOrders: k.length,
|
|
1835
|
+
totalRevenue: Object.values(L).reduce(
|
|
1836
|
+
(x, A) => x + A,
|
|
1819
1837
|
0
|
|
1820
1838
|
)
|
|
1821
1839
|
};
|
|
1822
|
-
if (
|
|
1823
|
-
allTimeCount:
|
|
1824
|
-
count:
|
|
1840
|
+
if (P && (Q.allTimeOrderStatusCounts = P), u && (Q.matchingOrderStatus = {
|
|
1841
|
+
allTimeCount: P?.[u] ?? I[u] ?? 0,
|
|
1842
|
+
count: I[u] ?? 0,
|
|
1825
1843
|
status: u,
|
|
1826
1844
|
timeRange: n.timeRange
|
|
1827
1845
|
}), n.reportType === "products" || n.reportType === "revenue" || n.reportType === "general") {
|
|
1828
|
-
const
|
|
1829
|
-
for (const A of
|
|
1830
|
-
const
|
|
1831
|
-
if (!
|
|
1846
|
+
const x = {};
|
|
1847
|
+
for (const A of T) {
|
|
1848
|
+
const B = Array.isArray(A.products) ? A.products[0] : A.products;
|
|
1849
|
+
if (!B?.id)
|
|
1832
1850
|
continue;
|
|
1833
|
-
const
|
|
1834
|
-
|
|
1835
|
-
id:
|
|
1851
|
+
const Z = B.id;
|
|
1852
|
+
x[Z] || (x[Z] = {
|
|
1853
|
+
id: Z,
|
|
1836
1854
|
quantity: 0,
|
|
1837
1855
|
revenue: 0,
|
|
1838
|
-
title:
|
|
1839
|
-
type:
|
|
1840
|
-
}),
|
|
1856
|
+
title: B.title,
|
|
1857
|
+
type: B.product_type
|
|
1858
|
+
}), x[Z].quantity += ee(A.quantity), x[Z].revenue += ee(A.quantity) * ee(A.price_at_purchase) / 100;
|
|
1841
1859
|
}
|
|
1842
|
-
|
|
1860
|
+
Q.topProducts = Object.values(x).sort((A, B) => B.revenue - A.revenue).slice(0, 10);
|
|
1843
1861
|
}
|
|
1844
1862
|
return {
|
|
1845
|
-
report:
|
|
1863
|
+
report: Q,
|
|
1846
1864
|
success: !0
|
|
1847
1865
|
};
|
|
1848
1866
|
}
|
|
1849
|
-
async function
|
|
1850
|
-
const n =
|
|
1851
|
-
if (u || !
|
|
1867
|
+
async function xr(e, t) {
|
|
1868
|
+
const n = bt.parse(e), r = C(t), o = Y(t), a = q(o), s = o.contentType === "page" ? "pages" : o.contentType === "post" ? "posts" : "products", { data: c, error: u } = await r.from(s).select("*").eq("id", a).single();
|
|
1869
|
+
if (u || !c)
|
|
1852
1870
|
throw new Error(
|
|
1853
|
-
`Failed to read current ${o.contentType}: ${
|
|
1871
|
+
`Failed to read current ${o.contentType}: ${y(u)}`
|
|
1854
1872
|
);
|
|
1855
1873
|
let d = [];
|
|
1856
1874
|
if (n.includeBlocks) {
|
|
1857
|
-
const
|
|
1875
|
+
const l = o.contentType === "page" ? "page_id" : o.contentType === "post" ? "post_id" : "product_id", { data: m, error: h } = await r.from("blocks").select("id, page_id, post_id, product_id, language_id, block_type, content, order").eq(l, a);
|
|
1858
1876
|
if (h)
|
|
1859
|
-
throw new Error(`Failed to read current ${o.contentType} blocks: ${
|
|
1860
|
-
d = (Array.isArray(m) ? m : []).slice().sort((p,
|
|
1877
|
+
throw new Error(`Failed to read current ${o.contentType} blocks: ${y(h)}`);
|
|
1878
|
+
d = (Array.isArray(m) ? m : []).slice().sort((p, f) => Number(p.order) - Number(f.order)).map((p) => Jn(p, n.includeBlockContent));
|
|
1861
1879
|
}
|
|
1862
1880
|
return {
|
|
1863
1881
|
blocks: d,
|
|
1864
1882
|
context: o,
|
|
1865
|
-
item:
|
|
1883
|
+
item: c,
|
|
1866
1884
|
success: !0
|
|
1867
1885
|
};
|
|
1868
1886
|
}
|
|
1869
|
-
const
|
|
1887
|
+
const Rt = /* @__PURE__ */ new Set([
|
|
1870
1888
|
"feature_image_id",
|
|
1871
1889
|
"language_id",
|
|
1872
1890
|
"meta_description",
|
|
@@ -1874,7 +1892,7 @@ const Lt = /* @__PURE__ */ new Set([
|
|
|
1874
1892
|
"slug",
|
|
1875
1893
|
"status",
|
|
1876
1894
|
"title"
|
|
1877
|
-
]),
|
|
1895
|
+
]), qt = /* @__PURE__ */ new Set([
|
|
1878
1896
|
"excerpt",
|
|
1879
1897
|
"feature_image_id",
|
|
1880
1898
|
"label",
|
|
@@ -1886,7 +1904,7 @@ const Lt = /* @__PURE__ */ new Set([
|
|
|
1886
1904
|
"status",
|
|
1887
1905
|
"subtitle",
|
|
1888
1906
|
"title"
|
|
1889
|
-
]),
|
|
1907
|
+
]), Cr = /* @__PURE__ */ new Set([
|
|
1890
1908
|
"description_json",
|
|
1891
1909
|
"language_id",
|
|
1892
1910
|
"meta_description",
|
|
@@ -1895,7 +1913,7 @@ const Lt = /* @__PURE__ */ new Set([
|
|
|
1895
1913
|
"slug",
|
|
1896
1914
|
"status",
|
|
1897
1915
|
"title"
|
|
1898
|
-
]),
|
|
1916
|
+
]), vr = /* @__PURE__ */ new Set([
|
|
1899
1917
|
"excerpt",
|
|
1900
1918
|
"feature_image_id",
|
|
1901
1919
|
"label",
|
|
@@ -1905,13 +1923,13 @@ const Lt = /* @__PURE__ */ new Set([
|
|
|
1905
1923
|
"short_description",
|
|
1906
1924
|
"subtitle"
|
|
1907
1925
|
]);
|
|
1908
|
-
function
|
|
1909
|
-
return e === "page" ?
|
|
1926
|
+
function Sr(e) {
|
|
1927
|
+
return e === "page" ? Rt : e === "post" ? qt : Cr;
|
|
1910
1928
|
}
|
|
1911
|
-
function
|
|
1912
|
-
return
|
|
1929
|
+
function Mt(e, t) {
|
|
1930
|
+
return vr.has(e) && t === "" ? null : t;
|
|
1913
1931
|
}
|
|
1914
|
-
function
|
|
1932
|
+
function Oe(e, t) {
|
|
1915
1933
|
if (typeof t != "string")
|
|
1916
1934
|
return;
|
|
1917
1935
|
const n = e === "product" ? ["active", "archived", "draft"] : ["archived", "draft", "published"];
|
|
@@ -1920,23 +1938,23 @@ function Ne(e, t) {
|
|
|
1920
1938
|
`Status "${t}" is not valid for ${e}. Allowed statuses: ${n.join(", ")}.`
|
|
1921
1939
|
);
|
|
1922
1940
|
}
|
|
1923
|
-
function
|
|
1924
|
-
const n =
|
|
1941
|
+
function Er(e, t) {
|
|
1942
|
+
const n = Sr(t.contentType), r = {};
|
|
1925
1943
|
for (const [o, a] of Object.entries(e))
|
|
1926
1944
|
if (a !== void 0) {
|
|
1927
1945
|
if (!n.has(o))
|
|
1928
1946
|
throw new Error(
|
|
1929
1947
|
`Field "${o}" cannot be updated for ${t.contentType} content.`
|
|
1930
1948
|
);
|
|
1931
|
-
o === "status" &&
|
|
1949
|
+
o === "status" && Oe(t.contentType, a), r[o] = Mt(o, a);
|
|
1932
1950
|
}
|
|
1933
1951
|
return r;
|
|
1934
1952
|
}
|
|
1935
|
-
async function
|
|
1936
|
-
const n =
|
|
1937
|
-
if (
|
|
1953
|
+
async function Dt(e, t) {
|
|
1954
|
+
const n = he.parse(e), r = C(t), o = Y(t), a = q(o), s = Er(n.fields, o), c = Object.keys(s);
|
|
1955
|
+
if (c.length === 0)
|
|
1938
1956
|
throw new Error("update_current_cms_fields requires at least one supported field.");
|
|
1939
|
-
const u =
|
|
1957
|
+
const u = N({
|
|
1940
1958
|
action: "UPDATE CMS FIELDS",
|
|
1941
1959
|
context: t,
|
|
1942
1960
|
payload: {
|
|
@@ -1948,7 +1966,7 @@ async function Rt(e, t) {
|
|
|
1948
1966
|
preview: {
|
|
1949
1967
|
contentType: o.contentType,
|
|
1950
1968
|
entityId: a,
|
|
1951
|
-
fields:
|
|
1969
|
+
fields: c,
|
|
1952
1970
|
slug: o.slug,
|
|
1953
1971
|
title: o.title
|
|
1954
1972
|
},
|
|
@@ -1956,113 +1974,123 @@ async function Rt(e, t) {
|
|
|
1956
1974
|
});
|
|
1957
1975
|
if (u)
|
|
1958
1976
|
return u;
|
|
1959
|
-
|
|
1977
|
+
const d = await J(t, o.contentType, a);
|
|
1978
|
+
typeof s.feature_image_id == "string" && (s.feature_image_id = await ne(
|
|
1960
1979
|
s.feature_image_id,
|
|
1961
1980
|
t,
|
|
1962
1981
|
typeof o.title == "string" ? o.title : void 0
|
|
1963
1982
|
));
|
|
1964
|
-
const
|
|
1983
|
+
const l = o.contentType === "page" ? "pages" : o.contentType === "post" ? "posts" : "products", { data: m, error: h } = await r.from(l).update({
|
|
1965
1984
|
...s,
|
|
1966
1985
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1967
1986
|
}).eq("id", a).select("id, language_id, slug, status, title").single();
|
|
1968
|
-
if (
|
|
1987
|
+
if (h || !m)
|
|
1969
1988
|
throw new Error(
|
|
1970
|
-
`Failed to update current ${o.contentType}: ${
|
|
1989
|
+
`Failed to update current ${o.contentType}: ${y(h)}`
|
|
1971
1990
|
);
|
|
1972
|
-
return
|
|
1991
|
+
return await G(t, o.contentType, a, d), O(t, o, m.slug), {
|
|
1973
1992
|
contentType: o.contentType,
|
|
1974
1993
|
entityId: a,
|
|
1975
1994
|
mutationExecuted: !0,
|
|
1976
|
-
slug:
|
|
1995
|
+
slug: m.slug,
|
|
1977
1996
|
success: !0,
|
|
1978
|
-
updatedFields:
|
|
1997
|
+
updatedFields: c
|
|
1979
1998
|
};
|
|
1980
1999
|
}
|
|
1981
|
-
async function
|
|
1982
|
-
const n =
|
|
2000
|
+
async function zt(e, t) {
|
|
2001
|
+
const n = ye.parse(e), r = C(t), o = Y(t), { data: a, error: s } = await r.from("blocks").select("id, page_id, post_id, product_id, language_id, block_type, content, order").eq("id", n.blockId).single();
|
|
1983
2002
|
if (s || !a)
|
|
1984
|
-
throw new Error(`Failed to read block ${n.blockId}: ${
|
|
1985
|
-
|
|
1986
|
-
const
|
|
1987
|
-
|
|
1988
|
-
const u =
|
|
1989
|
-
|
|
2003
|
+
throw new Error(`Failed to read block ${n.blockId}: ${y(s)}`);
|
|
2004
|
+
$t(a, o);
|
|
2005
|
+
const c = le(a.block_type, `Block ${n.blockId}`);
|
|
2006
|
+
At(n.blockType, c, `Block ${n.blockId}`);
|
|
2007
|
+
const u = re(a.content, `Block ${n.blockId}`), d = Vn(
|
|
2008
|
+
c,
|
|
1990
2009
|
u,
|
|
1991
2010
|
n.content,
|
|
1992
2011
|
t
|
|
1993
2012
|
);
|
|
1994
|
-
|
|
1995
|
-
const
|
|
2013
|
+
z(c, d, `Block ${n.blockId}`, t);
|
|
2014
|
+
const l = N({
|
|
1996
2015
|
action: "UPDATE CONTENT BLOCK",
|
|
1997
2016
|
context: t,
|
|
1998
2017
|
payload: {
|
|
1999
2018
|
blockId: n.blockId,
|
|
2000
|
-
blockType:
|
|
2019
|
+
blockType: c,
|
|
2001
2020
|
content: d,
|
|
2002
2021
|
tool: "update_content_block"
|
|
2003
2022
|
},
|
|
2004
2023
|
preview: {
|
|
2005
2024
|
blockId: n.blockId,
|
|
2006
|
-
blockType:
|
|
2025
|
+
blockType: c,
|
|
2007
2026
|
contentType: o.contentType,
|
|
2008
|
-
entityId:
|
|
2027
|
+
entityId: q(o)
|
|
2009
2028
|
},
|
|
2010
|
-
subject: `${
|
|
2029
|
+
subject: `${c} block ${n.blockId}`
|
|
2011
2030
|
});
|
|
2012
|
-
if (
|
|
2013
|
-
return
|
|
2014
|
-
const
|
|
2031
|
+
if (l)
|
|
2032
|
+
return l;
|
|
2033
|
+
const m = await J(
|
|
2034
|
+
t,
|
|
2035
|
+
o.contentType,
|
|
2036
|
+
q(o)
|
|
2037
|
+
), { data: h, error: p } = await r.from("blocks").update({
|
|
2015
2038
|
content: d,
|
|
2016
2039
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
2017
2040
|
}).eq("id", n.blockId).select("id, block_type, order").single();
|
|
2018
|
-
if (
|
|
2019
|
-
throw new Error(`Failed to update block ${n.blockId}: ${
|
|
2020
|
-
return await
|
|
2021
|
-
|
|
2022
|
-
|
|
2041
|
+
if (p || !h)
|
|
2042
|
+
throw new Error(`Failed to update block ${n.blockId}: ${y(p)}`);
|
|
2043
|
+
return await G(
|
|
2044
|
+
t,
|
|
2045
|
+
o.contentType,
|
|
2046
|
+
q(o),
|
|
2047
|
+
m
|
|
2048
|
+
), await ve({
|
|
2049
|
+
patch: ({ blocks: f }) => ({
|
|
2050
|
+
blocks: f.map(
|
|
2023
2051
|
(g) => String(g?.id) === String(n.blockId) ? { ...g, content: d } : g
|
|
2024
2052
|
)
|
|
2025
2053
|
}),
|
|
2026
2054
|
productId: a.product_id,
|
|
2027
2055
|
supabase: r
|
|
2028
|
-
}),
|
|
2029
|
-
blockId:
|
|
2030
|
-
blockType:
|
|
2056
|
+
}), $e([{ content: d }], r), O(t, o), {
|
|
2057
|
+
blockId: h.id,
|
|
2058
|
+
blockType: h.block_type,
|
|
2031
2059
|
contentUpdated: !0,
|
|
2032
2060
|
mutationExecuted: !0,
|
|
2033
2061
|
success: !0
|
|
2034
2062
|
};
|
|
2035
2063
|
}
|
|
2036
|
-
async function
|
|
2037
|
-
const n =
|
|
2038
|
-
const { data:
|
|
2064
|
+
async function Gt(e, t) {
|
|
2065
|
+
const n = we.parse(e), r = C(t), o = await oe(n, t), a = o.contentType === "product" ? o.item.id : Number(o.item.id), s = o.contentType === "page" ? "page_id" : o.contentType === "post" ? "post_id" : "product_id", c = async () => {
|
|
2066
|
+
const { data: T, error: I } = await r.from("blocks").select("id, page_id, post_id, product_id, language_id, block_type, content, order").eq(s, a);
|
|
2039
2067
|
if (I)
|
|
2040
|
-
throw new Error(`Failed to read ${o.contentType} blocks: ${
|
|
2041
|
-
return (Array.isArray(
|
|
2042
|
-
(
|
|
2068
|
+
throw new Error(`Failed to read ${o.contentType} blocks: ${y(I)}`);
|
|
2069
|
+
return (Array.isArray(T) ? T : []).sort(
|
|
2070
|
+
($, P) => Number($.order) - Number(P.order)
|
|
2043
2071
|
);
|
|
2044
|
-
}, u = (
|
|
2072
|
+
}, u = (T) => {
|
|
2045
2073
|
if (n.position === "start")
|
|
2046
2074
|
return 0;
|
|
2047
2075
|
if (n.position === "end") {
|
|
2048
|
-
const
|
|
2049
|
-
return
|
|
2076
|
+
const P = T.map((L) => Number(L.order)).filter(Number.isFinite);
|
|
2077
|
+
return P.length > 0 ? Math.max(...P) + 1 : 0;
|
|
2050
2078
|
}
|
|
2051
|
-
const I = n.anchorBlockId ?
|
|
2079
|
+
const I = n.anchorBlockId ? T.find((P) => Number(P.id) === n.anchorBlockId) : n.anchorBlockType ? T.find((P) => P.block_type === n.anchorBlockType) : null;
|
|
2052
2080
|
if (!I)
|
|
2053
2081
|
throw new Error(
|
|
2054
2082
|
n.anchorBlockType ? `Could not find a ${n.anchorBlockType} block to insert ${n.position}.` : `Could not find block ${n.anchorBlockId} to insert ${n.position}.`
|
|
2055
2083
|
);
|
|
2056
|
-
const
|
|
2057
|
-
return n.position === "before" ?
|
|
2058
|
-
}, d =
|
|
2084
|
+
const $ = Number(I.order);
|
|
2085
|
+
return n.position === "before" ? $ : $ + 1;
|
|
2086
|
+
}, d = pe(n.block, 0, t), l = await c(), m = u(l), h = {
|
|
2059
2087
|
contentType: o.contentType,
|
|
2060
2088
|
entityId: o.item.id,
|
|
2061
2089
|
languageId: o.item.language_id,
|
|
2062
2090
|
slug: o.item.slug,
|
|
2063
2091
|
title: o.item.title,
|
|
2064
2092
|
translationGroupId: o.item.translation_group_id
|
|
2065
|
-
}, p =
|
|
2093
|
+
}, p = N({
|
|
2066
2094
|
action: "INSERT CONTENT BLOCK",
|
|
2067
2095
|
context: t,
|
|
2068
2096
|
payload: {
|
|
@@ -2090,118 +2118,118 @@ async function Dt(e, t) {
|
|
|
2090
2118
|
});
|
|
2091
2119
|
if (p)
|
|
2092
2120
|
return p;
|
|
2093
|
-
const
|
|
2094
|
-
for (const
|
|
2121
|
+
const f = await c(), g = u(f), b = f.filter((T) => Number(T.order) >= g).sort((T, I) => Number(I.order) - Number(T.order)), _ = await J(t, o.contentType, a);
|
|
2122
|
+
for (const T of b) {
|
|
2095
2123
|
const { error: I } = await r.from("blocks").update({
|
|
2096
|
-
order: Number(
|
|
2124
|
+
order: Number(T.order) + 1,
|
|
2097
2125
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
2098
|
-
}).eq("id",
|
|
2126
|
+
}).eq("id", T.id);
|
|
2099
2127
|
if (I)
|
|
2100
|
-
throw new Error(`Failed to shift block ${
|
|
2128
|
+
throw new Error(`Failed to shift block ${T.id}: ${y(I)}`);
|
|
2101
2129
|
}
|
|
2102
|
-
const { data:
|
|
2130
|
+
const { data: w, error: k } = await r.from("blocks").insert({
|
|
2103
2131
|
block_type: d.block_type,
|
|
2104
2132
|
content: d.content,
|
|
2105
2133
|
language_id: o.item.language_id,
|
|
2106
|
-
order:
|
|
2134
|
+
order: g,
|
|
2107
2135
|
page_id: o.contentType === "page" ? a : null,
|
|
2108
2136
|
post_id: o.contentType === "post" ? a : null,
|
|
2109
2137
|
product_id: o.contentType === "product" ? a : null
|
|
2110
2138
|
}).select("id, block_type, order").single();
|
|
2111
|
-
if (
|
|
2112
|
-
throw new Error(`Failed to insert content block: ${
|
|
2113
|
-
return o.contentType === "product" && await
|
|
2114
|
-
patch: ({ blocks:
|
|
2139
|
+
if (k || !w)
|
|
2140
|
+
throw new Error(`Failed to insert content block: ${y(k)}`);
|
|
2141
|
+
return o.contentType === "product" && await ve({
|
|
2142
|
+
patch: ({ blocks: T }) => ({
|
|
2115
2143
|
blocks: [
|
|
2116
|
-
...
|
|
2117
|
-
(I) => Number(I?.order) >=
|
|
2144
|
+
...T.map(
|
|
2145
|
+
(I) => Number(I?.order) >= g ? { ...I, order: Number(I.order) + 1 } : I
|
|
2118
2146
|
),
|
|
2119
2147
|
{
|
|
2120
2148
|
block_type: d.block_type,
|
|
2121
2149
|
content: d.content,
|
|
2122
|
-
id:
|
|
2150
|
+
id: w.id,
|
|
2123
2151
|
language_id: o.item.language_id,
|
|
2124
|
-
order:
|
|
2152
|
+
order: g,
|
|
2125
2153
|
page_id: null,
|
|
2126
2154
|
post_id: null,
|
|
2127
2155
|
product_id: a
|
|
2128
2156
|
}
|
|
2129
|
-
].sort((I,
|
|
2157
|
+
].sort((I, $) => Number(I.order) - Number($.order))
|
|
2130
2158
|
}),
|
|
2131
2159
|
productId: a,
|
|
2132
2160
|
supabase: r
|
|
2133
|
-
}),
|
|
2134
|
-
blockId:
|
|
2135
|
-
blockType:
|
|
2161
|
+
}), await G(t, o.contentType, a, _), $e([d], r), O(t, h), {
|
|
2162
|
+
blockId: w.id,
|
|
2163
|
+
blockType: w.block_type,
|
|
2136
2164
|
contentType: o.contentType,
|
|
2137
2165
|
entityId: o.item.id,
|
|
2138
2166
|
mutationExecuted: !0,
|
|
2139
|
-
order:
|
|
2167
|
+
order: w.order,
|
|
2140
2168
|
success: !0
|
|
2141
2169
|
};
|
|
2142
2170
|
}
|
|
2143
|
-
async function
|
|
2144
|
-
const n =
|
|
2171
|
+
async function Kt(e, t) {
|
|
2172
|
+
const n = _e.parse(e), r = C(t), o = Y(t), { data: a, error: s } = await r.from("blocks").select("id, page_id, post_id, product_id, language_id, block_type, content, order").eq("id", n.parentBlockId).single();
|
|
2145
2173
|
if (s || !a)
|
|
2146
2174
|
throw new Error(
|
|
2147
|
-
`Failed to read parent block ${n.parentBlockId}: ${
|
|
2175
|
+
`Failed to read parent block ${n.parentBlockId}: ${y(s)}`
|
|
2148
2176
|
);
|
|
2149
|
-
|
|
2150
|
-
const
|
|
2177
|
+
$t(a, o);
|
|
2178
|
+
const c = le(
|
|
2151
2179
|
a.block_type,
|
|
2152
2180
|
`Parent block ${n.parentBlockId}`
|
|
2153
2181
|
);
|
|
2154
|
-
if (
|
|
2182
|
+
if (c !== "section")
|
|
2155
2183
|
throw new Error(
|
|
2156
|
-
`Parent block ${n.parentBlockId} must be a section block, not "${
|
|
2184
|
+
`Parent block ${n.parentBlockId} must be a section block, not "${c}".`
|
|
2157
2185
|
);
|
|
2158
|
-
const u =
|
|
2186
|
+
const u = re(
|
|
2159
2187
|
a.content,
|
|
2160
2188
|
`Parent block ${n.parentBlockId}`
|
|
2161
2189
|
);
|
|
2162
|
-
|
|
2163
|
-
|
|
2190
|
+
z(
|
|
2191
|
+
c,
|
|
2164
2192
|
u,
|
|
2165
2193
|
`Parent block ${n.parentBlockId}`,
|
|
2166
2194
|
t
|
|
2167
2195
|
);
|
|
2168
|
-
const
|
|
2169
|
-
if (!
|
|
2196
|
+
const l = u.column_blocks?.[n.columnIndex]?.[n.blockIndex];
|
|
2197
|
+
if (!l)
|
|
2170
2198
|
throw new Error(
|
|
2171
2199
|
`Nested block was not found at column ${n.columnIndex}, index ${n.blockIndex}.`
|
|
2172
2200
|
);
|
|
2173
|
-
const m =
|
|
2174
|
-
|
|
2201
|
+
const m = le(
|
|
2202
|
+
l.block_type,
|
|
2175
2203
|
`Nested block ${n.columnIndex}:${n.blockIndex}`
|
|
2176
2204
|
);
|
|
2177
|
-
|
|
2205
|
+
At(
|
|
2178
2206
|
n.blockType,
|
|
2179
2207
|
m,
|
|
2180
2208
|
`Nested block ${n.columnIndex}:${n.blockIndex}`
|
|
2181
|
-
),
|
|
2209
|
+
), z(
|
|
2182
2210
|
m,
|
|
2183
2211
|
n.content,
|
|
2184
2212
|
`Nested block ${n.columnIndex}:${n.blockIndex}`,
|
|
2185
2213
|
t
|
|
2186
2214
|
);
|
|
2187
2215
|
const h = u.column_blocks.map(
|
|
2188
|
-
(
|
|
2189
|
-
(
|
|
2190
|
-
...
|
|
2216
|
+
(w, k) => k === n.columnIndex ? w.map(
|
|
2217
|
+
(T, I) => I === n.blockIndex ? {
|
|
2218
|
+
...T,
|
|
2191
2219
|
content: n.content
|
|
2192
|
-
} :
|
|
2193
|
-
) :
|
|
2220
|
+
} : T
|
|
2221
|
+
) : w
|
|
2194
2222
|
), p = {
|
|
2195
2223
|
...u,
|
|
2196
2224
|
column_blocks: h
|
|
2197
2225
|
};
|
|
2198
|
-
|
|
2199
|
-
|
|
2226
|
+
z(
|
|
2227
|
+
c,
|
|
2200
2228
|
p,
|
|
2201
2229
|
`Updated parent block ${n.parentBlockId}`,
|
|
2202
2230
|
t
|
|
2203
2231
|
);
|
|
2204
|
-
const
|
|
2232
|
+
const f = N({
|
|
2205
2233
|
action: "UPDATE NESTED BLOCK",
|
|
2206
2234
|
context: t,
|
|
2207
2235
|
payload: {
|
|
@@ -2217,40 +2245,49 @@ async function zt(e, t) {
|
|
|
2217
2245
|
columnIndex: n.columnIndex,
|
|
2218
2246
|
nestedBlockType: m,
|
|
2219
2247
|
parentBlockId: n.parentBlockId,
|
|
2220
|
-
parentBlockType:
|
|
2248
|
+
parentBlockType: c
|
|
2221
2249
|
},
|
|
2222
2250
|
subject: `${m} nested block ${n.columnIndex}:${n.blockIndex}`
|
|
2223
2251
|
});
|
|
2224
|
-
if (
|
|
2225
|
-
return
|
|
2226
|
-
const
|
|
2252
|
+
if (f)
|
|
2253
|
+
return f;
|
|
2254
|
+
const g = await J(
|
|
2255
|
+
t,
|
|
2256
|
+
o.contentType,
|
|
2257
|
+
q(o)
|
|
2258
|
+
), { data: b, error: _ } = await r.from("blocks").update({
|
|
2227
2259
|
content: p,
|
|
2228
2260
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
2229
2261
|
}).eq("id", n.parentBlockId).select("id, block_type").single();
|
|
2230
|
-
if (
|
|
2262
|
+
if (_ || !b)
|
|
2231
2263
|
throw new Error(
|
|
2232
|
-
`Failed to update parent block ${n.parentBlockId}: ${_
|
|
2264
|
+
`Failed to update parent block ${n.parentBlockId}: ${y(_)}`
|
|
2233
2265
|
);
|
|
2234
|
-
return await
|
|
2235
|
-
patch: ({ blocks:
|
|
2236
|
-
blocks:
|
|
2237
|
-
(
|
|
2266
|
+
return await ve({
|
|
2267
|
+
patch: ({ blocks: w }) => ({
|
|
2268
|
+
blocks: w.map(
|
|
2269
|
+
(k) => String(k?.id) === String(n.parentBlockId) ? { ...k, content: p } : k
|
|
2238
2270
|
)
|
|
2239
2271
|
}),
|
|
2240
2272
|
productId: a.product_id,
|
|
2241
2273
|
supabase: r
|
|
2242
|
-
}),
|
|
2274
|
+
}), await G(
|
|
2275
|
+
t,
|
|
2276
|
+
o.contentType,
|
|
2277
|
+
q(o),
|
|
2278
|
+
g
|
|
2279
|
+
), O(t, o), {
|
|
2243
2280
|
blockIndex: n.blockIndex,
|
|
2244
2281
|
columnIndex: n.columnIndex,
|
|
2245
2282
|
mutationExecuted: !0,
|
|
2246
2283
|
nestedBlockType: m,
|
|
2247
|
-
parentBlockId:
|
|
2248
|
-
parentBlockType:
|
|
2284
|
+
parentBlockId: b.id,
|
|
2285
|
+
parentBlockType: b.block_type,
|
|
2249
2286
|
success: !0
|
|
2250
2287
|
};
|
|
2251
2288
|
}
|
|
2252
|
-
async function
|
|
2253
|
-
const n =
|
|
2289
|
+
async function We(e, t) {
|
|
2290
|
+
const n = ke.parse(e), r = C(t), o = Me(t), a = await Se(r, n.languageCode), s = M(n.slug || n.title), c = Ee(n.blocks, n.contactEmail, n.title, t), u = await Ge({
|
|
2254
2291
|
contentType: "page",
|
|
2255
2292
|
languageId: a.id,
|
|
2256
2293
|
slug: s,
|
|
@@ -2258,7 +2295,7 @@ async function Ve(e, t) {
|
|
|
2258
2295
|
});
|
|
2259
2296
|
if (u)
|
|
2260
2297
|
return u;
|
|
2261
|
-
const d = await
|
|
2298
|
+
const d = await Ke({
|
|
2262
2299
|
contentType: "page",
|
|
2263
2300
|
languageCode: a.code,
|
|
2264
2301
|
languageId: a.id,
|
|
@@ -2267,8 +2304,8 @@ async function Ve(e, t) {
|
|
|
2267
2304
|
});
|
|
2268
2305
|
if (d.result)
|
|
2269
2306
|
return d.result;
|
|
2270
|
-
const
|
|
2271
|
-
blocks:
|
|
2307
|
+
const l = {
|
|
2308
|
+
blocks: c,
|
|
2272
2309
|
item: {
|
|
2273
2310
|
feature_image_id: n.feature_image_id ?? null,
|
|
2274
2311
|
language_id: a.id,
|
|
@@ -2280,12 +2317,12 @@ async function Ve(e, t) {
|
|
|
2280
2317
|
translation_group_id: d.translationGroupId
|
|
2281
2318
|
},
|
|
2282
2319
|
tool: "create_cms_page"
|
|
2283
|
-
}, m =
|
|
2320
|
+
}, m = N({
|
|
2284
2321
|
action: "CREATE PAGE",
|
|
2285
2322
|
context: t,
|
|
2286
|
-
payload:
|
|
2323
|
+
payload: l,
|
|
2287
2324
|
preview: {
|
|
2288
|
-
blockCount:
|
|
2325
|
+
blockCount: c.length,
|
|
2289
2326
|
languageCode: a.code,
|
|
2290
2327
|
slug: s,
|
|
2291
2328
|
status: n.status,
|
|
@@ -2296,47 +2333,47 @@ async function Ve(e, t) {
|
|
|
2296
2333
|
});
|
|
2297
2334
|
if (m)
|
|
2298
2335
|
return m;
|
|
2299
|
-
const h = d.translationGroupId ||
|
|
2300
|
-
|
|
2336
|
+
const h = d.translationGroupId || De(), p = await ne(
|
|
2337
|
+
l.item.feature_image_id,
|
|
2301
2338
|
t,
|
|
2302
2339
|
n.title
|
|
2303
|
-
), { data:
|
|
2304
|
-
...
|
|
2340
|
+
), { data: f, error: g } = await r.from("pages").insert({
|
|
2341
|
+
...l.item,
|
|
2305
2342
|
author_id: o,
|
|
2306
2343
|
feature_image_id: p,
|
|
2307
2344
|
translation_group_id: h
|
|
2308
2345
|
}).select("id, language_id, slug, status, title, translation_group_id").single();
|
|
2309
|
-
if (
|
|
2310
|
-
throw new Error(`Failed to create page: ${
|
|
2346
|
+
if (g || !f?.id)
|
|
2347
|
+
throw new Error(`Failed to create page: ${y(g)}`);
|
|
2311
2348
|
try {
|
|
2312
|
-
await
|
|
2313
|
-
blocks:
|
|
2349
|
+
await He({
|
|
2350
|
+
blocks: c,
|
|
2314
2351
|
contentType: "page",
|
|
2315
|
-
itemId: Number(
|
|
2352
|
+
itemId: Number(f.id),
|
|
2316
2353
|
languageId: a.id,
|
|
2317
2354
|
supabase: r
|
|
2318
2355
|
});
|
|
2319
|
-
} catch (
|
|
2320
|
-
throw await
|
|
2356
|
+
} catch (b) {
|
|
2357
|
+
throw await Ve({ contentType: "page", itemId: Number(f.id), supabase: r }), b;
|
|
2321
2358
|
}
|
|
2322
|
-
return
|
|
2359
|
+
return O(
|
|
2323
2360
|
t,
|
|
2324
|
-
{ contentType: "page", entityId: Number(
|
|
2361
|
+
{ contentType: "page", entityId: Number(f.id), languageId: a.id, slug: s, title: n.title },
|
|
2325
2362
|
s
|
|
2326
2363
|
), t?.revalidatePath?.("/cms/pages"), {
|
|
2327
|
-
blockCount:
|
|
2364
|
+
blockCount: c.length,
|
|
2328
2365
|
contentType: "page",
|
|
2329
|
-
editPath:
|
|
2330
|
-
entityId:
|
|
2366
|
+
editPath: Je("page", f.id),
|
|
2367
|
+
entityId: f.id,
|
|
2331
2368
|
mutationExecuted: !0,
|
|
2332
2369
|
slug: s,
|
|
2333
2370
|
success: !0,
|
|
2334
2371
|
title: n.title,
|
|
2335
|
-
translationGroupId:
|
|
2372
|
+
translationGroupId: f.translation_group_id
|
|
2336
2373
|
};
|
|
2337
2374
|
}
|
|
2338
|
-
async function
|
|
2339
|
-
const n =
|
|
2375
|
+
async function Ye(e, t) {
|
|
2376
|
+
const n = Ie.parse(e), r = C(t), o = Me(t), a = await Se(r, n.languageCode), s = M(n.slug || n.title), c = Ee(n.blocks, void 0, void 0, t), u = await Ge({
|
|
2340
2377
|
contentType: "post",
|
|
2341
2378
|
languageId: a.id,
|
|
2342
2379
|
slug: s,
|
|
@@ -2344,7 +2381,7 @@ async function Je(e, t) {
|
|
|
2344
2381
|
});
|
|
2345
2382
|
if (u)
|
|
2346
2383
|
return u;
|
|
2347
|
-
const d = await
|
|
2384
|
+
const d = await Ke({
|
|
2348
2385
|
contentType: "post",
|
|
2349
2386
|
languageCode: a.code,
|
|
2350
2387
|
languageId: a.id,
|
|
@@ -2353,8 +2390,8 @@ async function Je(e, t) {
|
|
|
2353
2390
|
});
|
|
2354
2391
|
if (d.result)
|
|
2355
2392
|
return d.result;
|
|
2356
|
-
const
|
|
2357
|
-
blocks:
|
|
2393
|
+
const l = n.published_at && !Number.isNaN(new Date(n.published_at).getTime()) ? new Date(n.published_at).toISOString() : n.published_at ?? null, m = {
|
|
2394
|
+
blocks: c,
|
|
2358
2395
|
item: {
|
|
2359
2396
|
excerpt: n.excerpt ?? null,
|
|
2360
2397
|
feature_image_id: n.feature_image_id ?? null,
|
|
@@ -2362,7 +2399,7 @@ async function Je(e, t) {
|
|
|
2362
2399
|
language_id: a.id,
|
|
2363
2400
|
meta_description: n.meta_description ?? null,
|
|
2364
2401
|
meta_title: n.meta_title ?? null,
|
|
2365
|
-
published_at:
|
|
2402
|
+
published_at: l,
|
|
2366
2403
|
slug: s,
|
|
2367
2404
|
status: n.status,
|
|
2368
2405
|
subtitle: n.subtitle ?? null,
|
|
@@ -2370,12 +2407,12 @@ async function Je(e, t) {
|
|
|
2370
2407
|
translation_group_id: d.translationGroupId
|
|
2371
2408
|
},
|
|
2372
2409
|
tool: "create_cms_post"
|
|
2373
|
-
}, h =
|
|
2410
|
+
}, h = N({
|
|
2374
2411
|
action: "CREATE POST",
|
|
2375
2412
|
context: t,
|
|
2376
2413
|
payload: m,
|
|
2377
2414
|
preview: {
|
|
2378
|
-
blockCount:
|
|
2415
|
+
blockCount: c.length,
|
|
2379
2416
|
languageCode: a.code,
|
|
2380
2417
|
slug: s,
|
|
2381
2418
|
status: n.status,
|
|
@@ -2386,57 +2423,57 @@ async function Je(e, t) {
|
|
|
2386
2423
|
});
|
|
2387
2424
|
if (h)
|
|
2388
2425
|
return h;
|
|
2389
|
-
const p = d.translationGroupId ||
|
|
2426
|
+
const p = d.translationGroupId || De(), f = await ne(
|
|
2390
2427
|
m.item.feature_image_id,
|
|
2391
2428
|
t,
|
|
2392
2429
|
n.title
|
|
2393
|
-
), { data:
|
|
2430
|
+
), { data: g, error: b } = await r.from("posts").insert({
|
|
2394
2431
|
...m.item,
|
|
2395
2432
|
author_id: o,
|
|
2396
|
-
feature_image_id:
|
|
2433
|
+
feature_image_id: f,
|
|
2397
2434
|
translation_group_id: p
|
|
2398
2435
|
}).select("id, language_id, slug, status, title, translation_group_id").single();
|
|
2399
|
-
if (
|
|
2400
|
-
throw new Error(`Failed to create post: ${
|
|
2436
|
+
if (b || !g?.id)
|
|
2437
|
+
throw new Error(`Failed to create post: ${y(b)}`);
|
|
2401
2438
|
try {
|
|
2402
|
-
await
|
|
2403
|
-
blocks:
|
|
2439
|
+
await He({
|
|
2440
|
+
blocks: c,
|
|
2404
2441
|
contentType: "post",
|
|
2405
|
-
itemId: Number(
|
|
2442
|
+
itemId: Number(g.id),
|
|
2406
2443
|
languageId: a.id,
|
|
2407
2444
|
supabase: r
|
|
2408
2445
|
});
|
|
2409
|
-
} catch (
|
|
2410
|
-
throw await
|
|
2446
|
+
} catch (_) {
|
|
2447
|
+
throw await Ve({ contentType: "post", itemId: Number(g.id), supabase: r }), _;
|
|
2411
2448
|
}
|
|
2412
|
-
return
|
|
2449
|
+
return O(
|
|
2413
2450
|
t,
|
|
2414
|
-
{ contentType: "post", entityId: Number(
|
|
2451
|
+
{ contentType: "post", entityId: Number(g.id), languageId: a.id, slug: s, title: n.title },
|
|
2415
2452
|
s
|
|
2416
2453
|
), t?.revalidatePath?.("/cms/posts"), t?.revalidatePath?.("/articles"), {
|
|
2417
|
-
blockCount:
|
|
2454
|
+
blockCount: c.length,
|
|
2418
2455
|
contentType: "post",
|
|
2419
|
-
editPath:
|
|
2420
|
-
entityId:
|
|
2456
|
+
editPath: Je("post", g.id),
|
|
2457
|
+
entityId: g.id,
|
|
2421
2458
|
mutationExecuted: !0,
|
|
2422
2459
|
slug: s,
|
|
2423
2460
|
success: !0,
|
|
2424
2461
|
title: n.title,
|
|
2425
|
-
translationGroupId:
|
|
2462
|
+
translationGroupId: g.translation_group_id
|
|
2426
2463
|
};
|
|
2427
2464
|
}
|
|
2428
|
-
function
|
|
2429
|
-
return (t ||
|
|
2465
|
+
function $r(e, t) {
|
|
2466
|
+
return (t || M(e) || "product").replace(/-/g, "").slice(0, 24).toUpperCase();
|
|
2430
2467
|
}
|
|
2431
|
-
function
|
|
2468
|
+
function Ht(e) {
|
|
2432
2469
|
if (e == null)
|
|
2433
2470
|
return;
|
|
2434
2471
|
if (typeof e == "string")
|
|
2435
|
-
return
|
|
2436
|
-
const t = Array.isArray(e) ? { content: e, type: "doc" } :
|
|
2472
|
+
return gt(e) ?? void 0;
|
|
2473
|
+
const t = Array.isArray(e) ? { content: e, type: "doc" } : E(e) && e.type !== "doc" && Array.isArray(e.content) ? { ...e, type: "doc" } : e, n = nt().safeParse(t);
|
|
2437
2474
|
if (!n.success) {
|
|
2438
|
-
if (
|
|
2439
|
-
const r =
|
|
2475
|
+
if (E(e) && typeof e.type == "string") {
|
|
2476
|
+
const r = nt().safeParse({
|
|
2440
2477
|
content: [e],
|
|
2441
2478
|
type: "doc"
|
|
2442
2479
|
});
|
|
@@ -2449,23 +2486,23 @@ function Gt(e) {
|
|
|
2449
2486
|
}
|
|
2450
2487
|
return n.data;
|
|
2451
2488
|
}
|
|
2452
|
-
function
|
|
2453
|
-
const t = (o) => !!(o && Array.isArray(o.content) && o.content.length > 0), n =
|
|
2489
|
+
function Ar(e) {
|
|
2490
|
+
const t = (o) => !!(o && Array.isArray(o.content) && o.content.length > 0), n = Ht(e.description_json);
|
|
2454
2491
|
if (t(n))
|
|
2455
2492
|
return n;
|
|
2456
|
-
const r = e.description_html ?
|
|
2493
|
+
const r = e.description_html ? gt(e.description_html) : null;
|
|
2457
2494
|
return t(r) ? r : void 0;
|
|
2458
2495
|
}
|
|
2459
|
-
async function
|
|
2460
|
-
const n =
|
|
2496
|
+
async function Vt(e, t) {
|
|
2497
|
+
const n = Te.parse(e), r = C(t), o = await Se(r, n.languageCode), a = M(n.slug || n.title), s = Ee(n.blocks, void 0, void 0, t), c = await Ge({
|
|
2461
2498
|
contentType: "product",
|
|
2462
2499
|
languageId: o.id,
|
|
2463
2500
|
slug: a,
|
|
2464
2501
|
supabase: r
|
|
2465
2502
|
});
|
|
2466
|
-
if (
|
|
2467
|
-
return
|
|
2468
|
-
const u = await
|
|
2503
|
+
if (c)
|
|
2504
|
+
return c;
|
|
2505
|
+
const u = await Ke({
|
|
2469
2506
|
contentType: "product",
|
|
2470
2507
|
languageCode: o.code,
|
|
2471
2508
|
languageId: o.id,
|
|
@@ -2474,8 +2511,8 @@ async function Kt(e, t) {
|
|
|
2474
2511
|
});
|
|
2475
2512
|
if (u.result)
|
|
2476
2513
|
return u.result;
|
|
2477
|
-
const { createProduct: d, productSchema:
|
|
2478
|
-
description_json:
|
|
2514
|
+
const { createProduct: d, productSchema: l } = await jn(), h = n.product_type === "digital" && n.payment_provider === "freemius" ? n.trial_period_days : 0, p = l.parse({
|
|
2515
|
+
description_json: Ar(n),
|
|
2479
2516
|
freemius_plan_id: n.freemius_plan_id || "",
|
|
2480
2517
|
freemius_product_id: n.freemius_product_id || "",
|
|
2481
2518
|
is_taxable: n.is_taxable,
|
|
@@ -2490,7 +2527,7 @@ async function Kt(e, t) {
|
|
|
2490
2527
|
sale_price: n.sale_price ?? null,
|
|
2491
2528
|
sale_prices: n.sale_prices || {},
|
|
2492
2529
|
short_description: n.short_description ?? "",
|
|
2493
|
-
sku: n.sku ||
|
|
2530
|
+
sku: n.sku || $r(n.title, a),
|
|
2494
2531
|
slug: a,
|
|
2495
2532
|
status: n.status,
|
|
2496
2533
|
stock: n.stock,
|
|
@@ -2501,14 +2538,14 @@ async function Kt(e, t) {
|
|
|
2501
2538
|
upc: n.upc ?? "",
|
|
2502
2539
|
variation_attributes: [],
|
|
2503
2540
|
variants: []
|
|
2504
|
-
}),
|
|
2541
|
+
}), f = n.images ?? [], g = N({
|
|
2505
2542
|
action: "CREATE PRODUCT",
|
|
2506
2543
|
context: t,
|
|
2507
|
-
payload: { blocks: s, images:
|
|
2544
|
+
payload: { blocks: s, images: f, item: p, tool: "create_cms_product" },
|
|
2508
2545
|
preview: {
|
|
2509
2546
|
blockCount: s.length,
|
|
2510
2547
|
descriptionLength: p.description_json ? JSON.stringify(p.description_json).length : 0,
|
|
2511
|
-
imageCount:
|
|
2548
|
+
imageCount: f.length,
|
|
2512
2549
|
languageCode: o.code,
|
|
2513
2550
|
price: p.price,
|
|
2514
2551
|
sku: p.sku,
|
|
@@ -2520,45 +2557,45 @@ async function Kt(e, t) {
|
|
|
2520
2557
|
},
|
|
2521
2558
|
subject: a
|
|
2522
2559
|
});
|
|
2523
|
-
if (
|
|
2524
|
-
return
|
|
2525
|
-
let
|
|
2526
|
-
if (
|
|
2560
|
+
if (g)
|
|
2561
|
+
return g;
|
|
2562
|
+
let b = [], _ = null;
|
|
2563
|
+
if (f.length > 0)
|
|
2527
2564
|
try {
|
|
2528
|
-
if (
|
|
2565
|
+
if (b = [...new Set(await xt(f, t, n.title))], b.length === 0)
|
|
2529
2566
|
throw new Error("None of the provided images could be resolved to a media item.");
|
|
2530
|
-
} catch (
|
|
2531
|
-
|
|
2567
|
+
} catch (k) {
|
|
2568
|
+
_ = k instanceof Error ? k.message : String(k);
|
|
2532
2569
|
}
|
|
2533
2570
|
const w = await d(r, {
|
|
2534
2571
|
...p,
|
|
2535
2572
|
// First entry is the main product image; the rest become the gallery in order.
|
|
2536
|
-
product_media:
|
|
2573
|
+
product_media: b.map((k) => ({ media_id: k }))
|
|
2537
2574
|
});
|
|
2538
2575
|
if (!w?.id)
|
|
2539
2576
|
throw new Error("Failed to create product.");
|
|
2540
2577
|
try {
|
|
2541
|
-
await
|
|
2578
|
+
await He({
|
|
2542
2579
|
blocks: s,
|
|
2543
2580
|
contentType: "product",
|
|
2544
2581
|
itemId: w.id,
|
|
2545
2582
|
languageId: o.id,
|
|
2546
2583
|
supabase: r
|
|
2547
2584
|
});
|
|
2548
|
-
} catch (
|
|
2549
|
-
throw await
|
|
2585
|
+
} catch (k) {
|
|
2586
|
+
throw await Ve({ contentType: "product", itemId: w.id, supabase: r }), k;
|
|
2550
2587
|
}
|
|
2551
|
-
return
|
|
2588
|
+
return O(
|
|
2552
2589
|
t,
|
|
2553
2590
|
{ contentType: "product", entityId: w.id, languageId: o.id, slug: a, title: n.title },
|
|
2554
2591
|
a
|
|
2555
2592
|
), t?.revalidatePath?.("/cms/products"), {
|
|
2556
2593
|
blockCount: s.length,
|
|
2557
2594
|
contentType: "product",
|
|
2558
|
-
editPath:
|
|
2595
|
+
editPath: Je("product", w.id),
|
|
2559
2596
|
entityId: w.id,
|
|
2560
|
-
imageCount:
|
|
2561
|
-
...
|
|
2597
|
+
imageCount: b.length,
|
|
2598
|
+
..._ ? { imageError: _ } : {},
|
|
2562
2599
|
mutationExecuted: !0,
|
|
2563
2600
|
slug: a,
|
|
2564
2601
|
success: !0,
|
|
@@ -2566,32 +2603,32 @@ async function Kt(e, t) {
|
|
|
2566
2603
|
translationGroupId: w.translation_group_id
|
|
2567
2604
|
};
|
|
2568
2605
|
}
|
|
2569
|
-
function
|
|
2606
|
+
function Xe(e) {
|
|
2570
2607
|
return e.trim().replace(/[\s-]+/g, "_").toLowerCase();
|
|
2571
2608
|
}
|
|
2572
|
-
function
|
|
2573
|
-
const n = typeof t == "string" ?
|
|
2609
|
+
function Pr(e, t) {
|
|
2610
|
+
const n = typeof t == "string" ? Xe(t) : t;
|
|
2574
2611
|
return e === "product" ? n === "public" || n === "publish" || n === "published" ? "active" : n : n === "public" || n === "active" || n === "publish" ? "published" : n;
|
|
2575
2612
|
}
|
|
2576
|
-
function
|
|
2577
|
-
const t =
|
|
2613
|
+
function Nr(e) {
|
|
2614
|
+
const t = Xe(e.field);
|
|
2578
2615
|
return !!(e.startsAt || e.endsAt || t.includes("start") || t.includes("end") || t.includes("schedule") || t.includes("special_date"));
|
|
2579
2616
|
}
|
|
2580
|
-
async function
|
|
2617
|
+
async function Ur(e, t, n) {
|
|
2581
2618
|
if (e === "price" || e === "sale_price") {
|
|
2582
2619
|
if (t == null)
|
|
2583
2620
|
return { [e]: null };
|
|
2584
|
-
const r = await
|
|
2585
|
-
return { [e]:
|
|
2621
|
+
const r = await ot(n);
|
|
2622
|
+
return { [e]: Et(Number(t), r) };
|
|
2586
2623
|
}
|
|
2587
2624
|
if (e === "prices" || e === "sale_prices") {
|
|
2588
|
-
const r = await
|
|
2589
|
-
return { [e]:
|
|
2625
|
+
const r = await ot(n);
|
|
2626
|
+
return { [e]: Dn(t, r) };
|
|
2590
2627
|
}
|
|
2591
|
-
return e === "description_json" ? { description_json:
|
|
2628
|
+
return e === "description_json" ? { description_json: Ht(t) } : { [e]: t };
|
|
2592
2629
|
}
|
|
2593
|
-
function
|
|
2594
|
-
const n =
|
|
2630
|
+
function Or(e, t) {
|
|
2631
|
+
const n = Xe(e.field), r = n === "status" ? Pr(t.contentType, e.value) : e.value, a = {
|
|
2595
2632
|
description: "description_json",
|
|
2596
2633
|
feature_image: "feature_image_id",
|
|
2597
2634
|
feature_image_id: "feature_image_id",
|
|
@@ -2611,12 +2648,12 @@ function Nr(e, t) {
|
|
|
2611
2648
|
type: "product_type"
|
|
2612
2649
|
}[n] || n;
|
|
2613
2650
|
if (t.contentType !== "product") {
|
|
2614
|
-
if (!(t.contentType === "page" ?
|
|
2651
|
+
if (!(t.contentType === "page" ? Rt : qt).has(a))
|
|
2615
2652
|
throw new Error(`Field "${e.field}" cannot be updated for ${t.contentType}.`);
|
|
2616
|
-
return a === "status" &&
|
|
2653
|
+
return a === "status" && Oe(t.contentType, r), {
|
|
2617
2654
|
field: a,
|
|
2618
2655
|
payload: {
|
|
2619
|
-
[a]:
|
|
2656
|
+
[a]: Mt(a, r)
|
|
2620
2657
|
}
|
|
2621
2658
|
};
|
|
2622
2659
|
}
|
|
@@ -2645,7 +2682,7 @@ function Nr(e, t) {
|
|
|
2645
2682
|
"upc"
|
|
2646
2683
|
])).has(a))
|
|
2647
2684
|
throw new Error(`Field "${e.field}" cannot be updated for product.`);
|
|
2648
|
-
if (a === "status" &&
|
|
2685
|
+
if (a === "status" && Oe("product", r), (a === "price" || a === "sale_price") && r !== null && (typeof r != "number" || r < 0))
|
|
2649
2686
|
throw new Error(`${a} must be a non-negative number or null.`);
|
|
2650
2687
|
if (a === "stock" && (!Number.isInteger(r) || Number(r) < 0))
|
|
2651
2688
|
throw new Error("stock must be a non-negative integer.");
|
|
@@ -2660,25 +2697,25 @@ function Nr(e, t) {
|
|
|
2660
2697
|
}
|
|
2661
2698
|
};
|
|
2662
2699
|
}
|
|
2663
|
-
async function
|
|
2664
|
-
const n =
|
|
2665
|
-
if (
|
|
2700
|
+
async function Jt(e, t) {
|
|
2701
|
+
const n = xe.parse(e);
|
|
2702
|
+
if (Nr(n))
|
|
2666
2703
|
return {
|
|
2667
2704
|
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.",
|
|
2668
2705
|
mutationExecuted: !1,
|
|
2669
2706
|
success: !1,
|
|
2670
2707
|
unsupported: !0
|
|
2671
2708
|
};
|
|
2672
|
-
const r = await
|
|
2709
|
+
const r = await oe(n, t), o = Or(n, r), a = o.field;
|
|
2673
2710
|
let s = o.payload;
|
|
2674
2711
|
if (a === "language_id" && typeof s.language_id == "string") {
|
|
2675
|
-
const
|
|
2712
|
+
const h = await X(C(t), s.language_id);
|
|
2676
2713
|
s = {
|
|
2677
2714
|
...s,
|
|
2678
|
-
language_id:
|
|
2715
|
+
language_id: h.id
|
|
2679
2716
|
};
|
|
2680
2717
|
}
|
|
2681
|
-
const
|
|
2718
|
+
const c = N({
|
|
2682
2719
|
action: "UPDATE FIELD",
|
|
2683
2720
|
context: t,
|
|
2684
2721
|
payload: {
|
|
@@ -2698,75 +2735,80 @@ async function Ht(e, t) {
|
|
|
2698
2735
|
},
|
|
2699
2736
|
subject: `${r.contentType} ${r.item.slug || r.item.id} ${a}`
|
|
2700
2737
|
});
|
|
2701
|
-
if (
|
|
2702
|
-
return
|
|
2738
|
+
if (c)
|
|
2739
|
+
return c;
|
|
2740
|
+
const u = await J(
|
|
2741
|
+
t,
|
|
2742
|
+
r.contentType,
|
|
2743
|
+
r.item.id
|
|
2744
|
+
);
|
|
2703
2745
|
if (r.contentType === "product") {
|
|
2704
|
-
const
|
|
2705
|
-
...
|
|
2746
|
+
const h = C(t), p = await Ur(a, s[a], h), { data: f, error: g } = await h.from("products").update({
|
|
2747
|
+
...p,
|
|
2706
2748
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
2707
2749
|
}).eq("id", r.item.id).select("id, language_id, slug, status, title").single();
|
|
2708
|
-
if (g || !
|
|
2709
|
-
throw new Error(`Failed to update product: ${
|
|
2710
|
-
return
|
|
2750
|
+
if (g || !f)
|
|
2751
|
+
throw new Error(`Failed to update product: ${y(g)}`);
|
|
2752
|
+
return O(
|
|
2711
2753
|
t,
|
|
2712
2754
|
{
|
|
2713
2755
|
contentType: "product",
|
|
2714
|
-
entityId: String(
|
|
2715
|
-
languageId:
|
|
2716
|
-
slug:
|
|
2717
|
-
title:
|
|
2756
|
+
entityId: String(f.id),
|
|
2757
|
+
languageId: f.language_id,
|
|
2758
|
+
slug: f.slug,
|
|
2759
|
+
title: f.title
|
|
2718
2760
|
},
|
|
2719
|
-
|
|
2720
|
-
), {
|
|
2761
|
+
f.slug
|
|
2762
|
+
), await G(t, "product", f.id, u), {
|
|
2721
2763
|
contentType: "product",
|
|
2722
|
-
entityId:
|
|
2764
|
+
entityId: f.id,
|
|
2723
2765
|
field: a,
|
|
2724
2766
|
mutationExecuted: !0,
|
|
2725
|
-
slug:
|
|
2767
|
+
slug: f.slug,
|
|
2726
2768
|
success: !0,
|
|
2727
2769
|
updatedFields: [a]
|
|
2728
2770
|
};
|
|
2729
2771
|
}
|
|
2730
2772
|
a === "feature_image_id" && typeof s.feature_image_id == "string" && (s = {
|
|
2731
2773
|
...s,
|
|
2732
|
-
feature_image_id: await
|
|
2774
|
+
feature_image_id: await ne(
|
|
2733
2775
|
s.feature_image_id,
|
|
2734
2776
|
t,
|
|
2735
2777
|
typeof r.item.title == "string" ? r.item.title : void 0
|
|
2736
2778
|
)
|
|
2737
2779
|
});
|
|
2738
|
-
const
|
|
2780
|
+
const d = r.contentType === "page" ? "pages" : "posts", { data: l, error: m } = await C(t).from(d).update({
|
|
2739
2781
|
...s,
|
|
2740
2782
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
2741
2783
|
}).eq("id", r.item.id).select("id, language_id, slug, status, title").single();
|
|
2742
|
-
if (
|
|
2743
|
-
throw new Error(`Failed to update ${r.contentType}: ${
|
|
2744
|
-
return
|
|
2784
|
+
if (m || !l)
|
|
2785
|
+
throw new Error(`Failed to update ${r.contentType}: ${y(m)}`);
|
|
2786
|
+
return O(
|
|
2745
2787
|
t,
|
|
2746
2788
|
{
|
|
2747
2789
|
contentType: r.contentType,
|
|
2748
|
-
entityId: Number(
|
|
2749
|
-
languageId:
|
|
2750
|
-
slug:
|
|
2751
|
-
title:
|
|
2790
|
+
entityId: Number(l.id),
|
|
2791
|
+
languageId: l.language_id,
|
|
2792
|
+
slug: l.slug,
|
|
2793
|
+
title: l.title
|
|
2752
2794
|
},
|
|
2753
|
-
|
|
2754
|
-
), {
|
|
2795
|
+
l.slug
|
|
2796
|
+
), await G(t, r.contentType, l.id, u), {
|
|
2755
2797
|
contentType: r.contentType,
|
|
2756
|
-
entityId:
|
|
2798
|
+
entityId: l.id,
|
|
2757
2799
|
field: a,
|
|
2758
2800
|
mutationExecuted: !0,
|
|
2759
|
-
slug:
|
|
2801
|
+
slug: l.slug,
|
|
2760
2802
|
success: !0,
|
|
2761
2803
|
updatedFields: [a]
|
|
2762
2804
|
};
|
|
2763
2805
|
}
|
|
2764
|
-
async function
|
|
2765
|
-
const n =
|
|
2806
|
+
async function Wt(e, t) {
|
|
2807
|
+
const n = wt.parse(e), r = await oe(n, t);
|
|
2766
2808
|
if (r.contentType === "product")
|
|
2767
2809
|
return {
|
|
2768
2810
|
affectedCount: 1,
|
|
2769
|
-
collectionPath:
|
|
2811
|
+
collectionPath: at("product"),
|
|
2770
2812
|
contentType: "product",
|
|
2771
2813
|
item: r.item,
|
|
2772
2814
|
navigationLinkCount: 0,
|
|
@@ -2775,39 +2817,39 @@ async function Vt(e, t) {
|
|
|
2775
2817
|
};
|
|
2776
2818
|
const o = r.contentType === "page" ? "pages" : "posts", { data: a, error: s } = await C(t).from(o).select("id, slug, title, translation_group_id").eq("translation_group_id", r.item.translation_group_id);
|
|
2777
2819
|
if (s)
|
|
2778
|
-
throw new Error(`Failed to inspect related ${r.contentType}s: ${
|
|
2779
|
-
const
|
|
2820
|
+
throw new Error(`Failed to inspect related ${r.contentType}s: ${y(s)}`);
|
|
2821
|
+
const c = Array.isArray(a) ? a : [], u = c.map(
|
|
2780
2822
|
(p) => r.contentType === "page" ? p.slug === "home" ? "/" : `/${p.slug}` : `/article/${p.slug}`
|
|
2781
|
-
).filter(Boolean), d = new Set(u), { data:
|
|
2823
|
+
).filter(Boolean), d = new Set(u), { data: l, error: m } = await C(t).from("navigation_items").select("id, url");
|
|
2782
2824
|
if (m)
|
|
2783
|
-
throw new Error(`Failed to inspect related navigation links: ${
|
|
2784
|
-
const h = (Array.isArray(
|
|
2825
|
+
throw new Error(`Failed to inspect related navigation links: ${y(m)}`);
|
|
2826
|
+
const h = (Array.isArray(l) ? l : []).filter(
|
|
2785
2827
|
(p) => d.has(p.url)
|
|
2786
2828
|
).length;
|
|
2787
2829
|
return {
|
|
2788
|
-
affectedCount:
|
|
2789
|
-
collectionPath:
|
|
2830
|
+
affectedCount: c.length,
|
|
2831
|
+
collectionPath: at(r.contentType),
|
|
2790
2832
|
contentType: r.contentType,
|
|
2791
2833
|
item: r.item,
|
|
2792
2834
|
navigationLinkCount: h,
|
|
2793
2835
|
publicPaths: u,
|
|
2794
|
-
targetIds:
|
|
2836
|
+
targetIds: c.map((p) => p.id)
|
|
2795
2837
|
};
|
|
2796
2838
|
}
|
|
2797
|
-
function
|
|
2839
|
+
function Yt(e) {
|
|
2798
2840
|
const t = e.item.title || e.item.slug || "selected item", n = e.item.slug ? ` (${e.item.slug})` : "";
|
|
2799
2841
|
if (e.contentType === "product")
|
|
2800
2842
|
return `Delete product "${t}"${n}.`;
|
|
2801
2843
|
const r = [
|
|
2802
|
-
`${
|
|
2803
|
-
e.navigationLinkCount > 0 ? `${
|
|
2844
|
+
`${U(e.affectedCount, "language version")}`,
|
|
2845
|
+
e.navigationLinkCount > 0 ? `${U(e.navigationLinkCount, "navigation link")}` : null
|
|
2804
2846
|
].filter(Boolean);
|
|
2805
2847
|
return `Delete ${e.contentType} "${t}"${n}, including ${r.join(" and ")}.`;
|
|
2806
2848
|
}
|
|
2807
|
-
async function
|
|
2808
|
-
const n = await
|
|
2849
|
+
async function Fr(e, t) {
|
|
2850
|
+
const n = await Wt(e, t);
|
|
2809
2851
|
return {
|
|
2810
|
-
...
|
|
2852
|
+
...St({
|
|
2811
2853
|
action: `DELETE ${n.contentType}`,
|
|
2812
2854
|
payload: {
|
|
2813
2855
|
affectedCount: n.affectedCount,
|
|
@@ -2822,7 +2864,7 @@ async function Ur(e, t) {
|
|
|
2822
2864
|
navigationLinkCount: n.navigationLinkCount,
|
|
2823
2865
|
publicPaths: n.publicPaths,
|
|
2824
2866
|
slug: n.item.slug,
|
|
2825
|
-
summary:
|
|
2867
|
+
summary: Yt(n),
|
|
2826
2868
|
title: n.item.title
|
|
2827
2869
|
},
|
|
2828
2870
|
subject: `${n.item.id} ${n.item.slug || ""}`
|
|
@@ -2830,8 +2872,8 @@ async function Ur(e, t) {
|
|
|
2830
2872
|
preparedDelete: !0
|
|
2831
2873
|
};
|
|
2832
2874
|
}
|
|
2833
|
-
async function
|
|
2834
|
-
const n =
|
|
2875
|
+
async function Xt(e, t) {
|
|
2876
|
+
const n = Ce.parse(e), r = await Wt(n, t), o = N({
|
|
2835
2877
|
action: `DELETE ${r.contentType}`,
|
|
2836
2878
|
context: t,
|
|
2837
2879
|
payload: {
|
|
@@ -2847,7 +2889,7 @@ async function Wt(e, t) {
|
|
|
2847
2889
|
navigationLinkCount: r.navigationLinkCount,
|
|
2848
2890
|
publicPaths: r.publicPaths,
|
|
2849
2891
|
slug: r.item.slug,
|
|
2850
|
-
summary:
|
|
2892
|
+
summary: Yt(r),
|
|
2851
2893
|
title: r.item.title
|
|
2852
2894
|
},
|
|
2853
2895
|
subject: `${r.item.id} ${r.item.slug || ""}`
|
|
@@ -2856,18 +2898,18 @@ async function Wt(e, t) {
|
|
|
2856
2898
|
return o;
|
|
2857
2899
|
const a = C(t);
|
|
2858
2900
|
if (r.contentType === "product") {
|
|
2859
|
-
const { error:
|
|
2860
|
-
if (
|
|
2861
|
-
throw new Error(`Failed to delete product: ${
|
|
2901
|
+
const { error: c } = await a.from("products").delete().eq("id", r.item.id);
|
|
2902
|
+
if (c)
|
|
2903
|
+
throw new Error(`Failed to delete product: ${y(c)}`);
|
|
2862
2904
|
} else {
|
|
2863
2905
|
for (const d of r.publicPaths)
|
|
2864
2906
|
await a.from("navigation_items").delete().eq("url", d);
|
|
2865
|
-
const
|
|
2907
|
+
const c = r.contentType === "page" ? "pages" : "posts", { error: u } = await a.from(c).delete().eq("translation_group_id", r.item.translation_group_id);
|
|
2866
2908
|
if (u)
|
|
2867
|
-
throw new Error(`Failed to delete ${r.contentType}: ${
|
|
2909
|
+
throw new Error(`Failed to delete ${r.contentType}: ${y(u)}`);
|
|
2868
2910
|
}
|
|
2869
|
-
const s = t?.revalidatePath ??
|
|
2870
|
-
return s && (s(r.collectionPath), s("/cms/navigation"), r.publicPaths.forEach((
|
|
2911
|
+
const s = t?.revalidatePath ?? Re();
|
|
2912
|
+
return s && (s(r.collectionPath), s("/cms/navigation"), r.publicPaths.forEach((c) => s(c))), {
|
|
2871
2913
|
affectedCount: r.affectedCount,
|
|
2872
2914
|
collectionPath: r.collectionPath,
|
|
2873
2915
|
contentType: r.contentType,
|
|
@@ -2876,35 +2918,35 @@ async function Wt(e, t) {
|
|
|
2876
2918
|
success: !0
|
|
2877
2919
|
};
|
|
2878
2920
|
}
|
|
2879
|
-
async function
|
|
2921
|
+
async function lt(e, t) {
|
|
2880
2922
|
switch (e.tool) {
|
|
2881
2923
|
case "create_cms_page":
|
|
2882
|
-
return
|
|
2924
|
+
return We(e.input, t);
|
|
2883
2925
|
case "create_cms_post":
|
|
2884
|
-
return
|
|
2926
|
+
return Ye(e.input, t);
|
|
2885
2927
|
case "create_cms_product":
|
|
2886
|
-
return
|
|
2928
|
+
return Vt(e.input, t);
|
|
2887
2929
|
case "delete_cms_item":
|
|
2888
|
-
return
|
|
2930
|
+
return Xt(e.input, t);
|
|
2889
2931
|
case "update_cms_item_field":
|
|
2890
|
-
return
|
|
2932
|
+
return Jt(e.input, t);
|
|
2891
2933
|
case "update_content_block":
|
|
2892
|
-
return
|
|
2934
|
+
return zt(e.input, t);
|
|
2893
2935
|
case "insert_content_block":
|
|
2894
|
-
return
|
|
2936
|
+
return Gt(e.input, t);
|
|
2895
2937
|
case "update_current_cms_fields":
|
|
2896
|
-
return
|
|
2938
|
+
return Dt(e.input, t);
|
|
2897
2939
|
case "update_footer":
|
|
2898
|
-
return
|
|
2940
|
+
return Lt(e.input, t);
|
|
2899
2941
|
case "update_navigation_bar":
|
|
2900
|
-
return
|
|
2942
|
+
return jt(e.input, t);
|
|
2901
2943
|
case "update_section_column_block":
|
|
2902
|
-
return
|
|
2944
|
+
return Kt(e.input, t);
|
|
2903
2945
|
case "set_content_images":
|
|
2904
|
-
return
|
|
2946
|
+
return sn(e.input, t);
|
|
2905
2947
|
}
|
|
2906
2948
|
}
|
|
2907
|
-
function
|
|
2949
|
+
function jr(e, t) {
|
|
2908
2950
|
if (e.tool !== "create_cms_page" && e.tool !== "create_cms_post" && e.tool !== "create_cms_product" || e.input.translationGroupId || !e.input.languageCode)
|
|
2909
2951
|
return e;
|
|
2910
2952
|
const n = t[e.tool];
|
|
@@ -2916,17 +2958,17 @@ function Or(e, t) {
|
|
|
2916
2958
|
}
|
|
2917
2959
|
} : e;
|
|
2918
2960
|
}
|
|
2919
|
-
function
|
|
2961
|
+
function ut(e) {
|
|
2920
2962
|
return e === "create_cms_page" ? "page" : e === "create_cms_post" ? "post" : "product";
|
|
2921
2963
|
}
|
|
2922
|
-
function
|
|
2964
|
+
function Lr(e, t, n) {
|
|
2923
2965
|
if (e.tool !== "set_content_images")
|
|
2924
2966
|
return e;
|
|
2925
2967
|
const r = e.input;
|
|
2926
2968
|
if (r.entityId !== void 0)
|
|
2927
2969
|
return e;
|
|
2928
2970
|
const o = r.slug ? t.get(
|
|
2929
|
-
`${r.contentType || "product"}:${
|
|
2971
|
+
`${r.contentType || "product"}:${M(r.slug)}`
|
|
2930
2972
|
) : n;
|
|
2931
2973
|
return o ? {
|
|
2932
2974
|
...e,
|
|
@@ -2937,91 +2979,91 @@ function Fr(e, t, n) {
|
|
|
2937
2979
|
}
|
|
2938
2980
|
} : e;
|
|
2939
2981
|
}
|
|
2940
|
-
async function
|
|
2941
|
-
const n =
|
|
2982
|
+
async function Br(e, t) {
|
|
2983
|
+
const n = It.parse(e), r = new Set(
|
|
2942
2984
|
n.actions.filter(
|
|
2943
2985
|
(p) => p.tool === "create_cms_page" || p.tool === "create_cms_post" || p.tool === "create_cms_product"
|
|
2944
2986
|
).map((p) => {
|
|
2945
|
-
const
|
|
2946
|
-
return `${
|
|
2987
|
+
const f = p.input;
|
|
2988
|
+
return `${ut(p.tool)}:${M(f.slug || f.title || "")}`;
|
|
2947
2989
|
})
|
|
2948
2990
|
), o = (p) => {
|
|
2949
2991
|
if (p.tool !== "set_content_images")
|
|
2950
2992
|
return !1;
|
|
2951
|
-
const
|
|
2952
|
-
return
|
|
2953
|
-
`${
|
|
2993
|
+
const f = p.input;
|
|
2994
|
+
return f.slug ? r.has(
|
|
2995
|
+
`${f.contentType || "product"}:${M(f.slug)}`
|
|
2954
2996
|
) : r.size > 0;
|
|
2955
2997
|
};
|
|
2956
2998
|
if (!t?.skipConfirmation) {
|
|
2957
2999
|
const p = [];
|
|
2958
|
-
for (const
|
|
2959
|
-
if (o(
|
|
2960
|
-
const w =
|
|
3000
|
+
for (const b of n.actions) {
|
|
3001
|
+
if (o(b)) {
|
|
3002
|
+
const w = b.input;
|
|
2961
3003
|
p.push(
|
|
2962
|
-
`Set ${
|
|
3004
|
+
`Set ${U(w.images.length, "image")} on the ${w.slug ? `"${w.slug}"` : "new"} item created in this plan.`
|
|
2963
3005
|
);
|
|
2964
3006
|
continue;
|
|
2965
3007
|
}
|
|
2966
|
-
const
|
|
3008
|
+
const _ = await lt(b, {
|
|
2967
3009
|
...t,
|
|
2968
3010
|
latestUserMessage: null
|
|
2969
3011
|
});
|
|
2970
|
-
if (!
|
|
3012
|
+
if (!_ || typeof _ != "object")
|
|
2971
3013
|
return {
|
|
2972
3014
|
message: `Could not prepare action ${p.length + 1}.`,
|
|
2973
3015
|
mutationExecuted: !1,
|
|
2974
3016
|
success: !1
|
|
2975
3017
|
};
|
|
2976
|
-
if (
|
|
2977
|
-
return
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
) : p.push(`Run ${
|
|
3018
|
+
if (_.success === !1 || _.unsupported === !0)
|
|
3019
|
+
return _;
|
|
3020
|
+
_.requiresConfirmation === !0 && _.preview ? p.push(
|
|
3021
|
+
Rn(b.tool, _.preview)
|
|
3022
|
+
) : p.push(`Run ${b.tool.replace(/_/g, " ")}.`);
|
|
2981
3023
|
}
|
|
2982
|
-
const
|
|
3024
|
+
const f = n.summary || `Complete ${U(n.actions.length, "CMS action")}.`, g = N({
|
|
2983
3025
|
action: "EXECUTE CMS ACTION PLAN",
|
|
2984
3026
|
context: t,
|
|
2985
3027
|
payload: { actions: n.actions, tool: "execute_cms_action_plan" },
|
|
2986
3028
|
preview: {
|
|
2987
3029
|
actionCount: n.actions.length,
|
|
2988
3030
|
actionSummaries: p,
|
|
2989
|
-
summary:
|
|
3031
|
+
summary: f
|
|
2990
3032
|
},
|
|
2991
3033
|
subject: `${n.actions.length} actions`
|
|
2992
3034
|
});
|
|
2993
|
-
if (
|
|
2994
|
-
return
|
|
3035
|
+
if (g)
|
|
3036
|
+
return g;
|
|
2995
3037
|
}
|
|
2996
3038
|
const a = {
|
|
2997
3039
|
...t,
|
|
2998
3040
|
skipConfirmation: !0
|
|
2999
3041
|
}, s = [];
|
|
3000
|
-
let
|
|
3001
|
-
const
|
|
3042
|
+
let c = !1, u = null, d = null;
|
|
3043
|
+
const l = {}, m = /* @__PURE__ */ new Map();
|
|
3002
3044
|
let h = null;
|
|
3003
|
-
for (const [p,
|
|
3004
|
-
const
|
|
3005
|
-
|
|
3045
|
+
for (const [p, f] of n.actions.entries()) {
|
|
3046
|
+
const g = Lr(
|
|
3047
|
+
jr(f, l),
|
|
3006
3048
|
m,
|
|
3007
3049
|
h
|
|
3008
|
-
),
|
|
3009
|
-
if (s.push({ output:
|
|
3010
|
-
const
|
|
3011
|
-
if (
|
|
3012
|
-
const w =
|
|
3050
|
+
), b = await lt(g, a);
|
|
3051
|
+
if (s.push({ output: b, tool: g.tool }), b && typeof b == "object") {
|
|
3052
|
+
const _ = b;
|
|
3053
|
+
if (_.mutationExecuted === !0 && (c = !0), !u && typeof _.editPath == "string" && (u = _.editPath), typeof _.redirectPath == "string" && (d = _.redirectPath), (g.tool === "create_cms_page" || g.tool === "create_cms_post" || g.tool === "create_cms_product") && (typeof _.translationGroupId == "string" && (l[g.tool] = _.translationGroupId), _.entityId !== void 0 && _.entityId !== null)) {
|
|
3054
|
+
const w = ut(g.tool), k = {
|
|
3013
3055
|
contentType: w,
|
|
3014
|
-
entityId:
|
|
3056
|
+
entityId: _.entityId
|
|
3015
3057
|
};
|
|
3016
|
-
h =
|
|
3058
|
+
h = k, typeof _.slug == "string" && m.set(`${w}:${_.slug}`, k);
|
|
3017
3059
|
}
|
|
3018
|
-
if (
|
|
3060
|
+
if (_.success === !1 || _.unsupported === !0)
|
|
3019
3061
|
return {
|
|
3020
3062
|
actionCount: n.actions.length,
|
|
3021
3063
|
failedActionIndex: p,
|
|
3022
|
-
failedTool:
|
|
3023
|
-
message: typeof
|
|
3024
|
-
mutationExecuted:
|
|
3064
|
+
failedTool: g.tool,
|
|
3065
|
+
message: typeof _.message == "string" ? _.message : `Action ${p + 1} failed.`,
|
|
3066
|
+
mutationExecuted: c,
|
|
3025
3067
|
results: s,
|
|
3026
3068
|
success: !1,
|
|
3027
3069
|
...u ? { editPath: u } : {},
|
|
@@ -3032,18 +3074,18 @@ async function jr(e, t) {
|
|
|
3032
3074
|
return {
|
|
3033
3075
|
actionCount: n.actions.length,
|
|
3034
3076
|
editPath: d ? void 0 : u ?? void 0,
|
|
3035
|
-
mutationExecuted:
|
|
3077
|
+
mutationExecuted: c,
|
|
3036
3078
|
redirectPath: d ?? void 0,
|
|
3037
3079
|
results: s,
|
|
3038
3080
|
success: !0,
|
|
3039
3081
|
summary: n.summary ?? null
|
|
3040
3082
|
};
|
|
3041
3083
|
}
|
|
3042
|
-
const
|
|
3084
|
+
const Qt = i.strictObject({
|
|
3043
3085
|
maxChars: i.number().int().min(500).max(2e4).default(8e3).describe("Maximum characters of readable body text to return."),
|
|
3044
3086
|
url: i.string().trim().min(1).max(2048).refine((e) => /^https?:\/\//i.test(e), "URL must start with http:// or https://.")
|
|
3045
|
-
}),
|
|
3046
|
-
function
|
|
3087
|
+
}), Rr = 12e3, dt = 2e6;
|
|
3088
|
+
function pt(e) {
|
|
3047
3089
|
const t = e.trim().toLowerCase().replace(/\.$/, "").replace(/^\[|\]$/g, "");
|
|
3048
3090
|
if (!t || t === "localhost" || t.endsWith(".localhost") || t.endsWith(".local") || t.endsWith(".internal") || t === "metadata.google.internal" || t === "0.0.0.0" || t === "::1" || t.startsWith("fe80:") || t.startsWith("fc") || t.startsWith("fd"))
|
|
3049
3091
|
return !0;
|
|
@@ -3055,17 +3097,17 @@ function ut(e) {
|
|
|
3055
3097
|
}
|
|
3056
3098
|
return !1;
|
|
3057
3099
|
}
|
|
3058
|
-
function
|
|
3100
|
+
function ae(e) {
|
|
3059
3101
|
return e.replace(/<[^>]+>/g, " ").replace(/ /gi, " ").replace(/&/gi, "&").replace(/</gi, "<").replace(/>/gi, ">").replace(/"/gi, '"').replace(/'/gi, "'").replace(/\s+/g, " ").trim();
|
|
3060
3102
|
}
|
|
3061
|
-
function
|
|
3103
|
+
function qr(e) {
|
|
3062
3104
|
return e.trim().replace(/&/gi, "&").replace(/&/g, "&").replace(/"/gi, '"').replace(/'/g, "'");
|
|
3063
3105
|
}
|
|
3064
|
-
const
|
|
3065
|
-
function
|
|
3106
|
+
const Zt = /\.(avif|gif|jpe?g|png|webp)(?:[?#]|$)/i, en = /(?:^|[/_-])(?:sprite|icon|favicon|logo|placeholder|pixel|spacer|blank|avatar|badge|flag|loader|spinner|1x1|transparent|watermark|payment|visa|mastercard|paypal|amex|social|share|facebook|twitter|instagram|youtube|pinterest|linkedin)(?:[/_.-]|$)/i;
|
|
3107
|
+
function me(e, t) {
|
|
3066
3108
|
if (typeof e != "string")
|
|
3067
3109
|
return null;
|
|
3068
|
-
const n =
|
|
3110
|
+
const n = qr(e);
|
|
3069
3111
|
if (!n || n.startsWith("data:"))
|
|
3070
3112
|
return null;
|
|
3071
3113
|
try {
|
|
@@ -3075,45 +3117,45 @@ function ue(e, t) {
|
|
|
3075
3117
|
return null;
|
|
3076
3118
|
}
|
|
3077
3119
|
}
|
|
3078
|
-
function
|
|
3120
|
+
function Mr(e) {
|
|
3079
3121
|
let t = null;
|
|
3080
3122
|
for (const n of e.split(",")) {
|
|
3081
3123
|
const r = n.trim().split(/\s+/), o = r[0];
|
|
3082
3124
|
if (!o)
|
|
3083
3125
|
continue;
|
|
3084
|
-
const a = r[1] || "", s = a.match(/^(\d+(?:\.\d+)?)w$/i),
|
|
3126
|
+
const a = r[1] || "", s = a.match(/^(\d+(?:\.\d+)?)w$/i), c = a.match(/^(\d+(?:\.\d+)?)x$/i), u = s ? Number(s[1]) : c ? Number(c[1]) * 1e3 : 1;
|
|
3085
3127
|
(!t || u > t.weight) && (t = { url: o, weight: u });
|
|
3086
3128
|
}
|
|
3087
3129
|
return t?.url ?? null;
|
|
3088
3130
|
}
|
|
3089
|
-
function
|
|
3131
|
+
function j(e, t) {
|
|
3090
3132
|
const n = e.match(
|
|
3091
3133
|
new RegExp(`\\b${t}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`, "i")
|
|
3092
3134
|
);
|
|
3093
3135
|
return n ? n[1] ?? n[2] ?? n[3] ?? null : null;
|
|
3094
3136
|
}
|
|
3095
|
-
function
|
|
3096
|
-
const n = [], r = [], o = (
|
|
3097
|
-
if (typeof
|
|
3098
|
-
const d =
|
|
3137
|
+
function Dr(e, t) {
|
|
3138
|
+
const n = [], r = [], o = (c, u) => {
|
|
3139
|
+
if (typeof c == "string") {
|
|
3140
|
+
const d = me(c, t);
|
|
3099
3141
|
d && u.push(d);
|
|
3100
3142
|
return;
|
|
3101
3143
|
}
|
|
3102
|
-
if (Array.isArray(
|
|
3103
|
-
for (const d of
|
|
3144
|
+
if (Array.isArray(c)) {
|
|
3145
|
+
for (const d of c)
|
|
3104
3146
|
o(d, u);
|
|
3105
3147
|
return;
|
|
3106
3148
|
}
|
|
3107
|
-
|
|
3108
|
-
}, a = (
|
|
3109
|
-
if (u > 8 || !
|
|
3149
|
+
c && typeof c == "object" && (o(c.url, u), o(c.contentUrl, u));
|
|
3150
|
+
}, a = (c, u) => {
|
|
3151
|
+
if (u > 8 || !c || typeof c != "object")
|
|
3110
3152
|
return;
|
|
3111
|
-
if (Array.isArray(
|
|
3112
|
-
for (const p of
|
|
3153
|
+
if (Array.isArray(c)) {
|
|
3154
|
+
for (const p of c)
|
|
3113
3155
|
a(p, u + 1);
|
|
3114
3156
|
return;
|
|
3115
3157
|
}
|
|
3116
|
-
const d =
|
|
3158
|
+
const d = c, l = d["@type"], h = (Array.isArray(l) ? l : [l]).filter((p) => typeof p == "string").map((p) => p.toLowerCase()).some(
|
|
3117
3159
|
(p) => p === "product" || p === "productgroup" || p === "itempage"
|
|
3118
3160
|
);
|
|
3119
3161
|
"image" in d && o(d.image, h ? n : r);
|
|
@@ -3122,8 +3164,8 @@ function Rr(e, t) {
|
|
|
3122
3164
|
}, s = e.matchAll(
|
|
3123
3165
|
/<script\b[^>]*type\s*=\s*["']application\/ld\+json["'][^>]*>([\s\S]*?)<\/script>/gi
|
|
3124
3166
|
);
|
|
3125
|
-
for (const
|
|
3126
|
-
const u = (
|
|
3167
|
+
for (const c of s) {
|
|
3168
|
+
const u = (c[1] || "").trim();
|
|
3127
3169
|
if (u)
|
|
3128
3170
|
try {
|
|
3129
3171
|
a(JSON.parse(u), 0);
|
|
@@ -3132,8 +3174,8 @@ function Rr(e, t) {
|
|
|
3132
3174
|
}
|
|
3133
3175
|
return [...n, ...r];
|
|
3134
3176
|
}
|
|
3135
|
-
const
|
|
3136
|
-
function
|
|
3177
|
+
const tn = /(?:^|[/_-])(?:thumbnails?|thumbs?|small|mini)(?:[/_.-]|$)/i;
|
|
3178
|
+
function nn(e) {
|
|
3137
3179
|
try {
|
|
3138
3180
|
const { pathname: t } = new URL(e);
|
|
3139
3181
|
return decodeURIComponent(t.slice(t.lastIndexOf("/") + 1)).toLowerCase() || null;
|
|
@@ -3141,80 +3183,80 @@ function en(e) {
|
|
|
3141
3183
|
return null;
|
|
3142
3184
|
}
|
|
3143
3185
|
}
|
|
3144
|
-
function
|
|
3186
|
+
function zr(e, t) {
|
|
3145
3187
|
const n = /* @__PURE__ */ new Map();
|
|
3146
3188
|
for (const r of e.matchAll(/<a\b[^>]*>/gi)) {
|
|
3147
|
-
const o =
|
|
3148
|
-
if (!o || !
|
|
3189
|
+
const o = me(j(r[0], "href"), t);
|
|
3190
|
+
if (!o || !Zt.test(o) || tn.test(o) || en.test(o))
|
|
3149
3191
|
continue;
|
|
3150
|
-
const a =
|
|
3192
|
+
const a = nn(o);
|
|
3151
3193
|
a && !n.has(a) && n.set(a, o);
|
|
3152
3194
|
}
|
|
3153
3195
|
return n;
|
|
3154
3196
|
}
|
|
3155
|
-
function
|
|
3156
|
-
const n = [...
|
|
3197
|
+
function Gr(e, t) {
|
|
3198
|
+
const n = [...Dr(e, t)], r = [
|
|
3157
3199
|
/<meta\b[^>]*\b(?:property|name)\s*=\s*["'](?:og:image:secure_url|og:image:url|og:image)["'][^>]*>/gi,
|
|
3158
3200
|
/<meta\b[^>]*\b(?:property|name)\s*=\s*["'](?:twitter:image:src|twitter:image)["'][^>]*>/gi,
|
|
3159
3201
|
/<meta\b[^>]*\bitemprop\s*=\s*["']image["'][^>]*>/gi,
|
|
3160
3202
|
/<link\b[^>]*\brel\s*=\s*["']image_src["'][^>]*>/gi
|
|
3161
3203
|
];
|
|
3162
|
-
for (const
|
|
3163
|
-
for (const m of e.matchAll(
|
|
3164
|
-
const h = m[0], p =
|
|
3165
|
-
|
|
3204
|
+
for (const l of r)
|
|
3205
|
+
for (const m of e.matchAll(l)) {
|
|
3206
|
+
const h = m[0], p = me(
|
|
3207
|
+
j(h, "content") || j(h, "href"),
|
|
3166
3208
|
t
|
|
3167
3209
|
);
|
|
3168
3210
|
p && n.push(p);
|
|
3169
3211
|
}
|
|
3170
3212
|
const o = [];
|
|
3171
|
-
for (const
|
|
3172
|
-
const m =
|
|
3173
|
-
h ?
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3213
|
+
for (const l of e.matchAll(/<img\b[^>]*>/gi)) {
|
|
3214
|
+
const m = l[0], h = j(m, "srcset") || j(m, "data-srcset"), p = [
|
|
3215
|
+
h ? Mr(h) : null,
|
|
3216
|
+
j(m, "src"),
|
|
3217
|
+
j(m, "data-src"),
|
|
3218
|
+
j(m, "data-original"),
|
|
3219
|
+
j(m, "data-lazy-src"),
|
|
3220
|
+
j(m, "data-image")
|
|
3179
3221
|
];
|
|
3180
|
-
let
|
|
3181
|
-
for (const
|
|
3182
|
-
if (
|
|
3222
|
+
let f = null;
|
|
3223
|
+
for (const b of p)
|
|
3224
|
+
if (f = me(b, t), f)
|
|
3183
3225
|
break;
|
|
3184
|
-
if (!
|
|
3226
|
+
if (!f || en.test(f))
|
|
3185
3227
|
continue;
|
|
3186
|
-
const
|
|
3187
|
-
Number.isFinite(
|
|
3228
|
+
const g = Number(j(m, "width"));
|
|
3229
|
+
Number.isFinite(g) && g > 0 && g < 200 || o.push(f);
|
|
3188
3230
|
}
|
|
3189
|
-
const a = (
|
|
3190
|
-
n.push(...o.filter(a), ...o.filter((
|
|
3191
|
-
const s =
|
|
3192
|
-
if (!
|
|
3193
|
-
return
|
|
3194
|
-
const m =
|
|
3195
|
-
return m && s.get(m) ||
|
|
3231
|
+
const a = (l) => Zt.test(l);
|
|
3232
|
+
n.push(...o.filter(a), ...o.filter((l) => !a(l)));
|
|
3233
|
+
const s = zr(e, t), c = (l) => {
|
|
3234
|
+
if (!tn.test(l))
|
|
3235
|
+
return l;
|
|
3236
|
+
const m = nn(l);
|
|
3237
|
+
return m && s.get(m) || l;
|
|
3196
3238
|
}, u = /* @__PURE__ */ new Set(), d = [];
|
|
3197
|
-
for (const
|
|
3198
|
-
const m = l
|
|
3239
|
+
for (const l of n) {
|
|
3240
|
+
const m = c(l);
|
|
3199
3241
|
if (!u.has(m) && (u.add(m), d.push(m), d.length >= 12))
|
|
3200
3242
|
break;
|
|
3201
3243
|
}
|
|
3202
3244
|
return { images: d, mainImage: d[0] ?? null };
|
|
3203
3245
|
}
|
|
3204
|
-
function
|
|
3205
|
-
const r = e.replace(/<script\b[\s\S]*?<\/script>/gi, " ").replace(/<style\b[\s\S]*?<\/style>/gi, " ").replace(/<noscript\b[\s\S]*?<\/noscript>/gi, " ").replace(/<svg\b[\s\S]*?<\/svg>/gi, " "), { images: o, mainImage: a } =
|
|
3246
|
+
function Kr(e, t, n) {
|
|
3247
|
+
const r = e.replace(/<script\b[\s\S]*?<\/script>/gi, " ").replace(/<style\b[\s\S]*?<\/style>/gi, " ").replace(/<noscript\b[\s\S]*?<\/noscript>/gi, " ").replace(/<svg\b[\s\S]*?<\/svg>/gi, " "), { images: o, mainImage: a } = Gr(e, n), s = e.match(/<title\b[^>]*>([\s\S]*?)<\/title>/i), c = e.match(/<meta[^>]+name=["']description["'][^>]*content=["']([^"']*)["'][^>]*>/i) || e.match(/<meta[^>]+content=["']([^"']*)["'][^>]*name=["']description["'][^>]*>/i), u = [...r.matchAll(/<h([1-3])\b[^>]*>([\s\S]*?)<\/h\1>/gi)].map((m) => ae(m[2])).filter(Boolean).slice(0, 40), d = r.match(/<body\b[^>]*>([\s\S]*?)<\/body>/i), l = ae(d?.[1] ?? r);
|
|
3206
3248
|
return {
|
|
3207
|
-
description:
|
|
3249
|
+
description: c ? ae(c[1]) : "",
|
|
3208
3250
|
headings: u,
|
|
3209
3251
|
images: o,
|
|
3210
3252
|
mainImage: a,
|
|
3211
|
-
text:
|
|
3212
|
-
title: s ?
|
|
3213
|
-
truncated:
|
|
3253
|
+
text: l.slice(0, t),
|
|
3254
|
+
title: s ? ae(s[1]) : "",
|
|
3255
|
+
truncated: l.length > t
|
|
3214
3256
|
};
|
|
3215
3257
|
}
|
|
3216
|
-
async function
|
|
3217
|
-
const t =
|
|
3258
|
+
async function Hr(e) {
|
|
3259
|
+
const t = Qt.parse(e);
|
|
3218
3260
|
let n;
|
|
3219
3261
|
try {
|
|
3220
3262
|
n = new URL(t.url);
|
|
@@ -3223,13 +3265,13 @@ async function Gr(e) {
|
|
|
3223
3265
|
}
|
|
3224
3266
|
if (n.protocol !== "http:" && n.protocol !== "https:")
|
|
3225
3267
|
return { message: "Only http and https URLs can be fetched.", success: !1, url: t.url };
|
|
3226
|
-
if (
|
|
3268
|
+
if (pt(n.hostname))
|
|
3227
3269
|
return {
|
|
3228
3270
|
message: "Refusing to fetch a local, private, or internal address.",
|
|
3229
3271
|
success: !1,
|
|
3230
3272
|
url: t.url
|
|
3231
3273
|
};
|
|
3232
|
-
const r = new AbortController(), o = setTimeout(() => r.abort(),
|
|
3274
|
+
const r = new AbortController(), o = setTimeout(() => r.abort(), Rr);
|
|
3233
3275
|
try {
|
|
3234
3276
|
const a = await fetch(n.toString(), {
|
|
3235
3277
|
headers: {
|
|
@@ -3248,7 +3290,7 @@ async function Gr(e) {
|
|
|
3248
3290
|
};
|
|
3249
3291
|
const s = a.url || n.toString();
|
|
3250
3292
|
try {
|
|
3251
|
-
if (
|
|
3293
|
+
if (pt(new URL(s).hostname))
|
|
3252
3294
|
return {
|
|
3253
3295
|
message: "The URL redirected to a blocked internal address.",
|
|
3254
3296
|
success: !1,
|
|
@@ -3256,34 +3298,34 @@ async function Gr(e) {
|
|
|
3256
3298
|
};
|
|
3257
3299
|
} catch {
|
|
3258
3300
|
}
|
|
3259
|
-
const
|
|
3260
|
-
if (!/text\/html|text\/plain|application\/xhtml/i.test(
|
|
3301
|
+
const c = a.headers.get("content-type") || "";
|
|
3302
|
+
if (!/text\/html|text\/plain|application\/xhtml/i.test(c))
|
|
3261
3303
|
return {
|
|
3262
|
-
contentType:
|
|
3263
|
-
message: `The URL is not an HTML or text page (content-type: ${
|
|
3304
|
+
contentType: c,
|
|
3305
|
+
message: `The URL is not an HTML or text page (content-type: ${c || "unknown"}).`,
|
|
3264
3306
|
success: !1,
|
|
3265
3307
|
url: t.url
|
|
3266
3308
|
};
|
|
3267
|
-
const u = await a.text(), d = u.length >
|
|
3268
|
-
return !
|
|
3269
|
-
description:
|
|
3309
|
+
const u = await a.text(), d = u.length > dt ? u.slice(0, dt) : u, l = Kr(d, t.maxChars, s);
|
|
3310
|
+
return !l.text && !l.title ? { message: "The URL returned no readable text content.", success: !1, url: t.url } : {
|
|
3311
|
+
description: l.description,
|
|
3270
3312
|
finalUrl: s,
|
|
3271
|
-
headings:
|
|
3313
|
+
headings: l.headings,
|
|
3272
3314
|
// Ranked best-first (schema.org Product image > og:image > in-body <img>).
|
|
3273
3315
|
// `mainImage` is the page's subject image and can be passed straight into
|
|
3274
3316
|
// create_cms_product `images` / feature_image_id — it is imported into the
|
|
3275
3317
|
// media library automatically.
|
|
3276
|
-
images:
|
|
3277
|
-
mainImage:
|
|
3318
|
+
images: l.images,
|
|
3319
|
+
mainImage: l.mainImage,
|
|
3278
3320
|
success: !0,
|
|
3279
|
-
text:
|
|
3280
|
-
title:
|
|
3281
|
-
truncated:
|
|
3321
|
+
text: l.text,
|
|
3322
|
+
title: l.title,
|
|
3323
|
+
truncated: l.truncated,
|
|
3282
3324
|
url: t.url
|
|
3283
3325
|
};
|
|
3284
3326
|
} catch (a) {
|
|
3285
3327
|
return {
|
|
3286
|
-
message: a instanceof Error && (a.name === "AbortError" || /abort/i.test(a.message)) ? "Fetching the URL timed out." : `Failed to fetch the URL: ${
|
|
3328
|
+
message: a instanceof Error && (a.name === "AbortError" || /abort/i.test(a.message)) ? "Fetching the URL timed out." : `Failed to fetch the URL: ${y(a)}`,
|
|
3287
3329
|
success: !1,
|
|
3288
3330
|
url: t.url
|
|
3289
3331
|
};
|
|
@@ -3291,36 +3333,36 @@ async function Gr(e) {
|
|
|
3291
3333
|
clearTimeout(o);
|
|
3292
3334
|
}
|
|
3293
3335
|
}
|
|
3294
|
-
const
|
|
3336
|
+
const rn = i.strictObject({
|
|
3295
3337
|
count: i.number().int().min(1).max(15).default(6),
|
|
3296
3338
|
orientation: i.enum(["landscape", "portrait", "square"]).optional().describe("Preferred image orientation. Use landscape for hero/section backgrounds."),
|
|
3297
3339
|
query: i.string().trim().min(2).max(200).describe('What the photos should depict, e.g. "herbal supplements".')
|
|
3298
|
-
}),
|
|
3299
|
-
async function
|
|
3340
|
+
}), Vr = 12e3;
|
|
3341
|
+
async function Qe(e) {
|
|
3300
3342
|
let t = null, n = null;
|
|
3301
3343
|
if (e)
|
|
3302
3344
|
try {
|
|
3303
|
-
const { CORTEX_AI_PEXELS_SETTING_KEY: o, CORTEX_AI_UNSPLASH_SETTING_KEY: a, decryptStoredOpenRouterApiKey: s } = await import("./ai-config.es.js"),
|
|
3304
|
-
if (!
|
|
3345
|
+
const { CORTEX_AI_PEXELS_SETTING_KEY: o, CORTEX_AI_UNSPLASH_SETTING_KEY: a, decryptStoredOpenRouterApiKey: s } = await import("./ai-config.es.js"), c = (l) => {
|
|
3346
|
+
if (!l)
|
|
3305
3347
|
return null;
|
|
3306
3348
|
try {
|
|
3307
|
-
const m = s(
|
|
3349
|
+
const m = s(l);
|
|
3308
3350
|
return typeof m == "string" && m.trim() ? m.trim() : null;
|
|
3309
3351
|
} catch {
|
|
3310
3352
|
return null;
|
|
3311
3353
|
}
|
|
3312
3354
|
}, { data: u } = await e.from("site_settings").select("key, value").in("key", [o, a]), d = Array.isArray(u) ? u : [];
|
|
3313
|
-
t =
|
|
3355
|
+
t = c(d.find((l) => l.key === o)?.value), n = c(d.find((l) => l.key === a)?.value);
|
|
3314
3356
|
} catch {
|
|
3315
3357
|
}
|
|
3316
3358
|
t || (t = process.env.PEXELS_API_KEY?.trim() || null), n || (n = process.env.UNSPLASH_ACCESS_KEY?.trim() || null);
|
|
3317
3359
|
const r = [];
|
|
3318
3360
|
return t && r.push({ apiKey: t, provider: "pexels" }), n && r.push({ apiKey: n, provider: "unsplash" }), r;
|
|
3319
3361
|
}
|
|
3320
|
-
async function
|
|
3321
|
-
return (await
|
|
3362
|
+
async function uo(e) {
|
|
3363
|
+
return (await Qe(e))[0] ?? null;
|
|
3322
3364
|
}
|
|
3323
|
-
async function
|
|
3365
|
+
async function Jr(e) {
|
|
3324
3366
|
if (e)
|
|
3325
3367
|
try {
|
|
3326
3368
|
const { CORTEX_AI_UNSPLASH_APP_NAME_SETTING_KEY: t } = await import("./ai-config.es.js"), { data: n } = await e.from("site_settings").select("value").eq("key", t).maybeSingle(), r = n?.value;
|
|
@@ -3330,8 +3372,8 @@ async function Hr(e) {
|
|
|
3330
3372
|
}
|
|
3331
3373
|
return process.env.UNSPLASH_APP_NAME?.trim() || null;
|
|
3332
3374
|
}
|
|
3333
|
-
async function
|
|
3334
|
-
const n = new AbortController(), r = setTimeout(() => n.abort(),
|
|
3375
|
+
async function mt(e, t) {
|
|
3376
|
+
const n = new AbortController(), r = setTimeout(() => n.abort(), Vr);
|
|
3335
3377
|
try {
|
|
3336
3378
|
const o = await fetch(e, { headers: t, signal: n.signal });
|
|
3337
3379
|
if (!o.ok)
|
|
@@ -3341,34 +3383,34 @@ async function dt(e, t) {
|
|
|
3341
3383
|
clearTimeout(r);
|
|
3342
3384
|
}
|
|
3343
3385
|
}
|
|
3344
|
-
function
|
|
3386
|
+
function se(e) {
|
|
3345
3387
|
const t = Number(e);
|
|
3346
3388
|
return Number.isFinite(t) && t > 0 ? t : null;
|
|
3347
3389
|
}
|
|
3348
|
-
function
|
|
3349
|
-
if (
|
|
3390
|
+
function Fe(e, t) {
|
|
3391
|
+
if (!E(e))
|
|
3350
3392
|
return;
|
|
3351
3393
|
const n = (r) => {
|
|
3352
|
-
|
|
3394
|
+
E(r) && r.provider === "unsplash" && typeof r.downloadLocation == "string" && r.downloadLocation.trim() && t.add(r.downloadLocation.trim());
|
|
3353
3395
|
};
|
|
3354
|
-
if (n(e.attribution),
|
|
3396
|
+
if (n(e.attribution), E(e.background) && E(e.background.image) && n(e.background.image.attribution), Array.isArray(e.column_blocks)) {
|
|
3355
3397
|
for (const r of e.column_blocks)
|
|
3356
3398
|
if (Array.isArray(r))
|
|
3357
3399
|
for (const o of r)
|
|
3358
|
-
|
|
3400
|
+
E(o) && Fe(o.content, t);
|
|
3359
3401
|
}
|
|
3360
3402
|
if (Array.isArray(e.slides))
|
|
3361
3403
|
for (const r of e.slides)
|
|
3362
|
-
|
|
3404
|
+
Fe(r, t);
|
|
3363
3405
|
}
|
|
3364
|
-
async function
|
|
3406
|
+
async function $e(e, t) {
|
|
3365
3407
|
try {
|
|
3366
3408
|
const n = /* @__PURE__ */ new Set();
|
|
3367
3409
|
for (const a of e)
|
|
3368
|
-
|
|
3410
|
+
Fe(a?.content, n);
|
|
3369
3411
|
if (n.size === 0)
|
|
3370
3412
|
return;
|
|
3371
|
-
const o = (await
|
|
3413
|
+
const o = (await Qe(t)).find((a) => a.provider === "unsplash");
|
|
3372
3414
|
if (!o)
|
|
3373
3415
|
return;
|
|
3374
3416
|
await Promise.all(
|
|
@@ -3382,34 +3424,34 @@ async function ve(e, t) {
|
|
|
3382
3424
|
} catch {
|
|
3383
3425
|
}
|
|
3384
3426
|
}
|
|
3385
|
-
async function
|
|
3427
|
+
async function Wr(e, t, n) {
|
|
3386
3428
|
const r = new URLSearchParams({
|
|
3387
3429
|
per_page: String(t.count),
|
|
3388
3430
|
query: t.query
|
|
3389
3431
|
});
|
|
3390
3432
|
if (t.orientation && r.set("orientation", t.orientation), e.provider === "pexels") {
|
|
3391
|
-
const a = await
|
|
3433
|
+
const a = await mt(
|
|
3392
3434
|
`https://api.pexels.com/v1/search?${r.toString()}`,
|
|
3393
3435
|
{ Authorization: e.apiKey }
|
|
3394
3436
|
);
|
|
3395
3437
|
return (Array.isArray(a?.photos) ? a.photos : []).map((s) => {
|
|
3396
|
-
const
|
|
3438
|
+
const c = typeof s?.photographer == "string" ? s.photographer : null;
|
|
3397
3439
|
return {
|
|
3398
3440
|
alt: typeof s?.alt == "string" && s.alt.trim() ? s.alt.trim() : t.query,
|
|
3399
|
-
credit:
|
|
3441
|
+
credit: c ? `Photo by ${c} on Pexels` : "Photo on Pexels",
|
|
3400
3442
|
downloadLocation: null,
|
|
3401
|
-
height:
|
|
3402
|
-
photographer:
|
|
3443
|
+
height: se(s?.height),
|
|
3444
|
+
photographer: c,
|
|
3403
3445
|
photographerUrl: typeof s?.photographer_url == "string" ? s.photographer_url : null,
|
|
3404
3446
|
provider: "pexels",
|
|
3405
3447
|
sourceUrl: typeof s?.url == "string" ? s.url : null,
|
|
3406
3448
|
thumbnailUrl: s?.src?.medium || s?.src?.large || null,
|
|
3407
3449
|
url: s?.src?.large2x || s?.src?.large || s?.src?.original || null,
|
|
3408
|
-
width:
|
|
3450
|
+
width: se(s?.width)
|
|
3409
3451
|
};
|
|
3410
3452
|
}).filter((s) => typeof s.url == "string");
|
|
3411
3453
|
}
|
|
3412
|
-
const o = await
|
|
3454
|
+
const o = await mt(
|
|
3413
3455
|
`https://api.unsplash.com/search/photos?${r.toString()}`,
|
|
3414
3456
|
{ Authorization: `Client-ID ${e.apiKey}` }
|
|
3415
3457
|
);
|
|
@@ -3421,7 +3463,7 @@ async function Vr(e, t, n) {
|
|
|
3421
3463
|
// Unsplash requires triggering this endpoint when the photo is actually
|
|
3422
3464
|
// used; carry it so the block-persist path can fire it.
|
|
3423
3465
|
downloadLocation: typeof a?.links?.download_location == "string" ? a.links.download_location : null,
|
|
3424
|
-
height:
|
|
3466
|
+
height: se(a?.height),
|
|
3425
3467
|
photographer: s,
|
|
3426
3468
|
photographerUrl: typeof a?.user?.links?.html == "string" ? a.user.links.html : null,
|
|
3427
3469
|
provider: "unsplash",
|
|
@@ -3430,32 +3472,32 @@ async function Vr(e, t, n) {
|
|
|
3430
3472
|
url: a?.urls?.regular || a?.urls?.full || a?.urls?.raw || null,
|
|
3431
3473
|
// The operator's registered Unsplash app name for the attribution utm_source.
|
|
3432
3474
|
utmSource: n || null,
|
|
3433
|
-
width:
|
|
3475
|
+
width: se(a?.width)
|
|
3434
3476
|
};
|
|
3435
3477
|
}).filter((a) => typeof a.url == "string");
|
|
3436
3478
|
}
|
|
3437
|
-
async function
|
|
3438
|
-
const n =
|
|
3479
|
+
async function Yr(e, t) {
|
|
3480
|
+
const n = rn.parse(e), r = await Qe(t?.supabase);
|
|
3439
3481
|
if (r.length === 0)
|
|
3440
3482
|
return {
|
|
3441
3483
|
message: "No stock photo provider is configured. Add a free Pexels or Unsplash API key in /cms/settings/cortex-ai (or set PEXELS_API_KEY / UNSPLASH_ACCESS_KEY).",
|
|
3442
3484
|
photos: [],
|
|
3443
3485
|
success: !1
|
|
3444
3486
|
};
|
|
3445
|
-
const o = r.some((
|
|
3487
|
+
const o = r.some((c) => c.provider === "unsplash") ? await Jr(t?.supabase) : null, a = [];
|
|
3446
3488
|
let s = null;
|
|
3447
|
-
for (const
|
|
3448
|
-
a.push(
|
|
3489
|
+
for (const c of r) {
|
|
3490
|
+
a.push(c.provider);
|
|
3449
3491
|
try {
|
|
3450
|
-
const u = await
|
|
3492
|
+
const u = await Wr(c, n, o);
|
|
3451
3493
|
if (u.length > 0)
|
|
3452
3494
|
return {
|
|
3453
3495
|
attemptedProviders: a,
|
|
3454
3496
|
photos: u,
|
|
3455
|
-
provider:
|
|
3497
|
+
provider: c.provider,
|
|
3456
3498
|
query: n.query,
|
|
3457
3499
|
success: !0,
|
|
3458
|
-
usageGuidance:
|
|
3500
|
+
usageGuidance: c.provider === "unsplash" ? 'Unsplash photos: keep them hotlinked (use `url` as external_url; never save an Unsplash photo to the media library) and attribute each one — copy the photo\'s attribution fields into the image content\'s `attribution` (photographer, photographerUrl, sourceUrl, downloadLocation, utmSource, provider "unsplash"). The site renders the "Photo by … on Unsplash" credit from `attribution` automatically, so do NOT also copy the credit into `caption` (leave caption empty unless you have a genuine descriptive caption).' : 'Set the image content\'s `attribution` (photographer, photographerUrl, sourceUrl, provider "pexels"). The site renders the "Photo by … on Pexels" credit from `attribution` automatically, so do NOT also copy the credit into `caption` (leave caption empty unless you have a genuine descriptive caption). Pexels attribution is appreciated but optional.'
|
|
3459
3501
|
};
|
|
3460
3502
|
} catch (u) {
|
|
3461
3503
|
s = u;
|
|
@@ -3463,13 +3505,13 @@ async function Jr(e, t) {
|
|
|
3463
3505
|
}
|
|
3464
3506
|
return {
|
|
3465
3507
|
attemptedProviders: a,
|
|
3466
|
-
message: s ? `Stock photo search failed across ${a.join(", ")}: ${
|
|
3508
|
+
message: s ? `Stock photo search failed across ${a.join(", ")}: ${y(s)}` : `No matching stock photos found for "${n.query}".`,
|
|
3467
3509
|
photos: [],
|
|
3468
3510
|
success: !1
|
|
3469
3511
|
};
|
|
3470
3512
|
}
|
|
3471
|
-
const
|
|
3472
|
-
blocks: i.array(
|
|
3513
|
+
const on = W.extend({
|
|
3514
|
+
blocks: i.array(te).min(1).max(20),
|
|
3473
3515
|
meta: i.strictObject({
|
|
3474
3516
|
meta_description: i.string().max(500).nullable().optional(),
|
|
3475
3517
|
meta_title: i.string().max(160).nullable().optional(),
|
|
@@ -3477,7 +3519,7 @@ const nn = H.extend({
|
|
|
3477
3519
|
status: i.enum(["draft", "published", "archived"]).optional(),
|
|
3478
3520
|
title: i.string().trim().min(1).max(300).optional()
|
|
3479
3521
|
}).partial().optional()
|
|
3480
|
-
}),
|
|
3522
|
+
}), Xr = [
|
|
3481
3523
|
"custom_canonical",
|
|
3482
3524
|
"excerpt",
|
|
3483
3525
|
"feature_image_id",
|
|
@@ -3492,91 +3534,91 @@ const nn = H.extend({
|
|
|
3492
3534
|
"title",
|
|
3493
3535
|
"translation_group_id"
|
|
3494
3536
|
];
|
|
3495
|
-
function
|
|
3537
|
+
function Qr(e) {
|
|
3496
3538
|
const t = {};
|
|
3497
|
-
for (const n of
|
|
3539
|
+
for (const n of Xr)
|
|
3498
3540
|
n in e && e[n] !== void 0 && (t[n] = e[n]);
|
|
3499
3541
|
return t;
|
|
3500
3542
|
}
|
|
3501
|
-
function
|
|
3543
|
+
function Zr(e, t) {
|
|
3502
3544
|
if (!t)
|
|
3503
3545
|
return null;
|
|
3504
3546
|
const n = e === "page" ? t === "home" ? "/" : `/${t}` : `/article/${t}`;
|
|
3505
3547
|
return `/api/draft/start?path=${encodeURIComponent(n)}`;
|
|
3506
3548
|
}
|
|
3507
|
-
async function
|
|
3508
|
-
const n =
|
|
3549
|
+
async function eo(e, t) {
|
|
3550
|
+
const n = on.parse(e), r = C(t), o = Me(t), a = await oe(n, t);
|
|
3509
3551
|
if (a.contentType === "product")
|
|
3510
3552
|
throw new Error(
|
|
3511
3553
|
"rewrite_page_draft supports pages and posts only. Products use description_json, not page blocks."
|
|
3512
3554
|
);
|
|
3513
|
-
const s = a.contentType,
|
|
3514
|
-
if (!Number.isInteger(
|
|
3555
|
+
const s = a.contentType, c = Number(a.item.id);
|
|
3556
|
+
if (!Number.isInteger(c) || c <= 0)
|
|
3515
3557
|
throw new Error("Could not resolve a valid page/post id for the draft rewrite.");
|
|
3516
3558
|
const u = Number(a.item.language_id);
|
|
3517
3559
|
if (!Number.isInteger(u) || u <= 0)
|
|
3518
3560
|
throw new Error("The target page/post is missing a language id.");
|
|
3519
|
-
const
|
|
3520
|
-
block_type:
|
|
3521
|
-
content:
|
|
3561
|
+
const l = Ee(n.blocks, void 0, void 0, t).map((I, $) => ({
|
|
3562
|
+
block_type: I.block_type,
|
|
3563
|
+
content: I.content,
|
|
3522
3564
|
language_id: u,
|
|
3523
|
-
order:
|
|
3524
|
-
page_id: s === "page" ?
|
|
3525
|
-
post_id: s === "post" ?
|
|
3565
|
+
order: $,
|
|
3566
|
+
page_id: s === "page" ? c : null,
|
|
3567
|
+
post_id: s === "post" ? c : null,
|
|
3526
3568
|
product_id: null
|
|
3527
|
-
})), m =
|
|
3569
|
+
})), m = Qr(a.item);
|
|
3528
3570
|
if (n.meta)
|
|
3529
|
-
for (const [
|
|
3530
|
-
|
|
3531
|
-
const h =
|
|
3571
|
+
for (const [I, $] of Object.entries(n.meta))
|
|
3572
|
+
$ !== void 0 && (m[I] = $);
|
|
3573
|
+
const h = Ct(
|
|
3532
3574
|
typeof m.slug == "string" ? m.slug : a.item.slug
|
|
3533
|
-
), p = typeof m.title == "string" && m.title.trim() ? m.title : String(a.item.title || h || "Untitled"),
|
|
3575
|
+
), p = typeof m.title == "string" && m.title.trim() ? m.title : String(a.item.title || h || "Untitled"), f = s === "page" ? `/cms/pages/${c}/edit` : `/cms/posts/${c}/edit`, g = Zr(s, h), _ = N({
|
|
3534
3576
|
action: "REWRITE DRAFT",
|
|
3535
3577
|
context: t,
|
|
3536
3578
|
payload: {
|
|
3537
|
-
blocks:
|
|
3579
|
+
blocks: l,
|
|
3538
3580
|
meta: m,
|
|
3539
|
-
parent_id:
|
|
3581
|
+
parent_id: c,
|
|
3540
3582
|
parent_type: s,
|
|
3541
3583
|
tool: "rewrite_page_draft"
|
|
3542
3584
|
},
|
|
3543
3585
|
preview: {
|
|
3544
|
-
blockCount:
|
|
3586
|
+
blockCount: l.length,
|
|
3545
3587
|
contentType: s,
|
|
3546
3588
|
slug: h,
|
|
3547
|
-
summary: `Stage a Live Draft that replaces the ${s} "${p}" with ${
|
|
3548
|
-
|
|
3589
|
+
summary: `Stage a Live Draft that replaces the ${s} "${p}" with ${U(
|
|
3590
|
+
l.length,
|
|
3549
3591
|
"new block"
|
|
3550
3592
|
)}. Nothing goes live until you review the draft and click Publish (which also saves a revision snapshot).`,
|
|
3551
3593
|
title: p
|
|
3552
3594
|
},
|
|
3553
|
-
subject: `${s}-${
|
|
3595
|
+
subject: `${s}-${c}`
|
|
3554
3596
|
});
|
|
3555
|
-
if (
|
|
3556
|
-
return
|
|
3557
|
-
const w = Number(a.item.version) || 1, { error:
|
|
3558
|
-
if (
|
|
3559
|
-
throw new Error(`Failed to clear the existing draft: ${
|
|
3560
|
-
const { error:
|
|
3597
|
+
if (_)
|
|
3598
|
+
return _;
|
|
3599
|
+
const w = Number(a.item.version) || 1, { error: k } = await r.from("content_drafts").delete().eq("parent_type", s).eq("parent_id", c);
|
|
3600
|
+
if (k)
|
|
3601
|
+
throw new Error(`Failed to clear the existing draft: ${y(k)}`);
|
|
3602
|
+
const { error: T } = await r.from("content_drafts").insert({
|
|
3561
3603
|
author_id: o,
|
|
3562
3604
|
base_version: w,
|
|
3563
|
-
blocks:
|
|
3605
|
+
blocks: l,
|
|
3564
3606
|
meta: m,
|
|
3565
|
-
parent_id:
|
|
3607
|
+
parent_id: c,
|
|
3566
3608
|
parent_type: s
|
|
3567
3609
|
});
|
|
3568
|
-
if (
|
|
3569
|
-
throw new Error(`Failed to save the draft: ${
|
|
3570
|
-
return
|
|
3610
|
+
if (T)
|
|
3611
|
+
throw new Error(`Failed to save the draft: ${y(T)}`);
|
|
3612
|
+
return $e(l, r), O(
|
|
3571
3613
|
t,
|
|
3572
|
-
{ contentType: s, entityId:
|
|
3614
|
+
{ contentType: s, entityId: c, slug: h },
|
|
3573
3615
|
h
|
|
3574
3616
|
), {
|
|
3575
|
-
blockCount:
|
|
3617
|
+
blockCount: l.length,
|
|
3576
3618
|
contentType: s,
|
|
3577
|
-
draftPreviewPath:
|
|
3578
|
-
editPath:
|
|
3579
|
-
entityId:
|
|
3619
|
+
draftPreviewPath: g,
|
|
3620
|
+
editPath: f,
|
|
3621
|
+
entityId: c,
|
|
3580
3622
|
isDraft: !0,
|
|
3581
3623
|
mutationExecuted: !0,
|
|
3582
3624
|
slug: h,
|
|
@@ -3584,7 +3626,7 @@ async function Qr(e, t) {
|
|
|
3584
3626
|
title: p
|
|
3585
3627
|
};
|
|
3586
3628
|
}
|
|
3587
|
-
const
|
|
3629
|
+
const to = /* @__PURE__ */ new Set([
|
|
3588
3630
|
"alt_text",
|
|
3589
3631
|
"author_name",
|
|
3590
3632
|
"author_title",
|
|
@@ -3599,7 +3641,7 @@ const Zr = /* @__PURE__ */ new Set([
|
|
|
3599
3641
|
"text_content",
|
|
3600
3642
|
"title"
|
|
3601
3643
|
]);
|
|
3602
|
-
function
|
|
3644
|
+
function je(e, t, n) {
|
|
3603
3645
|
if (!e)
|
|
3604
3646
|
return e;
|
|
3605
3647
|
if (Object.prototype.hasOwnProperty.call(t, e))
|
|
@@ -3612,93 +3654,93 @@ function Oe(e, t, n) {
|
|
|
3612
3654
|
a && o.includes(a) && (o = o.split(a).join(s));
|
|
3613
3655
|
return o;
|
|
3614
3656
|
}
|
|
3615
|
-
function
|
|
3657
|
+
function Le(e, t, n) {
|
|
3616
3658
|
if (Array.isArray(e))
|
|
3617
|
-
return e.map((r) =>
|
|
3659
|
+
return e.map((r) => Le(r, t, n));
|
|
3618
3660
|
if (e && typeof e == "object") {
|
|
3619
3661
|
const r = {};
|
|
3620
3662
|
for (const [o, a] of Object.entries(e))
|
|
3621
|
-
typeof a == "string" &&
|
|
3663
|
+
typeof a == "string" && to.has(o) ? r[o] = je(a, t, n) : a && typeof a == "object" ? r[o] = Le(a, t, n) : r[o] = a;
|
|
3622
3664
|
return r;
|
|
3623
3665
|
}
|
|
3624
3666
|
return e;
|
|
3625
3667
|
}
|
|
3626
|
-
const
|
|
3668
|
+
const an = i.strictObject({
|
|
3627
3669
|
targetLanguageCode: i.string().trim().min(2).max(80).describe('Target language code or name, e.g. "fr" or "French".'),
|
|
3628
3670
|
title: i.string().trim().min(1).max(300).optional().describe("Translated page title (defaults to translating the source title)."),
|
|
3629
3671
|
translations: i.record(i.string(), i.string()).describe(
|
|
3630
3672
|
'Map of every visible source string to its translation, e.g. { "Explore Our Products": "Explorez nos produits" }. Include headings, paragraph text, button labels, image alt text, captions, and form labels.'
|
|
3631
3673
|
)
|
|
3632
3674
|
});
|
|
3633
|
-
async function
|
|
3634
|
-
const n =
|
|
3675
|
+
async function no(e, t) {
|
|
3676
|
+
const n = an.parse(e), r = Y(t);
|
|
3635
3677
|
if (r.contentType === "product")
|
|
3636
3678
|
throw new Error("translate_page supports pages and posts only.");
|
|
3637
|
-
const o = C(t), a =
|
|
3679
|
+
const o = C(t), a = qe(r), s = r.contentType === "page" ? "pages" : "posts", c = r.contentType === "page" ? "page_id" : "post_id", { data: u, error: d } = await o.from(s).select("*").eq("id", a).single();
|
|
3638
3680
|
if (d || !u)
|
|
3639
3681
|
throw new Error(
|
|
3640
|
-
`Could not read the source ${r.contentType} to translate: ${
|
|
3682
|
+
`Could not read the source ${r.contentType} to translate: ${y(d)}`
|
|
3641
3683
|
);
|
|
3642
|
-
const { data:
|
|
3684
|
+
const { data: l, error: m } = await o.from("blocks").select("id, block_type, content, order").eq(c, a);
|
|
3643
3685
|
if (m)
|
|
3644
|
-
throw new Error(`Could not read the source blocks: ${
|
|
3645
|
-
const h = (Array.isArray(
|
|
3686
|
+
throw new Error(`Could not read the source blocks: ${y(m)}`);
|
|
3687
|
+
const h = (Array.isArray(l) ? l : []).slice().sort((x, A) => Number(x.order) - Number(A.order));
|
|
3646
3688
|
if (h.length === 0)
|
|
3647
3689
|
throw new Error(`The source ${r.contentType} has no content blocks to translate.`);
|
|
3648
|
-
const p = n.translations || {},
|
|
3649
|
-
blockType:
|
|
3650
|
-
content:
|
|
3690
|
+
const p = n.translations || {}, f = Object.entries(p).filter(([x]) => !!x).sort((x, A) => A[0].length - x[0].length), g = h.map((x, A) => ({
|
|
3691
|
+
blockType: x.block_type,
|
|
3692
|
+
content: Le(K(x.content), p, f),
|
|
3651
3693
|
order: A
|
|
3652
|
-
})),
|
|
3653
|
-
blocks:
|
|
3694
|
+
})), b = await Se(o, n.targetLanguageCode), _ = String(u.title || ""), w = n.title || je(_, p, f) || _ || "Untitled", k = (x) => typeof x == "string" && x.trim() ? je(x, p, f) : void 0, T = M(w) || u.slug || "translated-page", I = {
|
|
3695
|
+
blocks: g,
|
|
3654
3696
|
feature_image_id: u.feature_image_id ?? void 0,
|
|
3655
|
-
languageCode:
|
|
3656
|
-
meta_description:
|
|
3657
|
-
meta_title:
|
|
3658
|
-
slug:
|
|
3697
|
+
languageCode: b.code,
|
|
3698
|
+
meta_description: k(u.meta_description),
|
|
3699
|
+
meta_title: k(u.meta_title),
|
|
3700
|
+
slug: T,
|
|
3659
3701
|
// Publish the translation immediately so it goes live the moment the owner
|
|
3660
3702
|
// confirms — the localized homepage/page is then reachable and the public
|
|
3661
3703
|
// language switcher can find it (drafts are filtered out of public lookups).
|
|
3662
3704
|
status: "published",
|
|
3663
3705
|
title: w,
|
|
3664
3706
|
translationGroupId: u.translation_group_id || void 0
|
|
3665
|
-
},
|
|
3666
|
-
...
|
|
3667
|
-
excerpt:
|
|
3668
|
-
label:
|
|
3707
|
+
}, $ = r.contentType === "post" ? {
|
|
3708
|
+
...I,
|
|
3709
|
+
excerpt: k(u.excerpt),
|
|
3710
|
+
label: k(u.label),
|
|
3669
3711
|
// Inherit the source post's publish date (or "now" if it has none) so a
|
|
3670
3712
|
// published translation sorts alongside its original in the article list
|
|
3671
3713
|
// instead of jumping to the top with a null published_at.
|
|
3672
3714
|
published_at: u.published_at ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
3673
|
-
subtitle:
|
|
3674
|
-
} :
|
|
3715
|
+
subtitle: k(u.subtitle)
|
|
3716
|
+
} : I, P = N({
|
|
3675
3717
|
action: "TRANSLATE",
|
|
3676
3718
|
context: t,
|
|
3677
|
-
payload: { createInput:
|
|
3719
|
+
payload: { createInput: $, sourceId: u.id, tool: "translate_page" },
|
|
3678
3720
|
preview: {
|
|
3679
|
-
blockCount:
|
|
3721
|
+
blockCount: g.length,
|
|
3680
3722
|
contentType: r.contentType,
|
|
3681
|
-
languageCode:
|
|
3682
|
-
slug:
|
|
3683
|
-
status:
|
|
3684
|
-
summary: `Publish a ${
|
|
3685
|
-
|
|
3723
|
+
languageCode: b.code,
|
|
3724
|
+
slug: I.slug,
|
|
3725
|
+
status: I.status,
|
|
3726
|
+
summary: `Publish a ${b.code.toUpperCase()} translation of "${_}" — it goes live immediately, linked to the original ${r.contentType}, at /${I.slug} with ${U(
|
|
3727
|
+
g.length,
|
|
3686
3728
|
"translated block"
|
|
3687
3729
|
)}.`,
|
|
3688
3730
|
title: w
|
|
3689
3731
|
},
|
|
3690
|
-
subject: `translate ${r.contentType} ${u.id} to ${
|
|
3732
|
+
subject: `translate ${r.contentType} ${u.id} to ${b.code}`
|
|
3691
3733
|
});
|
|
3692
|
-
if (
|
|
3693
|
-
return
|
|
3694
|
-
const
|
|
3695
|
-
return { ...r.contentType === "post" ? await
|
|
3734
|
+
if (P)
|
|
3735
|
+
return P;
|
|
3736
|
+
const L = { ...t, skipConfirmation: !0 };
|
|
3737
|
+
return { ...r.contentType === "post" ? await Ye($, L) : await We($, L), isTranslation: !0, languageCode: b.code };
|
|
3696
3738
|
}
|
|
3697
|
-
async function
|
|
3698
|
-
const n =
|
|
3739
|
+
async function sn(e, t) {
|
|
3740
|
+
const n = be.parse(e), r = n.entityId !== void 0 || !!n.slug || !!n.title, o = C(t);
|
|
3699
3741
|
let a, s;
|
|
3700
3742
|
if (r) {
|
|
3701
|
-
const g = await
|
|
3743
|
+
const g = await oe(
|
|
3702
3744
|
{
|
|
3703
3745
|
contentType: n.contentType,
|
|
3704
3746
|
entityId: n.entityId,
|
|
@@ -3706,16 +3748,16 @@ async function on(e, t) {
|
|
|
3706
3748
|
title: n.title
|
|
3707
3749
|
},
|
|
3708
3750
|
t
|
|
3709
|
-
),
|
|
3710
|
-
s =
|
|
3751
|
+
), b = g.item;
|
|
3752
|
+
s = b.id, a = {
|
|
3711
3753
|
contentType: g.contentType,
|
|
3712
3754
|
entityId: s,
|
|
3713
|
-
slug: typeof
|
|
3714
|
-
title: typeof
|
|
3755
|
+
slug: typeof b.slug == "string" ? b.slug : "",
|
|
3756
|
+
title: typeof b.title == "string" ? b.title : ""
|
|
3715
3757
|
};
|
|
3716
3758
|
} else
|
|
3717
|
-
a =
|
|
3718
|
-
const
|
|
3759
|
+
a = Y(t), s = q(a);
|
|
3760
|
+
const c = a.title || a.slug || "current item", u = a.contentType === "product", d = N({
|
|
3719
3761
|
action: "SET IMAGES",
|
|
3720
3762
|
context: t,
|
|
3721
3763
|
payload: {
|
|
@@ -3728,43 +3770,43 @@ async function on(e, t) {
|
|
|
3728
3770
|
contentType: a.contentType,
|
|
3729
3771
|
imageCount: n.images.length,
|
|
3730
3772
|
slug: a.slug,
|
|
3731
|
-
summary: u ? `Set ${
|
|
3773
|
+
summary: u ? `Set ${U(
|
|
3732
3774
|
n.images.length,
|
|
3733
3775
|
"image"
|
|
3734
|
-
)} on product "${
|
|
3776
|
+
)} on product "${c}" (the first becomes the main product image, the rest the gallery).` : `Set the feature image on the ${a.contentType} "${c}".`,
|
|
3735
3777
|
title: a.title
|
|
3736
3778
|
},
|
|
3737
3779
|
subject: `set images on ${a.contentType} ${String(s)}`
|
|
3738
3780
|
});
|
|
3739
3781
|
if (d)
|
|
3740
3782
|
return d;
|
|
3741
|
-
const
|
|
3742
|
-
if (
|
|
3783
|
+
const l = await xt(n.images, t, c);
|
|
3784
|
+
if (l.length === 0)
|
|
3743
3785
|
throw new Error("None of the provided images could be resolved to a media item.");
|
|
3744
3786
|
if (u) {
|
|
3745
|
-
const { data: g, error:
|
|
3746
|
-
if (
|
|
3787
|
+
const { data: g, error: b } = await o.from("products").select("id, slug, language_id, title").eq("id", s).maybeSingle();
|
|
3788
|
+
if (b || !g)
|
|
3747
3789
|
throw new Error(
|
|
3748
|
-
`Could not load the product to set images: ${
|
|
3790
|
+
`Could not load the product to set images: ${y(b)}`
|
|
3749
3791
|
);
|
|
3750
|
-
const
|
|
3751
|
-
mediaIds:
|
|
3792
|
+
const _ = await Un({
|
|
3793
|
+
mediaIds: l,
|
|
3752
3794
|
productId: s,
|
|
3753
3795
|
supabase: o
|
|
3754
3796
|
});
|
|
3755
|
-
return await
|
|
3756
|
-
patch: ({ meta:
|
|
3797
|
+
return await ve({
|
|
3798
|
+
patch: ({ meta: w }) => Array.isArray(w.product_media) ? {
|
|
3757
3799
|
meta: {
|
|
3758
|
-
...
|
|
3759
|
-
product_media:
|
|
3760
|
-
media_id:
|
|
3761
|
-
sort_order:
|
|
3800
|
+
...w,
|
|
3801
|
+
product_media: _.map((k, T) => ({
|
|
3802
|
+
media_id: k,
|
|
3803
|
+
sort_order: T
|
|
3762
3804
|
}))
|
|
3763
3805
|
}
|
|
3764
3806
|
} : {},
|
|
3765
3807
|
productId: s,
|
|
3766
3808
|
supabase: o
|
|
3767
|
-
}),
|
|
3809
|
+
}), O(
|
|
3768
3810
|
t,
|
|
3769
3811
|
{
|
|
3770
3812
|
contentType: "product",
|
|
@@ -3777,210 +3819,210 @@ async function on(e, t) {
|
|
|
3777
3819
|
), t?.revalidatePath?.("/cms/products"), {
|
|
3778
3820
|
contentType: "product",
|
|
3779
3821
|
entityId: s,
|
|
3780
|
-
imageCount:
|
|
3822
|
+
imageCount: _.length,
|
|
3781
3823
|
mutationExecuted: !0,
|
|
3782
3824
|
slug: g.slug,
|
|
3783
3825
|
success: !0
|
|
3784
3826
|
};
|
|
3785
3827
|
}
|
|
3786
|
-
const m = a.contentType === "page" ? "pages" : "posts", { data:
|
|
3787
|
-
feature_image_id:
|
|
3828
|
+
const m = await J(t, a.contentType, s), h = a.contentType === "page" ? "pages" : "posts", { data: p, error: f } = await o.from(h).update({
|
|
3829
|
+
feature_image_id: l[0],
|
|
3788
3830
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
3789
3831
|
}).eq("id", s).select("id, language_id, slug, status, title").single();
|
|
3790
|
-
if (
|
|
3791
|
-
throw new Error(`Failed to set the feature image: ${
|
|
3792
|
-
return
|
|
3832
|
+
if (f || !p)
|
|
3833
|
+
throw new Error(`Failed to set the feature image: ${y(f)}`);
|
|
3834
|
+
return await G(t, a.contentType, s, m), O(t, a, p.slug), {
|
|
3793
3835
|
contentType: a.contentType,
|
|
3794
3836
|
entityId: s,
|
|
3795
|
-
extraImagesIgnored:
|
|
3837
|
+
extraImagesIgnored: l.length - 1,
|
|
3796
3838
|
imageCount: 1,
|
|
3797
3839
|
mutationExecuted: !0,
|
|
3798
|
-
slug:
|
|
3840
|
+
slug: p.slug,
|
|
3799
3841
|
success: !0
|
|
3800
3842
|
};
|
|
3801
3843
|
}
|
|
3802
|
-
function
|
|
3844
|
+
function po(e) {
|
|
3803
3845
|
return {
|
|
3804
|
-
...
|
|
3805
|
-
...
|
|
3806
|
-
fetch_ecommerce_stats:
|
|
3846
|
+
...cn(e),
|
|
3847
|
+
...ln(e),
|
|
3848
|
+
fetch_ecommerce_stats: v({
|
|
3807
3849
|
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.",
|
|
3808
|
-
execute: (t) =>
|
|
3809
|
-
inputSchema:
|
|
3850
|
+
execute: (t) => Tr(t, e),
|
|
3851
|
+
inputSchema: yt,
|
|
3810
3852
|
strict: !0
|
|
3811
3853
|
}),
|
|
3812
|
-
read_current_cms_item:
|
|
3854
|
+
read_current_cms_item: v({
|
|
3813
3855
|
description: "Read the CMS item currently being edited. Requires pageContext and returns page/post/product metadata plus page/post block summaries or content.",
|
|
3814
|
-
execute: (t) =>
|
|
3815
|
-
inputSchema:
|
|
3856
|
+
execute: (t) => xr(t, e),
|
|
3857
|
+
inputSchema: bt,
|
|
3816
3858
|
strict: !0
|
|
3817
3859
|
}),
|
|
3818
|
-
search_documentation:
|
|
3860
|
+
search_documentation: v({
|
|
3819
3861
|
description: "Search the NextBlock documentation database and return concise source snippets for factual CMS guidance.",
|
|
3820
|
-
execute: (t) =>
|
|
3821
|
-
inputSchema:
|
|
3862
|
+
execute: (t) => _r(t, e),
|
|
3863
|
+
inputSchema: Be,
|
|
3822
3864
|
strict: !0
|
|
3823
3865
|
}),
|
|
3824
|
-
fetch_url_content:
|
|
3866
|
+
fetch_url_content: v({
|
|
3825
3867
|
description: "Fetch an external web page and return its title, meta description, headings, body text, AND its images: `mainImage` (the page's subject image — schema.org Product image, else og:image, else the best in-body <img>) plus a ranked `images` list, all as absolute URLs. Read-only, no confirmation. Use this first whenever the user references an external URL to copy, adapt, clone, or draw inspiration from. To reuse the source page's image, pass `mainImage` straight into create_cms_product `images` or a page/post `feature_image_id` — it is imported into the media library automatically. Never invent an image URL: if `mainImage` is null, the page had none.",
|
|
3826
|
-
execute: (t) =>
|
|
3827
|
-
inputSchema:
|
|
3868
|
+
execute: (t) => Hr(t),
|
|
3869
|
+
inputSchema: Qt,
|
|
3828
3870
|
strict: !0
|
|
3829
3871
|
}),
|
|
3830
|
-
search_stock_photos:
|
|
3872
|
+
search_stock_photos: v({
|
|
3831
3873
|
description: "Find relevant, free, high-quality stock photos (Unsplash/Pexels) for page imagery. Returns a list of photos each with a direct image `url`, `width`, `height`, `alt`, and `photographer`. Read-only, zero cost. Use the returned `url` directly as an image block's external_url or a section image background's image.external_url when building or revamping pages, so layouts show real photos instantly. Set orientation \"landscape\" for hero/section backgrounds.",
|
|
3832
|
-
execute: (t) =>
|
|
3833
|
-
inputSchema:
|
|
3874
|
+
execute: (t) => Yr(t, e),
|
|
3875
|
+
inputSchema: rn,
|
|
3834
3876
|
strict: !0
|
|
3835
3877
|
}),
|
|
3836
|
-
rewrite_page_draft:
|
|
3878
|
+
rewrite_page_draft: v({
|
|
3837
3879
|
description: 'Replace ALL blocks of an existing page or post with a brand-new set of blocks, staged as a Live Draft (content_drafts) that the user previews before publishing. Use this for whole-page redesigns/rewrites such as "rewrite my home page with 5 sections". Provide the complete new list of top-level blocks in `blocks` (usually section blocks for a landing/home page, each with nested heading/text/button blocks). Nothing goes live until the user publishes the draft, and publishing auto-creates a revision snapshot so the change is reversible. Mutating: first returns a confirmation phrase; only stages the draft after the user replies with the exact phrase.',
|
|
3838
|
-
execute: (t) =>
|
|
3839
|
-
inputSchema:
|
|
3880
|
+
execute: (t) => eo(t, e),
|
|
3881
|
+
inputSchema: on,
|
|
3840
3882
|
strict: !0
|
|
3841
3883
|
}),
|
|
3842
|
-
translate_page:
|
|
3884
|
+
translate_page: v({
|
|
3843
3885
|
description: 'Translate the CURRENT page or post into another language. This copies the source page\'s entire structure, layout, and images automatically and links the new page to the original as a translation — you ONLY supply the text translations. Provide targetLanguageCode (e.g. "fr") and a `translations` map of every visible source string to its translation (headings, paragraph text, button labels, image alt text, captions, form labels). Do NOT rebuild the layout or call search_stock_photos for a translation. Requires an open page/post. Mutating: first returns a confirmation phrase; only creates the translation after exact confirmation.',
|
|
3844
|
-
execute: (t) =>
|
|
3845
|
-
inputSchema:
|
|
3886
|
+
execute: (t) => no(t, e),
|
|
3887
|
+
inputSchema: an,
|
|
3846
3888
|
strict: !0
|
|
3847
3889
|
}),
|
|
3848
|
-
set_content_images:
|
|
3890
|
+
set_content_images: v({
|
|
3849
3891
|
description: "Set the feature image for a page or post, or the image gallery for a product. Pass `images`: a list of image URLs (e.g. `mainImage` from fetch_url_content or `url` values from search_stock_photos) and/or existing media library IDs. External URLs are imported into the media library automatically — NEVER put an image URL directly into feature_image_id. The FIRST image becomes the feature image (pages/posts) or the main product image (products); for a product the remaining images become its gallery in order (this REPLACES the product's current images). Targets the currently open page/post/product by default; to target any other item (for example a product you just created from the dashboard) pass contentType plus slug, entityId, or title — no open editor needed. Mutating: first returns a confirmation phrase; only applies after exact confirmation.",
|
|
3850
|
-
execute: (t) =>
|
|
3851
|
-
inputSchema:
|
|
3892
|
+
execute: (t) => sn(t, e),
|
|
3893
|
+
inputSchema: be,
|
|
3852
3894
|
strict: !0
|
|
3853
3895
|
}),
|
|
3854
|
-
create_cms_page:
|
|
3896
|
+
create_cms_page: v({
|
|
3855
3897
|
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.",
|
|
3856
|
-
execute: (t) =>
|
|
3857
|
-
inputSchema:
|
|
3898
|
+
execute: (t) => We(t, e),
|
|
3899
|
+
inputSchema: ke,
|
|
3858
3900
|
strict: !0
|
|
3859
3901
|
}),
|
|
3860
|
-
create_cms_post:
|
|
3902
|
+
create_cms_post: v({
|
|
3861
3903
|
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.",
|
|
3862
|
-
execute: (t) =>
|
|
3863
|
-
inputSchema:
|
|
3904
|
+
execute: (t) => Ye(t, e),
|
|
3905
|
+
inputSchema: Ie,
|
|
3864
3906
|
strict: !0
|
|
3865
3907
|
}),
|
|
3866
|
-
create_cms_product:
|
|
3908
|
+
create_cms_product: v({
|
|
3867
3909
|
description: "Create a new draft-capable product, complete with its images and its body copy in ONE call. Pass `images` to set the main product image and gallery (external https URLs are imported into the media library automatically — use `mainImage` from fetch_url_content to reuse a source page's photo). Pass `blocks` to build the product's \"Product Description Blocks\" — the SAME block vocabulary and section-based design rules as create_cms_page, rendered on the public product page. This is the richest product body and is what you should produce whenever the user asks to copy or write real product content. Also pass `short_description` for the one-line summary shown on product cards. `description_html` is a plain-HTML fallback body used only when no blocks are supplied. Defaults missing fields safely: physical Stripe product, generated SKU, price 0, stock 0, taxable, draft. `price` is in major units (25 = $25.00). For translations, pass translationGroupId from the source product context. Mutating: first returns a confirmation phrase; only executes after exact confirmation.",
|
|
3868
|
-
execute: (t) =>
|
|
3869
|
-
inputSchema:
|
|
3910
|
+
execute: (t) => Vt(t, e),
|
|
3911
|
+
inputSchema: Te,
|
|
3870
3912
|
strict: !0
|
|
3871
3913
|
}),
|
|
3872
|
-
delete_cms_item:
|
|
3914
|
+
delete_cms_item: v({
|
|
3873
3915
|
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.",
|
|
3874
|
-
execute: (t) =>
|
|
3875
|
-
inputSchema:
|
|
3916
|
+
execute: (t) => Xt(t, e),
|
|
3917
|
+
inputSchema: Ce,
|
|
3876
3918
|
strict: !0
|
|
3877
3919
|
}),
|
|
3878
|
-
prepare_delete_cms_item:
|
|
3920
|
+
prepare_delete_cms_item: v({
|
|
3879
3921
|
description: "Inspect the page, post, or product that would be deleted and return the exact confirmation phrase. This tool does not mutate data.",
|
|
3880
|
-
execute: (t) =>
|
|
3881
|
-
inputSchema:
|
|
3922
|
+
execute: (t) => Fr(t, e),
|
|
3923
|
+
inputSchema: wt,
|
|
3882
3924
|
strict: !0
|
|
3883
3925
|
}),
|
|
3884
|
-
update_footer:
|
|
3926
|
+
update_footer: v({
|
|
3885
3927
|
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.",
|
|
3886
|
-
execute: (t) =>
|
|
3887
|
-
inputSchema:
|
|
3928
|
+
execute: (t) => Lt(t, e),
|
|
3929
|
+
inputSchema: fe,
|
|
3888
3930
|
strict: !0
|
|
3889
3931
|
}),
|
|
3890
|
-
update_content_block:
|
|
3932
|
+
update_content_block: v({
|
|
3891
3933
|
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.',
|
|
3892
|
-
execute: (t) =>
|
|
3893
|
-
inputSchema:
|
|
3934
|
+
execute: (t) => zt(t, e),
|
|
3935
|
+
inputSchema: ye,
|
|
3894
3936
|
strict: !0
|
|
3895
3937
|
}),
|
|
3896
|
-
insert_content_block:
|
|
3938
|
+
insert_content_block: v({
|
|
3897
3939
|
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.',
|
|
3898
|
-
execute: (t) =>
|
|
3899
|
-
inputSchema:
|
|
3940
|
+
execute: (t) => Gt(t, e),
|
|
3941
|
+
inputSchema: we,
|
|
3900
3942
|
strict: !0
|
|
3901
3943
|
}),
|
|
3902
|
-
update_current_cms_fields:
|
|
3944
|
+
update_current_cms_fields: v({
|
|
3903
3945
|
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.",
|
|
3904
|
-
execute: (t) =>
|
|
3905
|
-
inputSchema:
|
|
3946
|
+
execute: (t) => Dt(t, e),
|
|
3947
|
+
inputSchema: he,
|
|
3906
3948
|
strict: !0
|
|
3907
3949
|
}),
|
|
3908
|
-
update_cms_item_field:
|
|
3950
|
+
update_cms_item_field: v({
|
|
3909
3951
|
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.",
|
|
3910
|
-
execute: (t) =>
|
|
3911
|
-
inputSchema:
|
|
3952
|
+
execute: (t) => Jt(t, e),
|
|
3953
|
+
inputSchema: xe,
|
|
3912
3954
|
strict: !0
|
|
3913
3955
|
}),
|
|
3914
|
-
update_navigation_bar:
|
|
3956
|
+
update_navigation_bar: v({
|
|
3915
3957
|
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.',
|
|
3916
|
-
execute: (t) =>
|
|
3917
|
-
inputSchema:
|
|
3958
|
+
execute: (t) => jt(t, e),
|
|
3959
|
+
inputSchema: ge,
|
|
3918
3960
|
strict: !0
|
|
3919
3961
|
}),
|
|
3920
|
-
update_section_column_block:
|
|
3962
|
+
update_section_column_block: v({
|
|
3921
3963
|
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.",
|
|
3922
|
-
execute: (t) =>
|
|
3923
|
-
inputSchema:
|
|
3964
|
+
execute: (t) => Kt(t, e),
|
|
3965
|
+
inputSchema: _e,
|
|
3924
3966
|
strict: !0
|
|
3925
3967
|
}),
|
|
3926
|
-
execute_cms_action_plan:
|
|
3968
|
+
execute_cms_action_plan: v({
|
|
3927
3969
|
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.",
|
|
3928
|
-
execute: (t) =>
|
|
3929
|
-
inputSchema:
|
|
3970
|
+
execute: (t) => Br(t, e),
|
|
3971
|
+
inputSchema: It,
|
|
3930
3972
|
strict: !0
|
|
3931
3973
|
})
|
|
3932
3974
|
};
|
|
3933
3975
|
}
|
|
3934
3976
|
export {
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3977
|
+
V as availableCortexAiBlockTypes,
|
|
3978
|
+
lo as buildVisibleContactIntroActionPlan,
|
|
3979
|
+
_t as cortexAiPageContextSchema,
|
|
3980
|
+
ke as createCmsPageInputSchema,
|
|
3981
|
+
Ie as createCmsPostInputSchema,
|
|
3982
|
+
Te as createCmsProductInputSchema,
|
|
3983
|
+
po as createCortexGlobalAgentTools,
|
|
3984
|
+
Ce as deleteCmsItemInputSchema,
|
|
3985
|
+
Br as executeCmsActionPlan,
|
|
3986
|
+
It as executeCmsActionPlanInputSchema,
|
|
3987
|
+
We as executeCreateCmsPage,
|
|
3988
|
+
Ye as executeCreateCmsPost,
|
|
3989
|
+
Vt as executeCreateCmsProduct,
|
|
3990
|
+
Xt as executeDeleteCmsItem,
|
|
3991
|
+
Tr as executeFetchEcommerceStats,
|
|
3992
|
+
Hr as executeFetchUrlContent,
|
|
3993
|
+
Gt as executeInsertContentBlock,
|
|
3994
|
+
Fr as executePrepareDeleteCmsItem,
|
|
3995
|
+
xr as executeReadCurrentCmsItem,
|
|
3996
|
+
eo as executeRewritePageDraft,
|
|
3997
|
+
yr as executeSearchDocumentation,
|
|
3998
|
+
_r as executeSearchDocumentationWithTimeout,
|
|
3999
|
+
Yr as executeSearchStockPhotos,
|
|
4000
|
+
sn as executeSetContentImages,
|
|
4001
|
+
no as executeTranslatePage,
|
|
4002
|
+
Jt as executeUpdateCmsItemField,
|
|
4003
|
+
zt as executeUpdateContentBlock,
|
|
4004
|
+
Dt as executeUpdateCurrentCmsFields,
|
|
4005
|
+
Lt as executeUpdateFooter,
|
|
4006
|
+
jt as executeUpdateNavigationBar,
|
|
4007
|
+
Kt as executeUpdateSectionColumnBlock,
|
|
4008
|
+
yt as fetchEcommerceStatsInputSchema,
|
|
4009
|
+
Qt as fetchUrlContentInputSchema,
|
|
4010
|
+
we as insertContentBlockInputSchema,
|
|
4011
|
+
$e as maybeTriggerStockPhotoDownloads,
|
|
4012
|
+
ht as navigationItemInputSchema,
|
|
4013
|
+
wt as prepareDeleteCmsItemInputSchema,
|
|
4014
|
+
bt as readCurrentCmsItemInputSchema,
|
|
4015
|
+
uo as resolveCortexAiStockPhotoProvider,
|
|
4016
|
+
Qe as resolveCortexAiStockPhotoProviders,
|
|
4017
|
+
on as rewritePageDraftInputSchema,
|
|
4018
|
+
Be as searchDocumentationInputSchema,
|
|
4019
|
+
rn as searchStockPhotosInputSchema,
|
|
4020
|
+
be as setContentImagesInputSchema,
|
|
4021
|
+
an as translatePageInputSchema,
|
|
4022
|
+
xe as updateCmsItemFieldInputSchema,
|
|
4023
|
+
ye as updateContentBlockInputSchema,
|
|
4024
|
+
he as updateCurrentCmsFieldsInputSchema,
|
|
4025
|
+
fe as updateFooterInputSchema,
|
|
4026
|
+
ge as updateNavigationBarInputSchema,
|
|
4027
|
+
_e as updateSectionColumnBlockInputSchema
|
|
3986
4028
|
};
|