@nextblock-cms/cortex 0.22.0 → 0.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -46
- package/lib/ai-global-agent-db-tools.cjs +1 -1
- package/lib/ai-global-agent-db-tools.es.js +148 -122
- package/lib/ai-global-agent-tools.cjs +1 -1
- package/lib/ai-global-agent-tools.es.js +801 -800
- package/lib/fetch-host-guard.cjs +1 -1
- package/lib/fetch-host-guard.d.ts +13 -0
- package/lib/fetch-host-guard.es.js +15 -4
- package/lib/mcp-tokens.cjs +1 -1
- package/lib/mcp-tokens.d.ts +20 -9
- package/lib/mcp-tokens.es.js +1 -1
- package/package.json +4 -4
|
@@ -4,13 +4,13 @@ import { availableCortexAiBlockTypes as n, isValidBlockType as r, loadCustomBloc
|
|
|
4
4
|
import { createCortexDatabaseAgentTools as c } from "./ai-global-agent-db-tools.es.js";
|
|
5
5
|
import { createCortexThemingTools as l } from "./ai-global-agent-theming-tools.es.js";
|
|
6
6
|
import { createCortexSiteTools as u } from "./ai-global-agent-site-tools.es.js";
|
|
7
|
-
import { isBlockedFetchHost as d } from "./fetch-host-guard.es.js";
|
|
8
|
-
import { createCortexContentOpsTools as
|
|
9
|
-
import { editorDocumentFromHtml as
|
|
10
|
-
import { tool as
|
|
11
|
-
import { revalidatePath as
|
|
7
|
+
import { isBlockedFetchHost as d, resolvedHostIsBlocked as f } from "./fetch-host-guard.es.js";
|
|
8
|
+
import { createCortexContentOpsTools as p } from "./ai-global-agent-content-ops-tools.es.js";
|
|
9
|
+
import { editorDocumentFromHtml as m } from "./editor-document-from-html.es.js";
|
|
10
|
+
import { tool as h } from "ai";
|
|
11
|
+
import { revalidatePath as g } from "next/cache";
|
|
12
12
|
//#region src/lib/ai-global-agent-tools.ts
|
|
13
|
-
async function
|
|
13
|
+
async function _(e, t, n) {
|
|
14
14
|
if (e?.recordRevision) try {
|
|
15
15
|
return await e.recordRevision({
|
|
16
16
|
contentType: t,
|
|
@@ -22,7 +22,7 @@ async function g(e, t, n) {
|
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
async function
|
|
25
|
+
async function v(e, t, n, r) {
|
|
26
26
|
if (e?.recordRevision && r !== void 0) try {
|
|
27
27
|
await e.recordRevision({
|
|
28
28
|
baseline: r,
|
|
@@ -34,7 +34,7 @@ async function _(e, t, n, r) {
|
|
|
34
34
|
console.error("Cortex AI: failed to record revision", e);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
var
|
|
37
|
+
var y = 1e4, b = {
|
|
38
38
|
arabic: "ar",
|
|
39
39
|
chinese: "zh",
|
|
40
40
|
dutch: "nl",
|
|
@@ -49,30 +49,30 @@ var v = 1e4, y = {
|
|
|
49
49
|
portuguese: "pt",
|
|
50
50
|
russian: "ru",
|
|
51
51
|
spanish: "es"
|
|
52
|
-
},
|
|
52
|
+
}, x = e.string().trim().min(1).max(2048).refine((e) => e.startsWith("/") || e.startsWith("#") || e.startsWith("http://") || e.startsWith("https://") || e.startsWith("mailto:") || e.startsWith("tel:"), "URL must be a relative path, hash link, http(s) URL, mailto URL, or tel URL."), S = e.strictObject({
|
|
53
53
|
label: e.string().trim().min(1).max(120),
|
|
54
54
|
target: e.enum(["_self", "_blank"]).optional(),
|
|
55
|
-
url:
|
|
56
|
-
}),
|
|
55
|
+
url: x
|
|
56
|
+
}), C = S.extend({ children: e.array(S).max(20).optional() }), ee = e.strictObject({
|
|
57
57
|
label: e.string().trim().min(1).max(120).optional(),
|
|
58
|
-
url:
|
|
58
|
+
url: x.optional()
|
|
59
59
|
}).refine((e) => !!(e.label || e.url), { message: "Navigation item match requires label or url." }), w = e.strictObject({
|
|
60
|
-
items: e.array(
|
|
60
|
+
items: e.array(C).min(1).max(30),
|
|
61
61
|
languageCode: e.string().trim().min(2).max(80).default("en").describe("Locale code or language name, for example \"en\", \"fr\", \"English\", or \"French\"."),
|
|
62
|
-
match:
|
|
62
|
+
match: ee.optional().describe("For mode \"update\", identifies the existing navigation item to update."),
|
|
63
63
|
mode: e.enum([
|
|
64
64
|
"append",
|
|
65
65
|
"replace",
|
|
66
66
|
"update"
|
|
67
67
|
]).default("append")
|
|
68
|
-
}),
|
|
68
|
+
}), te = e.strictObject({
|
|
69
69
|
copyright: e.record(e.string().trim().min(2).max(12), e.string().trim().min(1).max(500)).optional(),
|
|
70
70
|
languageCode: e.string().trim().min(2).max(80).default("en").describe("Locale code or language name, for example \"en\", \"fr\", \"English\", or \"French\"."),
|
|
71
|
-
links: e.array(
|
|
72
|
-
}),
|
|
71
|
+
links: e.array(C).min(1).max(30).optional()
|
|
72
|
+
}), ne = e.strictObject({
|
|
73
73
|
limit: e.number().int().min(1).max(8).default(4),
|
|
74
74
|
query: e.string().trim().min(2).max(300)
|
|
75
|
-
}),
|
|
75
|
+
}), re = e.object({
|
|
76
76
|
currency: e.string().trim().min(3).max(3).optional().describe("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."),
|
|
77
77
|
query: e.string().describe("The analytical question about orders, products, or revenue."),
|
|
78
78
|
reportType: e.enum([
|
|
@@ -90,7 +90,7 @@ var v = 1e4, y = {
|
|
|
90
90
|
"last_90_days",
|
|
91
91
|
"all_time"
|
|
92
92
|
]).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.")
|
|
93
|
-
}),
|
|
93
|
+
}), ie = e.strictObject({
|
|
94
94
|
contentType: e.enum([
|
|
95
95
|
"page",
|
|
96
96
|
"post",
|
|
@@ -106,21 +106,21 @@ var v = 1e4, y = {
|
|
|
106
106
|
slug: e.string().trim().min(1).max(300).nullable().optional(),
|
|
107
107
|
title: e.string().trim().min(1).max(300).nullable().optional(),
|
|
108
108
|
translationGroupId: e.string().trim().min(1).max(120).nullable().optional()
|
|
109
|
-
}),
|
|
109
|
+
}), ae = e.enum([
|
|
110
110
|
"page",
|
|
111
111
|
"post",
|
|
112
112
|
"product"
|
|
113
113
|
]), T = e.strictObject({
|
|
114
|
-
contentType:
|
|
114
|
+
contentType: ae.optional(),
|
|
115
115
|
entityId: e.union([e.number().int().positive(), e.string().trim().min(1).max(120)]).optional(),
|
|
116
116
|
slug: e.string().trim().min(1).max(300).optional(),
|
|
117
117
|
title: e.string().trim().min(1).max(300).optional()
|
|
118
|
-
}),
|
|
119
|
-
cmsTarget:
|
|
118
|
+
}), E = T.optional().describe("Names the page, post, or product to act on when no CMS editor is open (MCP clients). Pass contentType plus one of slug, entityId, or title. Ignored when an editor is already open."), oe = e.strictObject({
|
|
119
|
+
cmsTarget: E,
|
|
120
120
|
includeBlockContent: e.boolean().default(!1),
|
|
121
121
|
includeBlocks: e.boolean().default(!0)
|
|
122
|
-
}), se = "The feature image: an existing media library id OR an external https:// image URL, which is downloaded into the media library automatically (pass `mainImage` from fetch_url_content or a `url` from search_stock_photos straight in). WHAT IT DOES: on a page it renders as a full-width title banner ABOVE the page's blocks (the image as a dimmed cover background, about 200-300px tall, with the page title centred over it in white); on a post it is the article's hero image above the header. It is also the social/OG preview image and the card thumbnail in post listings. RULES: give every post one. Give a page one only when a title banner above its content is wanted; NEVER set one on the home page or on any page that opens with its own hero section (the banner would stack above the hero and repeat the title) — set the site-wide social preview with update_site_identity `social_image` instead. Pick a very wide landscape image (about 3:1, at least 1600px wide): the banner crops it to a short full-width band.",
|
|
123
|
-
cmsTarget:
|
|
122
|
+
}), se = "The feature image: an existing media library id OR an external https:// image URL, which is downloaded into the media library automatically (pass `mainImage` from fetch_url_content or a `url` from search_stock_photos straight in). WHAT IT DOES: on a page it renders as a full-width title banner ABOVE the page's blocks (the image as a dimmed cover background, about 200-300px tall, with the page title centred over it in white); on a post it is the article's hero image above the header. It is also the social/OG preview image and the card thumbnail in post listings. RULES: give every post one. Give a page one only when a title banner above its content is wanted; NEVER set one on the home page or on any page that opens with its own hero section (the banner would stack above the hero and repeat the title) — set the site-wide social preview with update_site_identity `social_image` instead. Pick a very wide landscape image (about 3:1, at least 1600px wide): the banner crops it to a short full-width band.", D = e.strictObject({
|
|
123
|
+
cmsTarget: E,
|
|
124
124
|
fields: e.strictObject({
|
|
125
125
|
description_json: e.unknown().optional(),
|
|
126
126
|
excerpt: e.string().max(2e3).nullable().optional(),
|
|
@@ -140,34 +140,34 @@ var v = 1e4, y = {
|
|
|
140
140
|
subtitle: e.string().max(300).nullable().optional(),
|
|
141
141
|
title: e.string().trim().min(1).max(300).optional()
|
|
142
142
|
}).partial()
|
|
143
|
-
}),
|
|
143
|
+
}), ce = e.string().trim().min(1).max(120).describe(`A built-in block type (${n.join(", ")}) or the slug of a custom block definition from list_custom_blocks, whose content is the flat { field_key: value } map its fields describe.`), O = e.strictObject({
|
|
144
144
|
blockId: e.number().int().positive(),
|
|
145
|
-
blockType:
|
|
146
|
-
cmsTarget:
|
|
145
|
+
blockType: ce.optional(),
|
|
146
|
+
cmsTarget: E,
|
|
147
147
|
content: e.record(e.string(), e.unknown())
|
|
148
|
-
}),
|
|
148
|
+
}), k = e.strictObject({
|
|
149
149
|
blockIndex: e.number().int().min(0),
|
|
150
|
-
blockType:
|
|
151
|
-
cmsTarget:
|
|
150
|
+
blockType: ce.optional(),
|
|
151
|
+
cmsTarget: E,
|
|
152
152
|
columnIndex: e.number().int().min(0),
|
|
153
153
|
content: e.record(e.string(), e.unknown()),
|
|
154
154
|
parentBlockId: e.number().int().positive()
|
|
155
|
-
}),
|
|
156
|
-
blockType:
|
|
155
|
+
}), le = e.strictObject({
|
|
156
|
+
blockType: ce,
|
|
157
157
|
content: e.record(e.string(), e.unknown()).describe("The block content, matching that block type's schema. For a `text` block, `html_content` is rendered as real HTML and may include an inline <style> and an inline <script> — so you can add scroll reveals, counters, hover effects, and other motion directly in a block. Inline scripts are stamped with the site CSP nonce automatically. Three rules. (1) THE PAGE IS REACT-HYDRATED. Do not change the text, classes, or attributes of surrounding server-rendered markup: React reconciles afterwards and reverts your change (a counter animates then snaps back) or logs a hydration mismatch. Waiting for `load` is NOT sufficient — hydration can still be in flight. Safe patterns instead: animate with the Web Animations API (el.animate() touches no attribute); append your own new elements and style those; use CSS for anything CSS can do; and if you must set text, render the FINAL value server-side and only animate toward it once the element scrolls into view. (2) `on*` attributes (onclick, onload, …) are stripped, so bind with addEventListener. (3) The script runs once per full page load, not on client-side navigation — for site-wide behaviour use manage_site_script. For a `section` block: `is_hero: true` marks the page hero (the editor checkbox \"Hero Section (Prioritized image loading)\": its background image loads with priority and its content is vertically centred); `slider: true` with a `slides` array ([{ background, column_blocks }, …], the editor checkbox \"Enable Slider (Carousel layout)\") renders a carousel of full sections: only the slides are drawn, but the grid track count still comes from the top-level `column_blocks`, so send one top-level column per column you want inside each slide (empty columns are fine) and give every slide that same number of columns. Add `autoplay: true` and `timeframe` in seconds (default 5) to rotate it."),
|
|
158
158
|
order: e.number().int().min(0).optional()
|
|
159
|
-
}),
|
|
159
|
+
}), ue = T.extend({ images: e.array(e.string().trim().min(1).max(2048)).min(1).max(12).describe("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).") }), de = T.extend({
|
|
160
160
|
anchorBlockId: e.number().int().positive().optional(),
|
|
161
|
-
anchorBlockType:
|
|
162
|
-
block:
|
|
161
|
+
anchorBlockType: ce.optional(),
|
|
162
|
+
block: le,
|
|
163
163
|
position: e.enum([
|
|
164
164
|
"before",
|
|
165
165
|
"after",
|
|
166
166
|
"start",
|
|
167
167
|
"end"
|
|
168
168
|
]).default("end")
|
|
169
|
-
}),
|
|
170
|
-
blocks: e.array(
|
|
169
|
+
}), fe = e.strictObject({
|
|
170
|
+
blocks: e.array(le).max(20).optional(),
|
|
171
171
|
contactEmail: e.string().email().optional(),
|
|
172
172
|
feature_image_id: e.string().trim().min(1).max(2048).nullable().optional().describe(se),
|
|
173
173
|
languageCode: e.string().trim().min(2).max(80).optional(),
|
|
@@ -181,8 +181,8 @@ var v = 1e4, y = {
|
|
|
181
181
|
]).default("draft"),
|
|
182
182
|
title: e.string().trim().min(1).max(300),
|
|
183
183
|
translationGroupId: e.string().trim().min(1).max(120).optional()
|
|
184
|
-
}),
|
|
185
|
-
blocks: e.array(
|
|
184
|
+
}), pe = e.strictObject({
|
|
185
|
+
blocks: e.array(le).max(20).optional(),
|
|
186
186
|
excerpt: e.string().max(2e3).nullable().optional(),
|
|
187
187
|
feature_image_id: e.string().trim().min(1).max(2048).nullable().optional().describe(se),
|
|
188
188
|
label: e.string().max(120).nullable().optional(),
|
|
@@ -199,8 +199,8 @@ var v = 1e4, y = {
|
|
|
199
199
|
subtitle: e.string().max(300).nullable().optional(),
|
|
200
200
|
title: e.string().trim().min(1).max(300),
|
|
201
201
|
translationGroupId: e.string().trim().min(1).max(120).optional()
|
|
202
|
-
}),
|
|
203
|
-
blocks: e.array(
|
|
202
|
+
}), me = e.strictObject({
|
|
203
|
+
blocks: e.array(le).max(20).optional().describe("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."),
|
|
204
204
|
description_html: e.string().max(6e4).optional().describe("The product body as an HTML fragment (headings, paragraphs, lists, bold/italic/links). Converted to the editor document automatically. Prefer this over description_json."),
|
|
205
205
|
description_json: e.unknown().optional(),
|
|
206
206
|
freemius_plan_id: e.string().optional(),
|
|
@@ -230,47 +230,47 @@ var v = 1e4, y = {
|
|
|
230
230
|
trial_requires_payment_method: e.boolean().default(!1),
|
|
231
231
|
translationGroupId: e.string().trim().min(1).max(120).optional(),
|
|
232
232
|
upc: e.string().max(120).nullable().optional()
|
|
233
|
-
}),
|
|
233
|
+
}), he = T.extend({
|
|
234
234
|
currencyCode: e.string().trim().min(3).max(3).optional(),
|
|
235
235
|
endsAt: e.string().max(80).nullable().optional(),
|
|
236
236
|
field: e.string().trim().min(1).max(120),
|
|
237
237
|
startsAt: e.string().max(80).nullable().optional(),
|
|
238
238
|
value: e.unknown()
|
|
239
|
-
}),
|
|
239
|
+
}), ge = T, A = T, _e = e.discriminatedUnion("tool", [
|
|
240
240
|
e.strictObject({
|
|
241
|
-
input:
|
|
241
|
+
input: fe,
|
|
242
242
|
tool: e.literal("create_cms_page")
|
|
243
243
|
}),
|
|
244
244
|
e.strictObject({
|
|
245
|
-
input:
|
|
245
|
+
input: pe,
|
|
246
246
|
tool: e.literal("create_cms_post")
|
|
247
247
|
}),
|
|
248
248
|
e.strictObject({
|
|
249
|
-
input:
|
|
249
|
+
input: me,
|
|
250
250
|
tool: e.literal("create_cms_product")
|
|
251
251
|
}),
|
|
252
252
|
e.strictObject({
|
|
253
|
-
input:
|
|
253
|
+
input: A,
|
|
254
254
|
tool: e.literal("delete_cms_item")
|
|
255
255
|
}),
|
|
256
256
|
e.strictObject({
|
|
257
|
-
input:
|
|
257
|
+
input: he,
|
|
258
258
|
tool: e.literal("update_cms_item_field")
|
|
259
259
|
}),
|
|
260
260
|
e.strictObject({
|
|
261
|
-
input:
|
|
261
|
+
input: O,
|
|
262
262
|
tool: e.literal("update_content_block")
|
|
263
263
|
}),
|
|
264
264
|
e.strictObject({
|
|
265
|
-
input:
|
|
265
|
+
input: de,
|
|
266
266
|
tool: e.literal("insert_content_block")
|
|
267
267
|
}),
|
|
268
268
|
e.strictObject({
|
|
269
|
-
input:
|
|
269
|
+
input: D,
|
|
270
270
|
tool: e.literal("update_current_cms_fields")
|
|
271
271
|
}),
|
|
272
272
|
e.strictObject({
|
|
273
|
-
input:
|
|
273
|
+
input: te,
|
|
274
274
|
tool: e.literal("update_footer")
|
|
275
275
|
}),
|
|
276
276
|
e.strictObject({
|
|
@@ -278,47 +278,47 @@ var v = 1e4, y = {
|
|
|
278
278
|
tool: e.literal("update_navigation_bar")
|
|
279
279
|
}),
|
|
280
280
|
e.strictObject({
|
|
281
|
-
input:
|
|
281
|
+
input: k,
|
|
282
282
|
tool: e.literal("update_section_column_block")
|
|
283
283
|
}),
|
|
284
284
|
e.strictObject({
|
|
285
|
-
input:
|
|
285
|
+
input: ue,
|
|
286
286
|
tool: e.literal("set_content_images")
|
|
287
287
|
})
|
|
288
|
-
]),
|
|
289
|
-
|
|
288
|
+
]), ve = e.union([
|
|
289
|
+
fe.extend({ tool: e.literal("create_cms_page") }).transform(({ tool: e, ...t }) => ({
|
|
290
290
|
input: t,
|
|
291
291
|
tool: e
|
|
292
292
|
})),
|
|
293
|
-
|
|
293
|
+
pe.extend({ tool: e.literal("create_cms_post") }).transform(({ tool: e, ...t }) => ({
|
|
294
294
|
input: t,
|
|
295
295
|
tool: e
|
|
296
296
|
})),
|
|
297
|
-
|
|
297
|
+
me.extend({ tool: e.literal("create_cms_product") }).transform(({ tool: e, ...t }) => ({
|
|
298
298
|
input: t,
|
|
299
299
|
tool: e
|
|
300
300
|
})),
|
|
301
|
-
|
|
301
|
+
A.extend({ tool: e.literal("delete_cms_item") }).transform(({ tool: e, ...t }) => ({
|
|
302
302
|
input: t,
|
|
303
303
|
tool: e
|
|
304
304
|
})),
|
|
305
|
-
|
|
305
|
+
he.extend({ tool: e.literal("update_cms_item_field") }).transform(({ tool: e, ...t }) => ({
|
|
306
306
|
input: t,
|
|
307
307
|
tool: e
|
|
308
308
|
})),
|
|
309
|
-
|
|
309
|
+
O.extend({ tool: e.literal("update_content_block") }).transform(({ tool: e, ...t }) => ({
|
|
310
310
|
input: t,
|
|
311
311
|
tool: e
|
|
312
312
|
})),
|
|
313
|
-
|
|
313
|
+
de.extend({ tool: e.literal("insert_content_block") }).transform(({ tool: e, ...t }) => ({
|
|
314
314
|
input: t,
|
|
315
315
|
tool: e
|
|
316
316
|
})),
|
|
317
|
-
|
|
317
|
+
D.extend({ tool: e.literal("update_current_cms_fields") }).transform(({ tool: e, ...t }) => ({
|
|
318
318
|
input: t,
|
|
319
319
|
tool: e
|
|
320
320
|
})),
|
|
321
|
-
|
|
321
|
+
te.extend({ tool: e.literal("update_footer") }).transform(({ tool: e, ...t }) => ({
|
|
322
322
|
input: t,
|
|
323
323
|
tool: e
|
|
324
324
|
})),
|
|
@@ -326,29 +326,29 @@ var v = 1e4, y = {
|
|
|
326
326
|
input: t,
|
|
327
327
|
tool: e
|
|
328
328
|
})),
|
|
329
|
-
|
|
329
|
+
k.extend({ tool: e.literal("update_section_column_block") }).transform(({ tool: e, ...t }) => ({
|
|
330
330
|
input: t,
|
|
331
331
|
tool: e
|
|
332
332
|
})),
|
|
333
|
-
|
|
333
|
+
ue.extend({ tool: e.literal("set_content_images") }).transform(({ tool: e, ...t }) => ({
|
|
334
334
|
input: t,
|
|
335
335
|
tool: e
|
|
336
336
|
}))
|
|
337
|
-
]),
|
|
338
|
-
let r =
|
|
337
|
+
]), ye = e.string().transform((t, n) => {
|
|
338
|
+
let r = Ee(t);
|
|
339
339
|
return r.success ? r.action : (n.addIssue({
|
|
340
340
|
code: "custom",
|
|
341
341
|
message: r.message
|
|
342
342
|
}), e.NEVER);
|
|
343
|
-
}),
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
]),
|
|
348
|
-
actions: e.array(
|
|
343
|
+
}), be = e.union([
|
|
344
|
+
_e,
|
|
345
|
+
ve,
|
|
346
|
+
ye
|
|
347
|
+
]), xe = e.strictObject({
|
|
348
|
+
actions: e.array(be).min(1).max(8),
|
|
349
349
|
summary: e.string().trim().min(1).max(500).optional()
|
|
350
350
|
});
|
|
351
|
-
function
|
|
351
|
+
function Se(e) {
|
|
352
352
|
let t = [], n = "", r = 0, i = null, a = !1;
|
|
353
353
|
for (let o of e) {
|
|
354
354
|
if (i) {
|
|
@@ -375,7 +375,7 @@ function ye(e) {
|
|
|
375
375
|
}
|
|
376
376
|
return n.trim() && t.push(n.trim()), t;
|
|
377
377
|
}
|
|
378
|
-
function
|
|
378
|
+
function Ce(e) {
|
|
379
379
|
let t = "";
|
|
380
380
|
for (let n = 0; n < e.length; n++) {
|
|
381
381
|
let r = e[n];
|
|
@@ -401,22 +401,22 @@ function be(e) {
|
|
|
401
401
|
}
|
|
402
402
|
return t.replace(/\bTrue\b/g, "true").replace(/\bFalse\b/g, "false").replace(/\bNone\b/g, "null");
|
|
403
403
|
}
|
|
404
|
-
function
|
|
404
|
+
function we(e) {
|
|
405
405
|
let t = e.trim();
|
|
406
|
-
return t.startsWith("'") && t.endsWith("'") || t.startsWith("\"") && t.endsWith("\"") || t.startsWith("[") || t.startsWith("{") ? JSON.parse(
|
|
406
|
+
return t.startsWith("'") && t.endsWith("'") || t.startsWith("\"") && t.endsWith("\"") || t.startsWith("[") || t.startsWith("{") ? JSON.parse(Ce(t)) : /^-?\d+(?:\.\d+)?$/.test(t) ? Number(t) : t === "true" || t === "True" ? !0 : t === "false" || t === "False" ? !1 : t === "null" || t === "None" ? null : t;
|
|
407
407
|
}
|
|
408
|
-
function
|
|
408
|
+
function Te(e) {
|
|
409
409
|
let t = {};
|
|
410
|
-
for (let n of
|
|
410
|
+
for (let n of Se(e)) {
|
|
411
411
|
let e = n.indexOf("=");
|
|
412
412
|
if (e <= 0) throw Error(`Expected key=value argument, received "${n}".`);
|
|
413
413
|
let r = n.slice(0, e).trim();
|
|
414
414
|
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(r)) throw Error(`Invalid argument name "${r}".`);
|
|
415
|
-
t[r] =
|
|
415
|
+
t[r] = we(n.slice(e + 1));
|
|
416
416
|
}
|
|
417
417
|
return t;
|
|
418
418
|
}
|
|
419
|
-
function
|
|
419
|
+
function Ee(e) {
|
|
420
420
|
let t = e.trim().match(/^([a-z_]+)\(([\s\S]*)\)$/);
|
|
421
421
|
if (!t) return {
|
|
422
422
|
message: "Action plan actions must be JSON objects like { \"tool\": \"create_cms_page\", \"input\": { ... } }, not freeform text.",
|
|
@@ -424,7 +424,7 @@ function Ce(e) {
|
|
|
424
424
|
};
|
|
425
425
|
let n = t[1], r;
|
|
426
426
|
try {
|
|
427
|
-
r =
|
|
427
|
+
r = Te(t[2]);
|
|
428
428
|
} catch (e) {
|
|
429
429
|
return {
|
|
430
430
|
message: e instanceof Error ? e.message : "Could not parse action-plan command arguments.",
|
|
@@ -434,7 +434,7 @@ function Ce(e) {
|
|
|
434
434
|
let i = {
|
|
435
435
|
input: r,
|
|
436
436
|
tool: n
|
|
437
|
-
}, a =
|
|
437
|
+
}, a = _e.safeParse(i);
|
|
438
438
|
return a.success ? {
|
|
439
439
|
action: a.data,
|
|
440
440
|
success: !0
|
|
@@ -443,26 +443,26 @@ function Ce(e) {
|
|
|
443
443
|
success: !1
|
|
444
444
|
};
|
|
445
445
|
}
|
|
446
|
-
function
|
|
446
|
+
function De(e) {
|
|
447
447
|
return e.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/\s+/g, " ").trim();
|
|
448
448
|
}
|
|
449
|
-
function
|
|
449
|
+
function Oe(e, t) {
|
|
450
450
|
return t.some((t) => e.includes(t));
|
|
451
451
|
}
|
|
452
|
-
function
|
|
453
|
-
let t =
|
|
452
|
+
function ke(e) {
|
|
453
|
+
let t = De(e), n = Oe(t, [
|
|
454
454
|
"add ",
|
|
455
455
|
"insert ",
|
|
456
456
|
"put ",
|
|
457
457
|
"create "
|
|
458
|
-
]), r =
|
|
458
|
+
]), r = Oe(t, [
|
|
459
459
|
"title",
|
|
460
460
|
"heading",
|
|
461
461
|
"description",
|
|
462
462
|
"intro",
|
|
463
463
|
"copy",
|
|
464
464
|
"paragraph"
|
|
465
|
-
]), i = t.includes("form") &&
|
|
465
|
+
]), i = t.includes("form") && Oe(t, ["above", "before"]), a = t.includes("contact page") || t.includes("contact pages") || t.includes("contact us") || t.includes("contactez-nous"), o = t.includes("english") && Oe(t, [
|
|
466
466
|
"french",
|
|
467
467
|
"francais",
|
|
468
468
|
"francaise"
|
|
@@ -496,20 +496,20 @@ function Ee(e) {
|
|
|
496
496
|
summary: "Add visible title and description copy above the forms on the English and French Contact pages."
|
|
497
497
|
};
|
|
498
498
|
}
|
|
499
|
-
function
|
|
499
|
+
function Ae() {
|
|
500
500
|
return e.object({
|
|
501
501
|
content: e.array(e.any()).optional(),
|
|
502
502
|
type: e.literal("doc")
|
|
503
503
|
});
|
|
504
504
|
}
|
|
505
|
-
function
|
|
506
|
-
return
|
|
505
|
+
function je() {
|
|
506
|
+
return g;
|
|
507
507
|
}
|
|
508
|
-
function
|
|
508
|
+
function j(e) {
|
|
509
509
|
if (!e?.supabase) throw Error("A Supabase service client is required to execute Cortex AI global tools.");
|
|
510
510
|
return e.supabase;
|
|
511
511
|
}
|
|
512
|
-
function
|
|
512
|
+
function Me(e, t, n) {
|
|
513
513
|
let r, i = new Promise((e) => {
|
|
514
514
|
r = setTimeout(() => e(n()), t);
|
|
515
515
|
});
|
|
@@ -517,31 +517,31 @@ function ke(e, t, n) {
|
|
|
517
517
|
r && clearTimeout(r);
|
|
518
518
|
}), i]);
|
|
519
519
|
}
|
|
520
|
-
function
|
|
521
|
-
let t =
|
|
520
|
+
function Ne(e) {
|
|
521
|
+
let t = ie.safeParse(e?.pageContext);
|
|
522
522
|
if (!t.success) throw Error("No current CMS page context is available. Open a page, post, or product edit screen before using this editing tool.");
|
|
523
523
|
return t.data;
|
|
524
524
|
}
|
|
525
|
-
function
|
|
525
|
+
function Pe(e) {
|
|
526
526
|
let t = typeof e.entityId == "number" ? e.entityId : Number.parseInt(e.entityId, 10);
|
|
527
527
|
if (!Number.isInteger(t) || t <= 0) throw Error(`Current ${e.contentType} id must be a positive integer.`);
|
|
528
528
|
return t;
|
|
529
529
|
}
|
|
530
|
-
function
|
|
530
|
+
function Fe(e) {
|
|
531
531
|
let t = String(e.entityId || "").trim();
|
|
532
532
|
if (!t) throw Error(`Current ${e.contentType} id is missing.`);
|
|
533
533
|
return t;
|
|
534
534
|
}
|
|
535
|
-
function
|
|
536
|
-
return e.contentType === "product" ?
|
|
535
|
+
function M(e) {
|
|
536
|
+
return e.contentType === "product" ? Fe(e) : Pe(e);
|
|
537
537
|
}
|
|
538
|
-
var
|
|
539
|
-
async function
|
|
538
|
+
var Ie = /^https?:\/\//i, Le = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
539
|
+
async function N(e, t, n) {
|
|
540
540
|
if (typeof e != "string") return null;
|
|
541
541
|
let r = e.trim();
|
|
542
542
|
if (!r) return null;
|
|
543
|
-
if (!
|
|
544
|
-
if (
|
|
543
|
+
if (!Ie.test(r)) {
|
|
544
|
+
if (Le.test(r)) return r;
|
|
545
545
|
throw Error(`"${r}" is not a usable image reference — provide an https:// image URL or a media library id.`);
|
|
546
546
|
}
|
|
547
547
|
let i = t?.importExternalImage;
|
|
@@ -553,139 +553,139 @@ async function F(e, t, n) {
|
|
|
553
553
|
if ("error" in a) throw Error(`I could not import the image from that URL: ${a.error}`);
|
|
554
554
|
return a.id;
|
|
555
555
|
}
|
|
556
|
-
async function
|
|
556
|
+
async function Re(e, t, n) {
|
|
557
557
|
let r = [];
|
|
558
558
|
for (let i = 0; i < e.length; i += 1) {
|
|
559
|
-
let a = await
|
|
559
|
+
let a = await N(e[i], t, `${n} image ${i + 1}`);
|
|
560
560
|
a && r.push(a);
|
|
561
561
|
}
|
|
562
562
|
return r;
|
|
563
563
|
}
|
|
564
|
-
async function
|
|
564
|
+
async function ze(e) {
|
|
565
565
|
let t = [...new Set(e.mediaIds)], { error: n } = await e.supabase.from("product_media").delete().eq("product_id", e.productId);
|
|
566
|
-
if (n) throw Error(`Could not clear the product's existing images: ${
|
|
566
|
+
if (n) throw Error(`Could not clear the product's existing images: ${F(n)}`);
|
|
567
567
|
if (t.length > 0) {
|
|
568
568
|
let { error: n } = await e.supabase.from("product_media").insert(t.map((t, n) => ({
|
|
569
569
|
media_id: t,
|
|
570
570
|
product_id: e.productId,
|
|
571
571
|
sort_order: n
|
|
572
572
|
})));
|
|
573
|
-
if (n) throw Error(`Could not save the product images: ${
|
|
573
|
+
if (n) throw Error(`Could not save the product images: ${F(n)}`);
|
|
574
574
|
}
|
|
575
575
|
return t;
|
|
576
576
|
}
|
|
577
|
-
async function
|
|
577
|
+
async function Be(e) {
|
|
578
578
|
if (!e.productId) return !1;
|
|
579
579
|
let { data: t, error: n } = await e.supabase.from("product_drafts").select("id, blocks, meta").eq("product_id", e.productId).maybeSingle();
|
|
580
580
|
if (n || !t) return !1;
|
|
581
581
|
let r = e.patch({
|
|
582
|
-
blocks: Array.isArray(t.blocks) ?
|
|
583
|
-
meta:
|
|
582
|
+
blocks: Array.isArray(t.blocks) ? H(t.blocks) : [],
|
|
583
|
+
meta: U(t.meta) ? H(t.meta) : {}
|
|
584
584
|
}), i = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
585
585
|
if (r.blocks && (i.blocks = r.blocks), r.meta && (i.meta = r.meta), Object.keys(i).length === 1) return !1;
|
|
586
586
|
let { error: a } = await e.supabase.from("product_drafts").update(i).eq("id", t.id);
|
|
587
|
-
if (a) throw Error(`The product was updated, but its open draft could not be kept in sync: ${
|
|
587
|
+
if (a) throw Error(`The product was updated, but its open draft could not be kept in sync: ${F(a)}. Publishing that draft would undo this change — publish or discard it in the product editor first.`);
|
|
588
588
|
return !0;
|
|
589
589
|
}
|
|
590
|
-
function
|
|
590
|
+
function Ve(e) {
|
|
591
591
|
return typeof e == "string" ? e.trim().replace(/^\/+|\/+$/g, "") : "";
|
|
592
592
|
}
|
|
593
|
-
function
|
|
594
|
-
let n =
|
|
593
|
+
function He(e, t) {
|
|
594
|
+
let n = Ve(t ?? e.slug);
|
|
595
595
|
return n ? e.contentType === "page" ? n === "home" ? "/" : `/${n}` : e.contentType === "post" ? `/article/${n}` : `/product/${n}` : null;
|
|
596
596
|
}
|
|
597
|
-
function
|
|
597
|
+
function Ue(e) {
|
|
598
598
|
let t = String(e.entityId);
|
|
599
599
|
return e.contentType === "page" ? `/cms/pages/${t}/edit` : e.contentType === "post" ? `/cms/posts/${t}/edit` : `/cms/products/${t}/edit`;
|
|
600
600
|
}
|
|
601
|
-
function
|
|
602
|
-
let r = e?.revalidatePath ??
|
|
601
|
+
function P(e, t, n) {
|
|
602
|
+
let r = e?.revalidatePath ?? je();
|
|
603
603
|
if (!r) return;
|
|
604
|
-
r(
|
|
605
|
-
let i =
|
|
604
|
+
r(Ue(t));
|
|
605
|
+
let i = He(t, n);
|
|
606
606
|
i && r(i), t.contentType === "page" && i !== "/" && r("/"), t.contentType === "product" && r("/cms/products");
|
|
607
607
|
}
|
|
608
|
-
function
|
|
609
|
-
let t = e?.revalidatePath ??
|
|
608
|
+
function We(e) {
|
|
609
|
+
let t = e?.revalidatePath ?? je();
|
|
610
610
|
t && (t("/", "layout"), t("/cms/navigation"));
|
|
611
611
|
}
|
|
612
|
-
function
|
|
612
|
+
function F(e) {
|
|
613
613
|
return e ? typeof e == "object" && "message" in e ? String(e.message || "Unknown database error.") : String(e) : "Unknown database error.";
|
|
614
614
|
}
|
|
615
|
-
async function
|
|
615
|
+
async function Ge() {
|
|
616
616
|
return import("./ai-global-agent-ecommerce.es.js");
|
|
617
617
|
}
|
|
618
|
-
function
|
|
619
|
-
return typeof e != "object" || !e ? JSON.stringify(e) : Array.isArray(e) ? `[${e.map((e) =>
|
|
618
|
+
function Ke(e) {
|
|
619
|
+
return typeof e != "object" || !e ? JSON.stringify(e) : Array.isArray(e) ? `[${e.map((e) => Ke(e)).join(",")}]` : `{${Object.keys(e).filter((e) => e !== "temp_id").sort().map((t) => `${JSON.stringify(t)}:${Ke(e[t])}`).join(",")}}`;
|
|
620
620
|
}
|
|
621
|
-
function
|
|
622
|
-
let t = 2166136261, n =
|
|
621
|
+
function qe(e) {
|
|
622
|
+
let t = 2166136261, n = Ke(e);
|
|
623
623
|
for (let e = 0; e < n.length; e++) t ^= n.charCodeAt(e), t = Math.imul(t, 16777619);
|
|
624
624
|
return (t >>> 0).toString(16).padStart(8, "0");
|
|
625
625
|
}
|
|
626
|
-
function
|
|
626
|
+
function Je(e) {
|
|
627
627
|
return e.replace(/\s+/g, " ").trim().toUpperCase();
|
|
628
628
|
}
|
|
629
|
-
function
|
|
630
|
-
return `${
|
|
629
|
+
function Ye(e, t, n) {
|
|
630
|
+
return `${Je(`CONFIRM ${e} ${t}`)} #${qe(n)}`;
|
|
631
631
|
}
|
|
632
|
-
function
|
|
632
|
+
function Xe(e) {
|
|
633
633
|
return {
|
|
634
|
-
confirmationPhrase:
|
|
634
|
+
confirmationPhrase: Ye(e.action, e.subject, e.payload),
|
|
635
635
|
mutationExecuted: !1,
|
|
636
636
|
preview: e.preview,
|
|
637
637
|
requiresConfirmation: !0,
|
|
638
638
|
success: !0
|
|
639
639
|
};
|
|
640
640
|
}
|
|
641
|
-
function
|
|
641
|
+
function I(e, t) {
|
|
642
642
|
let n = e[t];
|
|
643
643
|
return typeof n == "string" && n.trim() ? n.trim() : null;
|
|
644
644
|
}
|
|
645
|
-
function
|
|
645
|
+
function L(e, t) {
|
|
646
646
|
let n = Number(e[t]);
|
|
647
647
|
return Number.isFinite(n) ? n : null;
|
|
648
648
|
}
|
|
649
|
-
function
|
|
649
|
+
function R(e, t, n = `${t}s`) {
|
|
650
650
|
return `${e} ${e === 1 ? t : n}`;
|
|
651
651
|
}
|
|
652
|
-
function
|
|
653
|
-
let n =
|
|
652
|
+
function Ze(e, t) {
|
|
653
|
+
let n = I(t, "summary");
|
|
654
654
|
if (n) return n;
|
|
655
|
-
let r =
|
|
656
|
-
if (e === "create_cms_page" || e === "create_cms_post") return `Create ${a || "draft"} ${e === "create_cms_page" ? "page" : "post"} "${r || i || "Untitled"}"${i ? ` at slug "${i}"` : ""}${u === null ? "" : ` with ${
|
|
655
|
+
let r = I(t, "title"), i = I(t, "slug"), a = I(t, "status"), o = I(t, "contentType"), s = I(t, "field"), c = I(t, "mode"), l = I(t, "languageCode"), u = L(t, "blockCount"), d = L(t, "itemCount"), f = L(t, "affectedCount");
|
|
656
|
+
if (e === "create_cms_page" || e === "create_cms_post") return `Create ${a || "draft"} ${e === "create_cms_page" ? "page" : "post"} "${r || i || "Untitled"}"${i ? ` at slug "${i}"` : ""}${u === null ? "" : ` with ${R(u, "content block")}`}.`;
|
|
657
657
|
if (e === "create_cms_product") {
|
|
658
|
-
let e =
|
|
658
|
+
let e = L(t, "imageCount"), n = L(t, "blockCount"), o = [e ? R(e, "image") : null, n ? R(n, "description block") : L(t, "descriptionLength") ? "a full description" : null].filter(Boolean);
|
|
659
659
|
return `Create ${a || "draft"} product "${r || i || "Untitled"}"${i ? ` at slug "${i}"` : ""}${o.length ? ` with ${o.join(" and ")}` : ""}.`;
|
|
660
660
|
}
|
|
661
661
|
if (e === "update_cms_item_field") return `Update ${s || "one field"} on the ${o || "CMS item"} "${r || i || "selected item"}".`;
|
|
662
|
-
if (e === "update_navigation_bar") return `${c === "append" ? "Add" : c === "update" ? "Update" : "Replace"} ${d === null ? "navigation items" :
|
|
662
|
+
if (e === "update_navigation_bar") return `${c === "append" ? "Add" : c === "update" ? "Update" : "Replace"} ${d === null ? "navigation items" : R(d, "navigation item")} in the ${l || "selected"} header navigation.`;
|
|
663
663
|
if (e === "update_footer") {
|
|
664
|
-
let e =
|
|
665
|
-
return `Update the ${l || "selected"} footer${e === null ? "" : ` with ${
|
|
664
|
+
let e = L(t, "linkCount");
|
|
665
|
+
return `Update the ${l || "selected"} footer${e === null ? "" : ` with ${R(e, "link")}`}.`;
|
|
666
666
|
}
|
|
667
|
-
return e === "update_content_block" ? `Update the selected ${
|
|
667
|
+
return e === "update_content_block" ? `Update the selected ${I(t, "blockType") || "content"} block.` : e === "insert_content_block" ? `Insert ${I(t, "blockType") || "content"} block on the ${o || "CMS item"} "${r || i || "selected item"}".` : e === "update_section_column_block" ? `Update the selected nested ${I(t, "nestedBlockType") || "section"} block.` : e === "delete_cms_item" || e === "prepare_delete_cms_item" ? `Delete ${f === null ? `the selected ${o || "CMS item"}` : R(f, o || "CMS item")}${r || i ? ` for "${r || i}"` : ""}.` : "Complete the requested CMS change.";
|
|
668
668
|
}
|
|
669
|
-
function
|
|
669
|
+
function z(e) {
|
|
670
670
|
if (e.context?.skipConfirmation) return null;
|
|
671
|
-
let t =
|
|
671
|
+
let t = Xe(e), n = Je(e.context?.latestUserMessage || ""), r = Je(t.confirmationPhrase);
|
|
672
672
|
return n.includes(r) ? null : t;
|
|
673
673
|
}
|
|
674
|
-
function
|
|
674
|
+
function Qe(e) {
|
|
675
675
|
let t = e?.actorUserId;
|
|
676
676
|
if (!t) throw Error("A confirmed CMS mutation requires an authenticated admin actor.");
|
|
677
677
|
return t;
|
|
678
678
|
}
|
|
679
|
-
function
|
|
679
|
+
function $e() {
|
|
680
680
|
return globalThis.crypto?.randomUUID?.() || `id-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
681
681
|
}
|
|
682
|
-
function
|
|
682
|
+
function B(e) {
|
|
683
683
|
return e.normalize("NFD").replace(/\p{Diacritic}/gu, "").toLowerCase().trim().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "").replace(/-+/g, "-").replace(/^-|-$/g, "").slice(0, 300);
|
|
684
684
|
}
|
|
685
|
-
function
|
|
685
|
+
function et(e) {
|
|
686
686
|
return (e || "USD").trim().toUpperCase();
|
|
687
687
|
}
|
|
688
|
-
var
|
|
688
|
+
var tt = /* @__PURE__ */ new Set([
|
|
689
689
|
"BIF",
|
|
690
690
|
"CLP",
|
|
691
691
|
"DJF",
|
|
@@ -703,80 +703,80 @@ var Qe = /* @__PURE__ */ new Set([
|
|
|
703
703
|
"XOF",
|
|
704
704
|
"XPF"
|
|
705
705
|
]);
|
|
706
|
-
function
|
|
707
|
-
return
|
|
706
|
+
function nt(e) {
|
|
707
|
+
return tt.has(et(e)) ? 0 : 2;
|
|
708
708
|
}
|
|
709
|
-
function
|
|
710
|
-
return Math.round(e * 10 **
|
|
709
|
+
function rt(e, t) {
|
|
710
|
+
return Math.round(e * 10 ** nt(t));
|
|
711
711
|
}
|
|
712
|
-
function
|
|
712
|
+
function it(e, t) {
|
|
713
713
|
return !e || typeof e != "object" || Array.isArray(e) ? {} : Object.entries(e).reduce((e, [n, r]) => {
|
|
714
714
|
if (typeof r == "number" && Number.isFinite(r) && r >= 0) {
|
|
715
|
-
let i =
|
|
716
|
-
e[i] =
|
|
715
|
+
let i = et(n || t);
|
|
716
|
+
e[i] = rt(r, i);
|
|
717
717
|
}
|
|
718
718
|
return e;
|
|
719
719
|
}, {});
|
|
720
720
|
}
|
|
721
|
-
function
|
|
722
|
-
if (!
|
|
721
|
+
function V(e, t) {
|
|
722
|
+
if (!U(e)) throw Error(`${t} content must be a JSON object.`);
|
|
723
723
|
return JSON.parse(JSON.stringify(e));
|
|
724
724
|
}
|
|
725
|
-
function
|
|
725
|
+
function H(e) {
|
|
726
726
|
return JSON.parse(JSON.stringify(e));
|
|
727
727
|
}
|
|
728
|
-
function
|
|
728
|
+
function U(e) {
|
|
729
729
|
return !(!e || typeof e != "object" || Array.isArray(e));
|
|
730
730
|
}
|
|
731
|
-
function
|
|
732
|
-
let n =
|
|
731
|
+
function at(e, t) {
|
|
732
|
+
let n = H(e);
|
|
733
733
|
for (let [e, r] of Object.entries(t)) if (r !== void 0) {
|
|
734
|
-
if (
|
|
735
|
-
n[e] =
|
|
734
|
+
if (U(r) && U(n[e])) {
|
|
735
|
+
n[e] = at(n[e], r);
|
|
736
736
|
continue;
|
|
737
737
|
}
|
|
738
|
-
n[e] =
|
|
738
|
+
n[e] = H(r);
|
|
739
739
|
}
|
|
740
740
|
return n;
|
|
741
741
|
}
|
|
742
|
-
function
|
|
742
|
+
function ot(e, t) {
|
|
743
743
|
if (t.contentType === "product") {
|
|
744
|
-
if (String(e.product_id ?? "") !== String(
|
|
744
|
+
if (String(e.product_id ?? "") !== String(Fe(t))) throw Error(`Block ${e.id} does not belong to the current product being edited.`);
|
|
745
745
|
return;
|
|
746
746
|
}
|
|
747
|
-
let n =
|
|
747
|
+
let n = Pe(t);
|
|
748
748
|
if ((t.contentType === "page" ? Number(e.page_id) : Number(e.post_id)) !== n) throw Error(`Block ${e.id} does not belong to the current ${t.contentType} being edited.`);
|
|
749
749
|
}
|
|
750
|
-
function
|
|
750
|
+
function st(e, t) {
|
|
751
751
|
return t?.customBlockDefinitions?.find((t) => t.slug === e) ?? null;
|
|
752
752
|
}
|
|
753
|
-
function
|
|
753
|
+
function ct(e, t = /* @__PURE__ */ new Set(), n = 0) {
|
|
754
754
|
if (n > 12 || !e) return t;
|
|
755
755
|
if (typeof e == "string") return t.add(e), t;
|
|
756
756
|
if (Array.isArray(e)) {
|
|
757
|
-
for (let r of e)
|
|
757
|
+
for (let r of e) ct(r, t, n + 1);
|
|
758
758
|
return t;
|
|
759
759
|
}
|
|
760
|
-
if (typeof e == "object") for (let [r, i] of Object.entries(e)) (r === "block_type" || r === "blockType" || r === "anchorBlockType") && typeof i == "string" ? t.add(i) : i && typeof i == "object" &&
|
|
760
|
+
if (typeof e == "object") for (let [r, i] of Object.entries(e)) (r === "block_type" || r === "blockType" || r === "anchorBlockType") && typeof i == "string" ? t.add(i) : i && typeof i == "object" && ct(i, t, n + 1);
|
|
761
761
|
return t;
|
|
762
762
|
}
|
|
763
|
-
async function
|
|
764
|
-
return e?.customBlockDefinitions || !e?.supabase || ![...
|
|
763
|
+
async function W(e, t) {
|
|
764
|
+
return e?.customBlockDefinitions || !e?.supabase || ![...ct(t)].some((e) => !r(e)) ? e : {
|
|
765
765
|
...e,
|
|
766
766
|
customBlockDefinitions: await i(e.supabase)
|
|
767
767
|
};
|
|
768
768
|
}
|
|
769
|
-
function
|
|
769
|
+
function G(e, t, i) {
|
|
770
770
|
let a = typeof e == "string" ? e.trim() : "";
|
|
771
|
-
if (r(a) || a &&
|
|
771
|
+
if (r(a) || a && st(a, i)) return a;
|
|
772
772
|
throw Error(`${t} has unsupported block type "${a || "unknown"}". Built-in types: ${n.join(", ")}; a custom block must use a slug returned by list_custom_blocks.`);
|
|
773
773
|
}
|
|
774
|
-
function
|
|
774
|
+
function lt(e, t, n) {
|
|
775
775
|
if (e && e !== t) throw Error(`${n} is a "${t}" block. Refusing to update it as "${e}".`);
|
|
776
776
|
}
|
|
777
777
|
function K(e, t, n, i) {
|
|
778
778
|
if (!r(e)) {
|
|
779
|
-
let r =
|
|
779
|
+
let r = st(e, i);
|
|
780
780
|
if (!r) throw Error(`${n} references custom block "${e}", which does not exist.`);
|
|
781
781
|
let a = s(r, t);
|
|
782
782
|
if (!a.isValid) throw Error(`${n} content is invalid for custom block "${e}": ${a.errors.join("; ")}`);
|
|
@@ -785,68 +785,68 @@ function K(e, t, n, i) {
|
|
|
785
785
|
let a = o(e, t, i);
|
|
786
786
|
if (!a.isValid) throw Error(`${n} content is invalid for block type "${e}": ${a.errors.join("; ")}`);
|
|
787
787
|
}
|
|
788
|
-
function
|
|
788
|
+
function ut(e) {
|
|
789
789
|
return e === "section";
|
|
790
790
|
}
|
|
791
|
-
function
|
|
791
|
+
function dt(e) {
|
|
792
792
|
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.form_key == "string" || 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;
|
|
793
793
|
}
|
|
794
|
-
function
|
|
794
|
+
function ft(e) {
|
|
795
795
|
return `ai-${e}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
796
796
|
}
|
|
797
|
-
function
|
|
798
|
-
if (!
|
|
799
|
-
let r =
|
|
800
|
-
if (
|
|
801
|
-
let i =
|
|
797
|
+
function pt(e, t, n) {
|
|
798
|
+
if (!U(e)) throw Error(`${t} must be a JSON object.`);
|
|
799
|
+
let r = G(e.block_type ?? e.blockType, t, n);
|
|
800
|
+
if (ut(r)) throw Error(`${t} cannot be a nested ${r} block.`);
|
|
801
|
+
let i = Jt(r, V(e.content, t), t, n), a = e.temp_id ?? e.tempId;
|
|
802
802
|
return {
|
|
803
803
|
block_type: r,
|
|
804
804
|
content: i,
|
|
805
|
-
temp_id: typeof a == "string" && a.trim() ? a :
|
|
805
|
+
temp_id: typeof a == "string" && a.trim() ? a : ft(r)
|
|
806
806
|
};
|
|
807
807
|
}
|
|
808
|
-
function
|
|
808
|
+
function mt(e, t) {
|
|
809
809
|
let n = [];
|
|
810
|
-
if ("append_block" in e && n.push(
|
|
810
|
+
if ("append_block" in e && n.push(pt(e.append_block, "Nested block to append", t)), "append_blocks" in e) {
|
|
811
811
|
let r = e.append_blocks;
|
|
812
812
|
if (!Array.isArray(r)) throw Error("append_blocks must be an array of nested block objects.");
|
|
813
813
|
r.forEach((e, r) => {
|
|
814
|
-
n.push(
|
|
814
|
+
n.push(pt(e, `Nested block to append ${r}`, t));
|
|
815
815
|
});
|
|
816
816
|
}
|
|
817
817
|
return n;
|
|
818
818
|
}
|
|
819
|
-
function
|
|
819
|
+
function ht(e, t) {
|
|
820
820
|
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) return null;
|
|
821
|
-
let n =
|
|
821
|
+
let n = dt(e);
|
|
822
822
|
if (!n) return null;
|
|
823
|
-
let r =
|
|
823
|
+
let r = V(e, `Nested ${n} block`);
|
|
824
824
|
return K(n, r, `Nested ${n} block`, t), {
|
|
825
825
|
block_type: n,
|
|
826
826
|
content: r,
|
|
827
|
-
temp_id:
|
|
827
|
+
temp_id: ft(n)
|
|
828
828
|
};
|
|
829
829
|
}
|
|
830
|
-
function
|
|
830
|
+
function gt(e, t) {
|
|
831
831
|
let n = e.append_column_index ?? e.column_index;
|
|
832
832
|
if (n === void 0) return 0;
|
|
833
833
|
if (typeof n != "number" || !Number.isInteger(n) || n < 0) throw Error("append_column_index must be a non-negative integer.");
|
|
834
834
|
if (t > 0 && n >= t) throw Error(`append_column_index ${n} is outside the existing ${t} column(s).`);
|
|
835
835
|
return n;
|
|
836
836
|
}
|
|
837
|
-
function
|
|
838
|
-
if (!
|
|
839
|
-
let i = { ...n }, a =
|
|
837
|
+
function _t(e, t, n, r) {
|
|
838
|
+
if (!ut(e)) return at(t, n);
|
|
839
|
+
let i = { ...n }, a = mt(i, r), o = ht(i, r);
|
|
840
840
|
o && a.push(o), delete i.append_block, delete i.append_blocks, delete i.append_column_index, delete i.column_index;
|
|
841
|
-
let s =
|
|
841
|
+
let s = at(t, i);
|
|
842
842
|
if (a.length > 0) {
|
|
843
|
-
let e = Array.isArray(t.column_blocks) ?
|
|
843
|
+
let e = Array.isArray(t.column_blocks) ? H(t.column_blocks) : [], r = gt(n, e.length), i = e.length > 0 ? e : [[]];
|
|
844
844
|
for (; i.length <= r;) i.push([]);
|
|
845
845
|
i[r] = [...i[r] || [], ...a], s.column_blocks = i;
|
|
846
846
|
}
|
|
847
847
|
return s;
|
|
848
848
|
}
|
|
849
|
-
function
|
|
849
|
+
function vt(e, t) {
|
|
850
850
|
return {
|
|
851
851
|
blockType: e.block_type,
|
|
852
852
|
content: t ? e.content : void 0,
|
|
@@ -860,20 +860,20 @@ function _t(e, t) {
|
|
|
860
860
|
function q(e) {
|
|
861
861
|
return typeof e == "string" ? e.trim().toLowerCase() : "";
|
|
862
862
|
}
|
|
863
|
-
function
|
|
863
|
+
function yt(e) {
|
|
864
864
|
return typeof e == "string" ? e.trim().toLowerCase() : "";
|
|
865
865
|
}
|
|
866
|
-
function
|
|
866
|
+
function bt(e) {
|
|
867
867
|
return e.reduce((e, t) => e + 1 + (t.children?.length || 0), 0);
|
|
868
868
|
}
|
|
869
|
-
function
|
|
869
|
+
function xt(e) {
|
|
870
870
|
return typeof e == "string" ? e.trim().toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "") : "";
|
|
871
871
|
}
|
|
872
872
|
async function J(e, t) {
|
|
873
|
-
let n =
|
|
874
|
-
if (a) throw Error(`Failed to load language "${t}": ${
|
|
873
|
+
let n = xt(t.trim()), r = b[n], { data: i, error: a } = await e.from("languages").select("id, code, name, is_active");
|
|
874
|
+
if (a) throw Error(`Failed to load language "${t}": ${F(a)}`);
|
|
875
875
|
let o = (Array.isArray(i) ? i : []).filter((e) => e.is_active !== !1), s = o.find((e) => {
|
|
876
|
-
let t =
|
|
876
|
+
let t = xt(e.code), i = xt(e.name);
|
|
877
877
|
return t === n || t === r || i === n;
|
|
878
878
|
});
|
|
879
879
|
if (!s?.id || !s?.code) {
|
|
@@ -885,53 +885,53 @@ async function J(e, t) {
|
|
|
885
885
|
id: Number(s.id)
|
|
886
886
|
};
|
|
887
887
|
}
|
|
888
|
-
async function
|
|
888
|
+
async function St(e, t) {
|
|
889
889
|
if (t) return J(e, t);
|
|
890
890
|
let { data: n, error: r } = await e.from("languages").select("id, code, name, is_active, is_default");
|
|
891
|
-
if (r) throw Error(`Failed to load active languages: ${
|
|
892
|
-
let i = (Array.isArray(n) ? n : []).filter((e) => e.is_active !== !1), a = i.find((e) => e.is_default) || i.find((e) =>
|
|
891
|
+
if (r) throw Error(`Failed to load active languages: ${F(r)}`);
|
|
892
|
+
let i = (Array.isArray(n) ? n : []).filter((e) => e.is_active !== !1), a = i.find((e) => e.is_default) || i.find((e) => xt(e.code) === "en") || i[0];
|
|
893
893
|
if (!a?.id || !a?.code) throw Error("No active CMS language is available for Cortex AI content creation.");
|
|
894
894
|
return {
|
|
895
895
|
code: String(a.code),
|
|
896
896
|
id: Number(a.id)
|
|
897
897
|
};
|
|
898
898
|
}
|
|
899
|
-
async function
|
|
899
|
+
async function Ct(e) {
|
|
900
900
|
try {
|
|
901
901
|
let { data: t, error: n } = await e.from("currencies").select("code, is_default, is_active").eq("is_active", !0);
|
|
902
902
|
if (n) return "USD";
|
|
903
903
|
let r = Array.isArray(t) ? t : [];
|
|
904
|
-
return
|
|
904
|
+
return et((r.find((e) => e.is_default) || r[0])?.code || "USD");
|
|
905
905
|
} catch {
|
|
906
906
|
return "USD";
|
|
907
907
|
}
|
|
908
908
|
}
|
|
909
|
-
async function
|
|
909
|
+
async function wt(e) {
|
|
910
910
|
let t = e.contentType === "page" ? "pages" : e.contentType === "post" ? "posts" : "products", n = "id", r = e.entityId;
|
|
911
911
|
if (r === void 0 && e.slug && (n = "slug", r = e.slug), r === void 0 && e.title && (n = "title", r = e.title), r === void 0) throw Error(`A ${e.contentType} target requires an id, slug, title, or current edit context.`);
|
|
912
912
|
let { data: i, error: a } = await e.supabase.from(t).select("*").eq(n, r);
|
|
913
|
-
if (a) throw Error(`Failed to resolve ${e.contentType}: ${
|
|
913
|
+
if (a) throw Error(`Failed to resolve ${e.contentType}: ${F(a)}`);
|
|
914
914
|
let o = Array.isArray(i) ? i : i ? [i] : [];
|
|
915
915
|
if (o.length !== 1) throw Error(o.length === 0 ? `No ${e.contentType} matched ${n} "${String(r)}".` : `Multiple ${e.contentType}s matched ${n} "${String(r)}"; use an exact id.`);
|
|
916
916
|
return o[0];
|
|
917
917
|
}
|
|
918
918
|
async function Y(e, t) {
|
|
919
|
-
let n =
|
|
919
|
+
let n = ie.safeParse(t?.pageContext).success ? t?.pageContext : null, r = e.contentType || n?.contentType;
|
|
920
920
|
if (!r) throw Error("Target contentType is required when no current CMS edit context exists.");
|
|
921
921
|
let i = e.entityId !== void 0 || !!e.slug || !!e.title, a = e.entityId ?? (i ? void 0 : n?.entityId), o = e.slug ?? (i ? void 0 : n?.slug ?? void 0), s = e.title ?? (i ? void 0 : n?.title ?? void 0);
|
|
922
922
|
return {
|
|
923
923
|
contentType: r,
|
|
924
|
-
item: await
|
|
924
|
+
item: await wt({
|
|
925
925
|
contentType: r,
|
|
926
926
|
entityId: a,
|
|
927
927
|
slug: a === void 0 && o || void 0,
|
|
928
|
-
supabase:
|
|
928
|
+
supabase: j(t),
|
|
929
929
|
title: a === void 0 && !o && s || void 0
|
|
930
930
|
})
|
|
931
931
|
};
|
|
932
932
|
}
|
|
933
933
|
async function X(e, t) {
|
|
934
|
-
let n =
|
|
934
|
+
let n = ie.safeParse(t?.pageContext);
|
|
935
935
|
if (n.success) return n.data;
|
|
936
936
|
if (e === void 0 || e.entityId === void 0 && !e.slug && !e.title) throw Error("No current CMS page context is available. Open a page, post, or product edit screen, or pass `cmsTarget` naming the item — contentType plus one of slug, entityId, or title.");
|
|
937
937
|
let r = await Y(e, t), i = r.item;
|
|
@@ -942,8 +942,8 @@ async function X(e, t) {
|
|
|
942
942
|
title: typeof i.title == "string" ? i.title : ""
|
|
943
943
|
};
|
|
944
944
|
}
|
|
945
|
-
async function
|
|
946
|
-
let t = await
|
|
945
|
+
async function Tt(e) {
|
|
946
|
+
let t = await Dt({
|
|
947
947
|
item: e.item,
|
|
948
948
|
languageId: e.languageId,
|
|
949
949
|
menuKey: e.menuKey,
|
|
@@ -958,28 +958,28 @@ async function wt(e) {
|
|
|
958
958
|
...t?.navigationTranslationGroupId ? { translation_group_id: t.navigationTranslationGroupId } : {},
|
|
959
959
|
url: e.item.url
|
|
960
960
|
}, { data: r, error: i } = await e.supabase.from("navigation_items").insert(n).select("id").single();
|
|
961
|
-
if (i) throw Error(`Failed to insert ${e.menuKey} navigation item: ${
|
|
961
|
+
if (i) throw Error(`Failed to insert ${e.menuKey} navigation item: ${F(i)}`);
|
|
962
962
|
return Number(r.id);
|
|
963
963
|
}
|
|
964
|
-
function
|
|
964
|
+
function Et(e) {
|
|
965
965
|
let t = e.trim();
|
|
966
966
|
if (!t.startsWith("/") || t.startsWith("//")) return null;
|
|
967
967
|
let n = t.split("?")[0]?.split("#")[0] || "", r = n === "/" ? "home" : n.replace(/^\/+|\/+$/g, "");
|
|
968
968
|
return r && !r.includes("/") ? r : null;
|
|
969
969
|
}
|
|
970
|
-
async function
|
|
971
|
-
let t =
|
|
970
|
+
async function Dt(e) {
|
|
971
|
+
let t = Et(e.item.url);
|
|
972
972
|
if (!t) return null;
|
|
973
973
|
let { 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);
|
|
974
|
-
if (r) throw Error(`Failed to resolve linked page for navigation item: ${
|
|
974
|
+
if (r) throw Error(`Failed to resolve linked page for navigation item: ${F(r)}`);
|
|
975
975
|
let i = Array.isArray(n) ? n[0] : n;
|
|
976
976
|
if (!i?.id) return null;
|
|
977
|
-
let a =
|
|
977
|
+
let a = $e();
|
|
978
978
|
if (i.translation_group_id) {
|
|
979
979
|
let { data: t, error: n } = await e.supabase.from("pages").select("id").eq("translation_group_id", i.translation_group_id);
|
|
980
|
-
if (n) throw Error(`Failed to inspect linked page translations for navigation item: ${
|
|
980
|
+
if (n) throw Error(`Failed to inspect linked page translations for navigation item: ${F(n)}`);
|
|
981
981
|
let r = new Set((Array.isArray(t) ? t : []).map((e) => String(e.id)).filter(Boolean)), { data: o, error: s } = await e.supabase.from("navigation_items").select("id, page_id, translation_group_id, menu_key").eq("menu_key", e.menuKey);
|
|
982
|
-
if (s) throw Error(`Failed to inspect related navigation translations: ${
|
|
982
|
+
if (s) throw Error(`Failed to inspect related navigation translations: ${F(s)}`);
|
|
983
983
|
let c = (Array.isArray(o) ? o : []).find((e) => e.translation_group_id && r.has(String(e.page_id)));
|
|
984
984
|
c?.translation_group_id && (a = c.translation_group_id);
|
|
985
985
|
}
|
|
@@ -988,11 +988,11 @@ async function Et(e) {
|
|
|
988
988
|
pageId: Number(i.id)
|
|
989
989
|
};
|
|
990
990
|
}
|
|
991
|
-
async function
|
|
991
|
+
async function Ot(e) {
|
|
992
992
|
let t = await J(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);
|
|
993
|
-
if (r) throw Error(`Failed to inspect existing ${e.menuKey} navigation items: ${
|
|
994
|
-
let i = Array.isArray(n) ? n : [], a = i.filter((e) => e.parent_id == null).length, o =
|
|
995
|
-
|
|
993
|
+
if (r) throw Error(`Failed to inspect existing ${e.menuKey} navigation items: ${F(r)}`);
|
|
994
|
+
let i = Array.isArray(n) ? n : [], a = i.filter((e) => e.parent_id == null).length, o = bt(e.items);
|
|
995
|
+
kt({
|
|
996
996
|
existingItemCount: i.length,
|
|
997
997
|
existingTopLevelCount: a,
|
|
998
998
|
languageCode: t.code,
|
|
@@ -1000,10 +1000,10 @@ async function Dt(e) {
|
|
|
1000
1000
|
replacementItemCount: o
|
|
1001
1001
|
});
|
|
1002
1002
|
let { error: s } = await e.supabase.from("navigation_items").delete().eq("menu_key", e.menuKey).eq("language_id", t.id);
|
|
1003
|
-
if (s) throw Error(`Failed to clear ${e.menuKey} navigation items: ${
|
|
1003
|
+
if (s) throw Error(`Failed to clear ${e.menuKey} navigation items: ${F(s)}`);
|
|
1004
1004
|
let c = 0;
|
|
1005
1005
|
for (let [n, r] of e.items.entries()) {
|
|
1006
|
-
let i = await
|
|
1006
|
+
let i = await Tt({
|
|
1007
1007
|
item: r,
|
|
1008
1008
|
languageId: t.id,
|
|
1009
1009
|
menuKey: e.menuKey,
|
|
@@ -1011,7 +1011,7 @@ async function Dt(e) {
|
|
|
1011
1011
|
supabase: e.supabase
|
|
1012
1012
|
});
|
|
1013
1013
|
c++;
|
|
1014
|
-
for (let [n, a] of (r.children ?? []).entries()) await
|
|
1014
|
+
for (let [n, a] of (r.children ?? []).entries()) await Tt({
|
|
1015
1015
|
item: a,
|
|
1016
1016
|
languageId: t.id,
|
|
1017
1017
|
menuKey: e.menuKey,
|
|
@@ -1028,27 +1028,27 @@ async function Dt(e) {
|
|
|
1028
1028
|
updatedCount: 0
|
|
1029
1029
|
};
|
|
1030
1030
|
}
|
|
1031
|
-
function
|
|
1031
|
+
function kt(e) {
|
|
1032
1032
|
if (!(e.existingItemCount === 0 || e.replacementItemCount >= e.existingItemCount)) throw Error(`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.`);
|
|
1033
1033
|
}
|
|
1034
|
-
async function
|
|
1034
|
+
async function At(e) {
|
|
1035
1035
|
let t = await J(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);
|
|
1036
|
-
if (r) throw Error(`Failed to inspect existing ${e.menuKey} navigation items: ${
|
|
1036
|
+
if (r) throw Error(`Failed to inspect existing ${e.menuKey} navigation items: ${F(r)}`);
|
|
1037
1037
|
let i = Array.isArray(n) ? n : [];
|
|
1038
|
-
|
|
1038
|
+
kt({
|
|
1039
1039
|
existingItemCount: i.length,
|
|
1040
1040
|
existingTopLevelCount: i.filter((e) => e.parent_id == null).length,
|
|
1041
1041
|
languageCode: t.code,
|
|
1042
1042
|
menuKey: e.menuKey,
|
|
1043
|
-
replacementItemCount:
|
|
1043
|
+
replacementItemCount: bt(e.items)
|
|
1044
1044
|
});
|
|
1045
1045
|
}
|
|
1046
|
-
async function
|
|
1046
|
+
async function jt(e) {
|
|
1047
1047
|
if (e.items.length !== 1) throw Error("mode \"update\" requires exactly one navigation item.");
|
|
1048
|
-
let t = await J(e.supabase, e.languageCode), n = e.items[0], r = q(e.match?.url) || q(n.url), i =
|
|
1049
|
-
if (o) throw Error(`Failed to load existing ${e.menuKey} navigation items: ${
|
|
1048
|
+
let t = await J(e.supabase, e.languageCode), n = e.items[0], r = q(e.match?.url) || q(n.url), i = yt(e.match?.label), { data: a, error: o } = await e.supabase.from("navigation_items").select("id, label, url, parent_id, order").eq("menu_key", e.menuKey).eq("language_id", t.id);
|
|
1049
|
+
if (o) throw Error(`Failed to load existing ${e.menuKey} navigation items: ${F(o)}`);
|
|
1050
1050
|
let s = (Array.isArray(a) ? a : []).find((e) => {
|
|
1051
|
-
let t = q(e.url), n =
|
|
1051
|
+
let t = q(e.url), n = yt(e.label);
|
|
1052
1052
|
return !!(r && t === r || i && n === i);
|
|
1053
1053
|
});
|
|
1054
1054
|
if (!s?.id) throw Error(`Could not find a ${e.menuKey} navigation item to update in ${t.code}. Use a matching label or url.`);
|
|
@@ -1056,7 +1056,7 @@ async function At(e) {
|
|
|
1056
1056
|
label: n.label,
|
|
1057
1057
|
url: n.url
|
|
1058
1058
|
}).eq("id", s.id);
|
|
1059
|
-
if (c) throw Error(`Failed to update ${e.menuKey} navigation item: ${
|
|
1059
|
+
if (c) throw Error(`Failed to update ${e.menuKey} navigation item: ${F(c)}`);
|
|
1060
1060
|
return {
|
|
1061
1061
|
insertedCount: 0,
|
|
1062
1062
|
languageCode: t.code,
|
|
@@ -1065,9 +1065,9 @@ async function At(e) {
|
|
|
1065
1065
|
updatedCount: 1
|
|
1066
1066
|
};
|
|
1067
1067
|
}
|
|
1068
|
-
async function
|
|
1068
|
+
async function Mt(e) {
|
|
1069
1069
|
let t = await J(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);
|
|
1070
|
-
if (r) throw Error(`Failed to load existing ${e.menuKey} navigation items: ${
|
|
1070
|
+
if (r) throw Error(`Failed to load existing ${e.menuKey} navigation items: ${F(r)}`);
|
|
1071
1071
|
let i = 0, a = 0, o = Array.isArray(n) ? n : [], s = new Set(o.map((e) => q(e.url)).filter(Boolean)), c = o.filter((e) => e.parent_id == null).map((e) => Number(e.order)).filter(Number.isFinite), l = c.length > 0 ? Math.max(...c) + 1 : o.length;
|
|
1072
1072
|
for (let n of e.items) {
|
|
1073
1073
|
let r = q(n.url);
|
|
@@ -1075,7 +1075,7 @@ async function jt(e) {
|
|
|
1075
1075
|
a++;
|
|
1076
1076
|
continue;
|
|
1077
1077
|
}
|
|
1078
|
-
let o = await
|
|
1078
|
+
let o = await Tt({
|
|
1079
1079
|
item: n,
|
|
1080
1080
|
languageId: t.id,
|
|
1081
1081
|
menuKey: e.menuKey,
|
|
@@ -1090,7 +1090,7 @@ async function jt(e) {
|
|
|
1090
1090
|
a++;
|
|
1091
1091
|
continue;
|
|
1092
1092
|
}
|
|
1093
|
-
await
|
|
1093
|
+
await Tt({
|
|
1094
1094
|
item: r,
|
|
1095
1095
|
languageId: t.id,
|
|
1096
1096
|
menuKey: e.menuKey,
|
|
@@ -1111,10 +1111,10 @@ async function jt(e) {
|
|
|
1111
1111
|
function Z(e) {
|
|
1112
1112
|
return typeof e == "string" && e.trim() ? e.trim() : "";
|
|
1113
1113
|
}
|
|
1114
|
-
function
|
|
1114
|
+
function Nt(e) {
|
|
1115
1115
|
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
1116
1116
|
}
|
|
1117
|
-
function
|
|
1117
|
+
function Pt(e) {
|
|
1118
1118
|
let t = Z(e.field_type ?? e.fieldType ?? e.type ?? e.input_type).toLowerCase().replace(/\s+/g, "_"), n = Z(e.label ?? e.name ?? e.placeholder).toLowerCase();
|
|
1119
1119
|
return [
|
|
1120
1120
|
"email",
|
|
@@ -1141,7 +1141,7 @@ function Nt(e) {
|
|
|
1141
1141
|
"quantity"
|
|
1142
1142
|
].includes(t) ? "number" : n.includes("email") || n.includes("courriel") ? "email" : n.includes("phone") || n.includes("téléphone") || n.includes("telephone") ? "tel" : n.includes("website") || n.includes("site web") ? "url" : n.includes("message") || n.includes("comment") || n.includes("details") ? "textarea" : "text";
|
|
1143
1143
|
}
|
|
1144
|
-
function
|
|
1144
|
+
function Ft(e) {
|
|
1145
1145
|
return (Array.isArray(e) && e.length > 0 ? e : [
|
|
1146
1146
|
{
|
|
1147
1147
|
field_type: "text",
|
|
@@ -1162,7 +1162,7 @@ function Pt(e) {
|
|
|
1162
1162
|
placeholder: "How can we help?"
|
|
1163
1163
|
}
|
|
1164
1164
|
]).map((e, t) => {
|
|
1165
|
-
let n =
|
|
1165
|
+
let n = U(e) ? e : {}, r = Z(n.label ?? n.name) || (t === 0 ? "Name" : t === 1 ? "Email" : "Message"), i = Pt({
|
|
1166
1166
|
...n,
|
|
1167
1167
|
label: r
|
|
1168
1168
|
}), a = n.is_required ?? n.isRequired ?? n.required;
|
|
@@ -1176,58 +1176,58 @@ function Pt(e) {
|
|
|
1176
1176
|
};
|
|
1177
1177
|
});
|
|
1178
1178
|
}
|
|
1179
|
-
var
|
|
1179
|
+
var It = /* @__PURE__ */ new Set([
|
|
1180
1180
|
"none",
|
|
1181
1181
|
"sm",
|
|
1182
1182
|
"md",
|
|
1183
1183
|
"lg",
|
|
1184
1184
|
"xl"
|
|
1185
|
-
]),
|
|
1185
|
+
]), Lt = /* @__PURE__ */ new Set([
|
|
1186
1186
|
"none",
|
|
1187
1187
|
"sm",
|
|
1188
1188
|
"md",
|
|
1189
1189
|
"lg",
|
|
1190
1190
|
"xl"
|
|
1191
|
-
]),
|
|
1191
|
+
]), Rt = /* @__PURE__ */ new Set([
|
|
1192
1192
|
"full-width",
|
|
1193
1193
|
"container",
|
|
1194
1194
|
"container-sm",
|
|
1195
1195
|
"container-lg",
|
|
1196
1196
|
"container-xl"
|
|
1197
|
-
]),
|
|
1197
|
+
]), zt = /* @__PURE__ */ new Set([
|
|
1198
1198
|
"start",
|
|
1199
1199
|
"center",
|
|
1200
1200
|
"end",
|
|
1201
1201
|
"stretch"
|
|
1202
|
-
]),
|
|
1202
|
+
]), Bt = /* @__PURE__ */ new Set([
|
|
1203
1203
|
"none",
|
|
1204
1204
|
"theme",
|
|
1205
1205
|
"solid",
|
|
1206
1206
|
"gradient",
|
|
1207
1207
|
"image"
|
|
1208
|
-
]),
|
|
1208
|
+
]), Vt = /* @__PURE__ */ new Set([
|
|
1209
1209
|
"primary",
|
|
1210
1210
|
"secondary",
|
|
1211
1211
|
"muted",
|
|
1212
1212
|
"accent",
|
|
1213
1213
|
"destructive"
|
|
1214
|
-
]),
|
|
1214
|
+
]), Ht = /* @__PURE__ */ new Set([
|
|
1215
1215
|
"center",
|
|
1216
1216
|
"top",
|
|
1217
1217
|
"bottom",
|
|
1218
1218
|
"left",
|
|
1219
1219
|
"right"
|
|
1220
1220
|
]);
|
|
1221
|
-
function
|
|
1221
|
+
function Ut(e) {
|
|
1222
1222
|
return typeof e == "string" && /^https?:\/\//i.test(e.trim());
|
|
1223
1223
|
}
|
|
1224
1224
|
function Q(e, t, n) {
|
|
1225
1225
|
return typeof e == "string" && t.has(e) ? e : n;
|
|
1226
1226
|
}
|
|
1227
|
-
function
|
|
1227
|
+
function Wt(e) {
|
|
1228
1228
|
return Number.isFinite(e) ? Math.min(4, Math.max(1, Math.round(e))) : 1;
|
|
1229
1229
|
}
|
|
1230
|
-
function
|
|
1230
|
+
function Gt(e) {
|
|
1231
1231
|
let t = [{
|
|
1232
1232
|
color: "#1e3a8a",
|
|
1233
1233
|
position: 0
|
|
@@ -1235,7 +1235,7 @@ function Wt(e) {
|
|
|
1235
1235
|
color: "#3b82f6",
|
|
1236
1236
|
position: 100
|
|
1237
1237
|
}];
|
|
1238
|
-
if (!
|
|
1238
|
+
if (!U(e)) return {
|
|
1239
1239
|
direction: "to bottom right",
|
|
1240
1240
|
stops: t,
|
|
1241
1241
|
type: "linear"
|
|
@@ -1247,11 +1247,11 @@ function Wt(e) {
|
|
|
1247
1247
|
type: n
|
|
1248
1248
|
};
|
|
1249
1249
|
}
|
|
1250
|
-
function
|
|
1251
|
-
if (!
|
|
1252
|
-
let t = Q(e.type,
|
|
1250
|
+
function Kt(e) {
|
|
1251
|
+
if (!U(e)) return { type: "none" };
|
|
1252
|
+
let t = Q(e.type, Bt, "none"), n = typeof e.min_height == "string" && e.min_height.trim() ? { min_height: e.min_height } : {};
|
|
1253
1253
|
if (t === "theme") return {
|
|
1254
|
-
theme: Q(e.theme,
|
|
1254
|
+
theme: Q(e.theme, Vt, "muted"),
|
|
1255
1255
|
type: t,
|
|
1256
1256
|
...n
|
|
1257
1257
|
};
|
|
@@ -1261,17 +1261,17 @@ function Gt(e) {
|
|
|
1261
1261
|
...n
|
|
1262
1262
|
} : { type: "none" };
|
|
1263
1263
|
if (t === "gradient") return {
|
|
1264
|
-
gradient:
|
|
1264
|
+
gradient: Gt(e.gradient),
|
|
1265
1265
|
type: t,
|
|
1266
1266
|
...n
|
|
1267
1267
|
};
|
|
1268
1268
|
if (t === "image") {
|
|
1269
|
-
let r =
|
|
1269
|
+
let r = U(e.image) ? e.image : null, i = r && Ut(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());
|
|
1270
1270
|
return r && (i || a) ? {
|
|
1271
1271
|
image: {
|
|
1272
1272
|
...r,
|
|
1273
1273
|
...i ? { external_url: i } : {},
|
|
1274
|
-
position: Q(r.position,
|
|
1274
|
+
position: Q(r.position, Ht, "center"),
|
|
1275
1275
|
size: r.size === "contain" ? "contain" : "cover"
|
|
1276
1276
|
},
|
|
1277
1277
|
type: t,
|
|
@@ -1283,60 +1283,60 @@ function Gt(e) {
|
|
|
1283
1283
|
...n
|
|
1284
1284
|
};
|
|
1285
1285
|
}
|
|
1286
|
-
function
|
|
1286
|
+
function qt(e, t, n) {
|
|
1287
1287
|
let r = e.is_hero === !0, i = Array.isArray(e.column_blocks) ? e.column_blocks : [];
|
|
1288
|
-
i.length > 0 && i.every((e) =>
|
|
1289
|
-
let a = i.map((e, r) => (Array.isArray(e) ? e : []).map((e, i) =>
|
|
1288
|
+
i.length > 0 && i.every((e) => U(e) && !Array.isArray(e)) && (i = [i]);
|
|
1289
|
+
let a = i.map((e, r) => (Array.isArray(e) ? e : []).map((e, i) => pt(e, `${t} column ${r} block ${i}`, n))), o = a.length > 0 ? a : [[]], s = Wt(o.length), c = U(e.responsive_columns) ? e.responsive_columns : {}, l = Number(c.tablet), u = Number(c.mobile), d = Number.isFinite(l) ? Math.min(3, Math.max(1, Math.min(s, l))) : Math.min(3, s), f = Number.isFinite(u) ? Math.min(2, Math.max(1, u)) : 1, p = U(e.padding) ? e.padding : {}, m = {
|
|
1290
1290
|
...e,
|
|
1291
|
-
background:
|
|
1291
|
+
background: Kt(e.background),
|
|
1292
1292
|
column_blocks: o,
|
|
1293
|
-
column_gap: Q(e.column_gap,
|
|
1294
|
-
container_type: Q(e.container_type,
|
|
1293
|
+
column_gap: Q(e.column_gap, It, "lg"),
|
|
1294
|
+
container_type: Q(e.container_type, Rt, "container"),
|
|
1295
1295
|
padding: {
|
|
1296
|
-
bottom: Q(p.bottom,
|
|
1297
|
-
top: Q(p.top,
|
|
1296
|
+
bottom: Q(p.bottom, Lt, "xl"),
|
|
1297
|
+
top: Q(p.top, Lt, "xl")
|
|
1298
1298
|
},
|
|
1299
1299
|
responsive_columns: {
|
|
1300
1300
|
desktop: s,
|
|
1301
1301
|
mobile: f,
|
|
1302
1302
|
tablet: d
|
|
1303
1303
|
},
|
|
1304
|
-
vertical_alignment: Q(e.vertical_alignment,
|
|
1304
|
+
vertical_alignment: Q(e.vertical_alignment, zt, r ? "center" : "start")
|
|
1305
1305
|
};
|
|
1306
|
-
return Array.isArray(e.slides) && (m.slides = e.slides.filter((e) =>
|
|
1306
|
+
return Array.isArray(e.slides) && (m.slides = e.slides.filter((e) => U(e)).map((e, r) => {
|
|
1307
1307
|
let i = Array.isArray(e.column_blocks) ? e.column_blocks : [];
|
|
1308
|
-
return i.length > 0 && i.every((e) =>
|
|
1309
|
-
background:
|
|
1310
|
-
column_blocks: i.map((e, i) => (Array.isArray(e) ? e : []).map((e, a) =>
|
|
1308
|
+
return i.length > 0 && i.every((e) => U(e) && !Array.isArray(e)) && (i = [i]), {
|
|
1309
|
+
background: Kt(e.background),
|
|
1310
|
+
column_blocks: i.map((e, i) => (Array.isArray(e) ? e : []).map((e, a) => pt(e, `${t} slide ${r} column ${i} block ${a}`, n)))
|
|
1311
1311
|
};
|
|
1312
1312
|
})), m.slider === !0 && !(Array.isArray(m.slides) && m.slides.length > 0) && (m.slider = !1), m;
|
|
1313
1313
|
}
|
|
1314
|
-
function
|
|
1314
|
+
function Jt(e, t, n, i) {
|
|
1315
1315
|
if (!r(e)) {
|
|
1316
|
-
let r =
|
|
1316
|
+
let r = H(t);
|
|
1317
1317
|
return K(e, r, n, i), r;
|
|
1318
1318
|
}
|
|
1319
1319
|
if (e === "section") {
|
|
1320
|
-
let r =
|
|
1320
|
+
let r = qt(t, n, i);
|
|
1321
1321
|
return K(e, r, n, i), r;
|
|
1322
1322
|
}
|
|
1323
|
-
let a =
|
|
1323
|
+
let a = H(t);
|
|
1324
1324
|
if (e === "heading" && (a.text_content = Z(a.text_content) || Z(a.text) || Z(a.title) || Z(a.heading) || "Untitled", a.level = typeof a.level == "number" ? a.level : 1), e === "text") {
|
|
1325
1325
|
let e = Z(a.html_content) || Z(a.html) || Z(a.content) || Z(a.text);
|
|
1326
|
-
e && (a.html_content = /<\/?[a-z][\s\S]*>/i.test(e) ? e : `<p>${
|
|
1326
|
+
e && (a.html_content = /<\/?[a-z][\s\S]*>/i.test(e) ? e : `<p>${Nt(e)}</p>`);
|
|
1327
1327
|
}
|
|
1328
|
-
return e === "button" && (a.text = Z(a.text) || Z(a.label) || Z(a.title) || "Learn More", a.url = Z(a.url) || Z(a.href) || Z(a.link) || "#"), e === "form" && (a.fields =
|
|
1328
|
+
return e === "button" && (a.text = Z(a.text) || Z(a.label) || Z(a.title) || "Learn More", a.url = Z(a.url) || Z(a.href) || Z(a.link) || "#"), e === "form" && (a.fields = Ft(a.fields), a.submit_button_text = Z(a.submit_button_text ?? a.submitButtonText ?? a.button_text) || "Send Message", a.success_message = Z(a.success_message ?? a.successMessage) || "Thanks for reaching out. We will reply as soon as possible."), K(e, a, n, i), a;
|
|
1329
1329
|
}
|
|
1330
|
-
function
|
|
1331
|
-
let r =
|
|
1330
|
+
function Yt(e, t, n) {
|
|
1331
|
+
let r = G(e.blockType, `Block ${t}`, n);
|
|
1332
1332
|
return {
|
|
1333
1333
|
block_type: r,
|
|
1334
|
-
content:
|
|
1334
|
+
content: Jt(r, V(e.content, `Block ${t}`), `Block ${t}`, n),
|
|
1335
1335
|
order: e.order ?? t
|
|
1336
1336
|
};
|
|
1337
1337
|
}
|
|
1338
|
-
function
|
|
1339
|
-
return [
|
|
1338
|
+
function Xt(e, t = "Contact Us", n) {
|
|
1339
|
+
return [Yt({
|
|
1340
1340
|
blockType: "section",
|
|
1341
1341
|
content: {
|
|
1342
1342
|
is_hero: !0,
|
|
@@ -1348,11 +1348,11 @@ function Yt(e, t = "Contact Us", n) {
|
|
|
1348
1348
|
textAlign: "center",
|
|
1349
1349
|
text_content: t
|
|
1350
1350
|
},
|
|
1351
|
-
temp_id:
|
|
1351
|
+
temp_id: ft("heading")
|
|
1352
1352
|
}, {
|
|
1353
1353
|
block_type: "text",
|
|
1354
1354
|
content: { html_content: "<p>Have a question, project, or support request? Send us a note and we will get back to you soon.</p>" },
|
|
1355
|
-
temp_id:
|
|
1355
|
+
temp_id: ft("text")
|
|
1356
1356
|
}]],
|
|
1357
1357
|
column_gap: "lg",
|
|
1358
1358
|
container_type: "container",
|
|
@@ -1367,7 +1367,7 @@ function Yt(e, t = "Contact Us", n) {
|
|
|
1367
1367
|
},
|
|
1368
1368
|
vertical_alignment: "center"
|
|
1369
1369
|
}
|
|
1370
|
-
}, 0, n),
|
|
1370
|
+
}, 0, n), Yt({
|
|
1371
1371
|
blockType: "form",
|
|
1372
1372
|
content: {
|
|
1373
1373
|
fields: [
|
|
@@ -1398,12 +1398,12 @@ function Yt(e, t = "Contact Us", n) {
|
|
|
1398
1398
|
}
|
|
1399
1399
|
}, 1, n)];
|
|
1400
1400
|
}
|
|
1401
|
-
function
|
|
1402
|
-
return (!e || e.length === 0) && t ?
|
|
1401
|
+
function Zt(e, t, n, r) {
|
|
1402
|
+
return (!e || e.length === 0) && t ? Xt(t, n, r) : (e || []).map((e, t) => Yt(e, t, r));
|
|
1403
1403
|
}
|
|
1404
|
-
async function
|
|
1404
|
+
async function Qt(e) {
|
|
1405
1405
|
let 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);
|
|
1406
|
-
if (r) throw Error(`Failed to check ${e.contentType} slug uniqueness: ${
|
|
1406
|
+
if (r) throw Error(`Failed to check ${e.contentType} slug uniqueness: ${F(r)}`);
|
|
1407
1407
|
let i = Array.isArray(n) ? n : [];
|
|
1408
1408
|
return i.length > 0 ? {
|
|
1409
1409
|
duplicate: !0,
|
|
@@ -1413,10 +1413,10 @@ async function Zt(e) {
|
|
|
1413
1413
|
message: `A ${e.contentType} with slug "${e.slug}" already exists for this language.`
|
|
1414
1414
|
} : null;
|
|
1415
1415
|
}
|
|
1416
|
-
async function
|
|
1416
|
+
async function $t(e) {
|
|
1417
1417
|
if (!e.suppliedTranslationGroupId) return { translationGroupId: void 0 };
|
|
1418
1418
|
let 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);
|
|
1419
|
-
if (r) throw Error(`Failed to inspect ${e.contentType} translation group: ${
|
|
1419
|
+
if (r) throw Error(`Failed to inspect ${e.contentType} translation group: ${F(r)}`);
|
|
1420
1420
|
let i = Array.isArray(n) ? n : [];
|
|
1421
1421
|
if (i.length === 0) return {
|
|
1422
1422
|
result: {
|
|
@@ -1438,7 +1438,7 @@ async function Qt(e) {
|
|
|
1438
1438
|
translationGroupId: e.suppliedTranslationGroupId
|
|
1439
1439
|
} : { translationGroupId: e.suppliedTranslationGroupId };
|
|
1440
1440
|
}
|
|
1441
|
-
async function
|
|
1441
|
+
async function en(e) {
|
|
1442
1442
|
if (e.blocks.length === 0) return [];
|
|
1443
1443
|
let t = e.blocks.map((t, n) => ({
|
|
1444
1444
|
block_type: t.block_type,
|
|
@@ -1449,28 +1449,28 @@ async function $t(e) {
|
|
|
1449
1449
|
post_id: e.contentType === "post" ? e.itemId : null,
|
|
1450
1450
|
product_id: e.contentType === "product" ? e.itemId : null
|
|
1451
1451
|
})), { data: n, error: r } = await e.supabase.from("blocks").insert(t).select("*");
|
|
1452
|
-
if (r) throw Error(`Failed to insert ${e.contentType} blocks: ${
|
|
1453
|
-
return
|
|
1452
|
+
if (r) throw Error(`Failed to insert ${e.contentType} blocks: ${F(r)}`);
|
|
1453
|
+
return Er(e.blocks, e.supabase), Array.isArray(n) ? n : [];
|
|
1454
1454
|
}
|
|
1455
|
-
async function
|
|
1455
|
+
async function tn(e) {
|
|
1456
1456
|
let t = e.contentType === "page" ? "pages" : e.contentType === "post" ? "posts" : "products";
|
|
1457
1457
|
await e.supabase.from(t).delete().eq("id", e.itemId);
|
|
1458
1458
|
}
|
|
1459
|
-
function
|
|
1459
|
+
function nn(e, t) {
|
|
1460
1460
|
return e === "page" ? `/cms/pages/${t}/edit` : e === "post" ? `/cms/posts/${t}/edit` : `/cms/products/${t}/edit`;
|
|
1461
1461
|
}
|
|
1462
|
-
function
|
|
1462
|
+
function rn(e) {
|
|
1463
1463
|
return e === "page" ? "/cms/pages" : e === "post" ? "/cms/posts" : "/cms/products";
|
|
1464
1464
|
}
|
|
1465
|
-
async function
|
|
1466
|
-
let n = w.parse(e), r =
|
|
1467
|
-
n.mode === "replace" && await
|
|
1465
|
+
async function an(e, t) {
|
|
1466
|
+
let n = w.parse(e), r = j(t);
|
|
1467
|
+
n.mode === "replace" && await At({
|
|
1468
1468
|
items: n.items,
|
|
1469
1469
|
languageCode: n.languageCode,
|
|
1470
1470
|
menuKey: "HEADER",
|
|
1471
1471
|
supabase: r
|
|
1472
1472
|
});
|
|
1473
|
-
let i =
|
|
1473
|
+
let i = z({
|
|
1474
1474
|
action: "UPDATE NAVIGATION",
|
|
1475
1475
|
context: t,
|
|
1476
1476
|
payload: {
|
|
@@ -1486,34 +1486,34 @@ async function rn(e, t) {
|
|
|
1486
1486
|
subject: `${n.mode} header`
|
|
1487
1487
|
});
|
|
1488
1488
|
if (i) return i;
|
|
1489
|
-
let a = n.mode === "update" ? await
|
|
1489
|
+
let a = n.mode === "update" ? await jt({
|
|
1490
1490
|
items: n.items,
|
|
1491
1491
|
languageCode: n.languageCode,
|
|
1492
1492
|
match: n.match,
|
|
1493
1493
|
menuKey: "HEADER",
|
|
1494
1494
|
supabase: r
|
|
1495
|
-
}) : n.mode === "append" ? await
|
|
1495
|
+
}) : n.mode === "append" ? await Mt({
|
|
1496
1496
|
items: n.items,
|
|
1497
1497
|
languageCode: n.languageCode,
|
|
1498
1498
|
menuKey: "HEADER",
|
|
1499
1499
|
supabase: r
|
|
1500
|
-
}) : await
|
|
1500
|
+
}) : await Ot({
|
|
1501
1501
|
items: n.items,
|
|
1502
1502
|
languageCode: n.languageCode,
|
|
1503
1503
|
menuKey: "HEADER",
|
|
1504
1504
|
supabase: r
|
|
1505
1505
|
});
|
|
1506
|
-
return
|
|
1506
|
+
return We(t), {
|
|
1507
1507
|
...a,
|
|
1508
1508
|
mutationExecuted: !0,
|
|
1509
1509
|
mode: n.mode,
|
|
1510
1510
|
success: !0
|
|
1511
1511
|
};
|
|
1512
1512
|
}
|
|
1513
|
-
async function
|
|
1514
|
-
let n =
|
|
1513
|
+
async function on(e, t) {
|
|
1514
|
+
let n = te.parse(e);
|
|
1515
1515
|
if (!n.links?.length && !n.copyright) throw Error("update_footer requires links or copyright.");
|
|
1516
|
-
let r =
|
|
1516
|
+
let r = j(t), i = z({
|
|
1517
1517
|
action: "UPDATE FOOTER",
|
|
1518
1518
|
context: t,
|
|
1519
1519
|
payload: {
|
|
@@ -1530,7 +1530,7 @@ async function an(e, t) {
|
|
|
1530
1530
|
});
|
|
1531
1531
|
if (i) return i;
|
|
1532
1532
|
let a = null;
|
|
1533
|
-
if (n.links?.length && (a = await
|
|
1533
|
+
if (n.links?.length && (a = await Ot({
|
|
1534
1534
|
items: n.links,
|
|
1535
1535
|
languageCode: n.languageCode,
|
|
1536
1536
|
menuKey: "FOOTER",
|
|
@@ -1540,31 +1540,31 @@ async function an(e, t) {
|
|
|
1540
1540
|
key: "footer_copyright",
|
|
1541
1541
|
value: n.copyright
|
|
1542
1542
|
});
|
|
1543
|
-
if (e) throw Error(`Failed to update footer copyright: ${
|
|
1543
|
+
if (e) throw Error(`Failed to update footer copyright: ${F(e)}`);
|
|
1544
1544
|
}
|
|
1545
|
-
return
|
|
1545
|
+
return We(t), {
|
|
1546
1546
|
copyrightUpdated: !!n.copyright,
|
|
1547
1547
|
footerNavigation: a,
|
|
1548
1548
|
mutationExecuted: !0,
|
|
1549
1549
|
success: !0
|
|
1550
1550
|
};
|
|
1551
1551
|
}
|
|
1552
|
-
function
|
|
1552
|
+
function sn(e) {
|
|
1553
1553
|
return typeof e == "string" ? e.toLowerCase() : "";
|
|
1554
1554
|
}
|
|
1555
|
-
function
|
|
1556
|
-
let n = t.map(
|
|
1555
|
+
function cn(e, t) {
|
|
1556
|
+
let n = t.map(sn).join(" ");
|
|
1557
1557
|
return e.reduce((e, t) => e + +!!n.includes(t), 0);
|
|
1558
1558
|
}
|
|
1559
|
-
function
|
|
1560
|
-
return (e.find((e) => t.some((t) =>
|
|
1559
|
+
function ln(e, t) {
|
|
1560
|
+
return (e.find((e) => t.some((t) => sn(e).includes(t))) || e.find((e) => e.trim().length > 0) || "No excerpt available.").slice(0, 500);
|
|
1561
1561
|
}
|
|
1562
|
-
async function
|
|
1563
|
-
let n =
|
|
1564
|
-
if (a.error) throw Error(`Failed to search documentation posts: ${
|
|
1565
|
-
if (o.error) throw Error(`Failed to search documentation pages: ${
|
|
1562
|
+
async function un(e, t) {
|
|
1563
|
+
let n = ne.parse(e), r = j(t), i = n.query.toLowerCase().split(/\s+/).map((e) => e.trim()).filter(Boolean), [a, o] = await Promise.all([r.from("posts").select("id, title, slug, excerpt, subtitle, meta_description, status, updated_at").eq("status", "published").limit(100), r.from("pages").select("id, title, slug, meta_description, status, updated_at").eq("status", "published").limit(100)]);
|
|
1564
|
+
if (a.error) throw Error(`Failed to search documentation posts: ${F(a.error)}`);
|
|
1565
|
+
if (o.error) throw Error(`Failed to search documentation pages: ${F(o.error)}`);
|
|
1566
1566
|
let s = (a.data ?? []).map((e) => ({
|
|
1567
|
-
excerpt:
|
|
1567
|
+
excerpt: ln([
|
|
1568
1568
|
e.excerpt,
|
|
1569
1569
|
e.subtitle,
|
|
1570
1570
|
e.meta_description,
|
|
@@ -1574,13 +1574,13 @@ async function ln(e, t) {
|
|
|
1574
1574
|
title: e.title,
|
|
1575
1575
|
url: `/article/${e.slug}`
|
|
1576
1576
|
})), c = (o.data ?? []).map((e) => ({
|
|
1577
|
-
excerpt:
|
|
1577
|
+
excerpt: ln([e.meta_description, e.slug].filter(Boolean), i),
|
|
1578
1578
|
source: "page",
|
|
1579
1579
|
title: e.title,
|
|
1580
1580
|
url: e.slug === "home" ? "/" : `/${e.slug}`
|
|
1581
1581
|
})), l = [...s, ...c].map((e) => ({
|
|
1582
1582
|
...e,
|
|
1583
|
-
score:
|
|
1583
|
+
score: cn(i, [
|
|
1584
1584
|
e.title,
|
|
1585
1585
|
e.excerpt,
|
|
1586
1586
|
e.url
|
|
@@ -1597,9 +1597,9 @@ async function ln(e, t) {
|
|
|
1597
1597
|
success: !0
|
|
1598
1598
|
};
|
|
1599
1599
|
}
|
|
1600
|
-
async function
|
|
1601
|
-
let r =
|
|
1602
|
-
return
|
|
1600
|
+
async function dn(e, t, n = y) {
|
|
1601
|
+
let r = ne.safeParse(e), i = r.success ? r.data.query : "";
|
|
1602
|
+
return Me(un(e, t), n, () => ({
|
|
1603
1603
|
message: "Documentation search took too long to respond. Please try again or ask a more specific question.",
|
|
1604
1604
|
query: i,
|
|
1605
1605
|
results: [],
|
|
@@ -1607,7 +1607,7 @@ async function un(e, t, n = v) {
|
|
|
1607
1607
|
timedOut: !0
|
|
1608
1608
|
}));
|
|
1609
1609
|
}
|
|
1610
|
-
var
|
|
1610
|
+
var fn = [
|
|
1611
1611
|
"pending",
|
|
1612
1612
|
"trial",
|
|
1613
1613
|
"paid",
|
|
@@ -1615,7 +1615,7 @@ var dn = [
|
|
|
1615
1615
|
"cancelled",
|
|
1616
1616
|
"refunded",
|
|
1617
1617
|
"failed"
|
|
1618
|
-
],
|
|
1618
|
+
], pn = {
|
|
1619
1619
|
awaiting: "pending",
|
|
1620
1620
|
canceled: "cancelled",
|
|
1621
1621
|
cancelled: "cancelled",
|
|
@@ -1632,31 +1632,31 @@ var dn = [
|
|
|
1632
1632
|
trial: "trial",
|
|
1633
1633
|
trials: "trial"
|
|
1634
1634
|
};
|
|
1635
|
-
function
|
|
1635
|
+
function mn(e) {
|
|
1636
1636
|
return String(e ?? "unknown").trim().toLowerCase() || "unknown";
|
|
1637
1637
|
}
|
|
1638
|
-
function
|
|
1639
|
-
let t = Object.fromEntries(
|
|
1638
|
+
function hn(e) {
|
|
1639
|
+
let t = Object.fromEntries(fn.map((e) => [e, 0]));
|
|
1640
1640
|
for (let n of e) {
|
|
1641
|
-
let e =
|
|
1641
|
+
let e = mn(n.status);
|
|
1642
1642
|
t[e] = (t[e] ?? 0) + 1;
|
|
1643
1643
|
}
|
|
1644
1644
|
return t;
|
|
1645
1645
|
}
|
|
1646
|
-
function
|
|
1646
|
+
function gn(e) {
|
|
1647
1647
|
let t = e.toLowerCase().replace(/[^a-z0-9_]+/g, " ").split(/\s+/).filter(Boolean);
|
|
1648
1648
|
for (let e of t) {
|
|
1649
|
-
let t =
|
|
1649
|
+
let t = pn[e];
|
|
1650
1650
|
if (t) return t;
|
|
1651
1651
|
}
|
|
1652
1652
|
return null;
|
|
1653
1653
|
}
|
|
1654
|
-
function
|
|
1654
|
+
function _n(e) {
|
|
1655
1655
|
let t = Number(e);
|
|
1656
1656
|
return Number.isFinite(t) ? t : 0;
|
|
1657
1657
|
}
|
|
1658
|
-
async function
|
|
1659
|
-
let n =
|
|
1658
|
+
async function vn(e, t) {
|
|
1659
|
+
let n = re.parse(e), r = j(t), i = /* @__PURE__ */ new Date(), a = null, o = null;
|
|
1660
1660
|
switch (n.timeRange) {
|
|
1661
1661
|
case "today":
|
|
1662
1662
|
a = new Date(i.getFullYear(), i.getMonth(), i.getDate());
|
|
@@ -1678,7 +1678,7 @@ async function _n(e, t) {
|
|
|
1678
1678
|
break;
|
|
1679
1679
|
case "all_time": a = null;
|
|
1680
1680
|
}
|
|
1681
|
-
let s = n.currency?.toUpperCase(), c =
|
|
1681
|
+
let s = n.currency?.toUpperCase(), c = gn(n.query), l = r.from("orders").select("id, status, total, currency, created_at, paid_at");
|
|
1682
1682
|
s && l.eq("currency", s), a && l.gte("created_at", a.toISOString()), o && l.lte("created_at", o.toISOString());
|
|
1683
1683
|
let u = n.reportType === "products" || n.reportType === "revenue" || n.reportType === "general" ? r.from("order_items").select("\n quantity,\n price_at_purchase,\n products!inner (\n id,\n title,\n product_type\n ),\n orders!inner (\n id,\n status,\n paid_at,\n currency\n )\n ").eq("orders.status", "paid") : null;
|
|
1684
1684
|
u && (s && u.eq("orders.currency", s), a && u.gte("orders.paid_at", a.toISOString()), o && u.lte("orders.paid_at", o.toISOString()));
|
|
@@ -1695,13 +1695,13 @@ async function _n(e, t) {
|
|
|
1695
1695
|
error: null
|
|
1696
1696
|
})
|
|
1697
1697
|
]);
|
|
1698
|
-
if (p) throw Error(`Failed to fetch ecommerce stats: ${
|
|
1699
|
-
if (h) throw Error(`Failed to fetch ecommerce stats: ${
|
|
1700
|
-
if (g.error) throw Error(`Failed to fetch ecommerce stats: ${
|
|
1701
|
-
let _ = Array.isArray(f) ? f : [], v = Array.isArray(m) ? m : [], y =
|
|
1698
|
+
if (p) throw Error(`Failed to fetch ecommerce stats: ${F(p)}`);
|
|
1699
|
+
if (h) throw Error(`Failed to fetch ecommerce stats: ${F(h)}`);
|
|
1700
|
+
if (g.error) throw Error(`Failed to fetch ecommerce stats: ${F(g.error)}`);
|
|
1701
|
+
let _ = Array.isArray(f) ? f : [], v = Array.isArray(m) ? m : [], y = hn(_), b = Array.isArray(g.data) ? g.data : null, x = b ? hn(b) : null, S = {};
|
|
1702
1702
|
for (let e of v) {
|
|
1703
1703
|
let t = Array.isArray(e.orders) ? e.orders[0] : e.orders, n = String(t?.currency || s || "unknown").toUpperCase();
|
|
1704
|
-
S[n] = (S[n] ?? 0) +
|
|
1704
|
+
S[n] = (S[n] ?? 0) + _n(e.quantity) * _n(e.price_at_purchase) / 100;
|
|
1705
1705
|
}
|
|
1706
1706
|
let C = {
|
|
1707
1707
|
currency: s ?? null,
|
|
@@ -1732,7 +1732,7 @@ async function _n(e, t) {
|
|
|
1732
1732
|
revenue: 0,
|
|
1733
1733
|
title: n.title,
|
|
1734
1734
|
type: n.product_type
|
|
1735
|
-
}), e[r].quantity +=
|
|
1735
|
+
}), e[r].quantity += _n(t.quantity), e[r].revenue += _n(t.quantity) * _n(t.price_at_purchase) / 100;
|
|
1736
1736
|
}
|
|
1737
1737
|
C.topProducts = Object.values(e).sort((e, t) => t.revenue - e.revenue).slice(0, 10);
|
|
1738
1738
|
}
|
|
@@ -1741,14 +1741,14 @@ async function _n(e, t) {
|
|
|
1741
1741
|
success: !0
|
|
1742
1742
|
};
|
|
1743
1743
|
}
|
|
1744
|
-
async function
|
|
1745
|
-
let n = oe.parse(e), r =
|
|
1746
|
-
if (c || !s) throw Error(`Failed to read current ${i.contentType}: ${
|
|
1744
|
+
async function yn(e, t) {
|
|
1745
|
+
let n = oe.parse(e), r = j(t), i = await X(n.cmsTarget, t), a = M(i), o = i.contentType === "page" ? "pages" : i.contentType === "post" ? "posts" : "products", { data: s, error: c } = await r.from(o).select("*").eq("id", a).single();
|
|
1746
|
+
if (c || !s) throw Error(`Failed to read current ${i.contentType}: ${F(c)}`);
|
|
1747
1747
|
let l = [];
|
|
1748
1748
|
if (n.includeBlocks) {
|
|
1749
1749
|
let e = i.contentType === "page" ? "page_id" : i.contentType === "post" ? "post_id" : "product_id", { data: t, error: o } = await r.from("blocks").select("id, page_id, post_id, product_id, language_id, block_type, content, order").eq(e, a);
|
|
1750
|
-
if (o) throw Error(`Failed to read current ${i.contentType} blocks: ${
|
|
1751
|
-
l = (Array.isArray(t) ? t : []).slice().sort((e, t) => Number(e.order) - Number(t.order)).map((e) =>
|
|
1750
|
+
if (o) throw Error(`Failed to read current ${i.contentType} blocks: ${F(o)}`);
|
|
1751
|
+
l = (Array.isArray(t) ? t : []).slice().sort((e, t) => Number(e.order) - Number(t.order)).map((e) => vt(e, n.includeBlockContent));
|
|
1752
1752
|
}
|
|
1753
1753
|
return {
|
|
1754
1754
|
blocks: l,
|
|
@@ -1757,7 +1757,7 @@ async function vn(e, t) {
|
|
|
1757
1757
|
success: !0
|
|
1758
1758
|
};
|
|
1759
1759
|
}
|
|
1760
|
-
var
|
|
1760
|
+
var bn = /* @__PURE__ */ new Set([
|
|
1761
1761
|
"feature_image_id",
|
|
1762
1762
|
"language_id",
|
|
1763
1763
|
"meta_description",
|
|
@@ -1765,7 +1765,7 @@ var yn = /* @__PURE__ */ new Set([
|
|
|
1765
1765
|
"slug",
|
|
1766
1766
|
"status",
|
|
1767
1767
|
"title"
|
|
1768
|
-
]),
|
|
1768
|
+
]), xn = /* @__PURE__ */ new Set([
|
|
1769
1769
|
"excerpt",
|
|
1770
1770
|
"feature_image_id",
|
|
1771
1771
|
"label",
|
|
@@ -1777,7 +1777,7 @@ var yn = /* @__PURE__ */ new Set([
|
|
|
1777
1777
|
"status",
|
|
1778
1778
|
"subtitle",
|
|
1779
1779
|
"title"
|
|
1780
|
-
]),
|
|
1780
|
+
]), Sn = /* @__PURE__ */ new Set([
|
|
1781
1781
|
"description_json",
|
|
1782
1782
|
"language_id",
|
|
1783
1783
|
"meta_description",
|
|
@@ -1786,7 +1786,7 @@ var yn = /* @__PURE__ */ new Set([
|
|
|
1786
1786
|
"slug",
|
|
1787
1787
|
"status",
|
|
1788
1788
|
"title"
|
|
1789
|
-
]),
|
|
1789
|
+
]), Cn = /* @__PURE__ */ new Set([
|
|
1790
1790
|
"excerpt",
|
|
1791
1791
|
"feature_image_id",
|
|
1792
1792
|
"label",
|
|
@@ -1796,13 +1796,13 @@ var yn = /* @__PURE__ */ new Set([
|
|
|
1796
1796
|
"short_description",
|
|
1797
1797
|
"subtitle"
|
|
1798
1798
|
]);
|
|
1799
|
-
function
|
|
1800
|
-
return e === "page" ?
|
|
1801
|
-
}
|
|
1802
|
-
function wn(e, t) {
|
|
1803
|
-
return Sn.has(e) && t === "" ? null : t;
|
|
1799
|
+
function wn(e) {
|
|
1800
|
+
return e === "page" ? bn : e === "post" ? xn : Sn;
|
|
1804
1801
|
}
|
|
1805
1802
|
function Tn(e, t) {
|
|
1803
|
+
return Cn.has(e) && t === "" ? null : t;
|
|
1804
|
+
}
|
|
1805
|
+
function En(e, t) {
|
|
1806
1806
|
if (typeof t != "string") return;
|
|
1807
1807
|
let n = e === "product" ? [
|
|
1808
1808
|
"active",
|
|
@@ -1815,18 +1815,18 @@ function Tn(e, t) {
|
|
|
1815
1815
|
];
|
|
1816
1816
|
if (!n.includes(t)) throw Error(`Status "${t}" is not valid for ${e}. Allowed statuses: ${n.join(", ")}.`);
|
|
1817
1817
|
}
|
|
1818
|
-
function
|
|
1819
|
-
let n =
|
|
1818
|
+
function Dn(e, t) {
|
|
1819
|
+
let n = wn(t.contentType), r = {};
|
|
1820
1820
|
for (let [i, a] of Object.entries(e)) if (a !== void 0) {
|
|
1821
1821
|
if (!n.has(i)) throw Error(`Field "${i}" cannot be updated for ${t.contentType} content.`);
|
|
1822
|
-
i === "status" &&
|
|
1822
|
+
i === "status" && En(t.contentType, a), r[i] = Tn(i, a);
|
|
1823
1823
|
}
|
|
1824
1824
|
return r;
|
|
1825
1825
|
}
|
|
1826
|
-
async function
|
|
1827
|
-
let n =
|
|
1826
|
+
async function On(e, t) {
|
|
1827
|
+
let n = D.parse(e), r = j(t), i = await X(n.cmsTarget, t), a = M(i), o = Dn(n.fields, i), s = Object.keys(o);
|
|
1828
1828
|
if (s.length === 0) throw Error("update_current_cms_fields requires at least one supported field.");
|
|
1829
|
-
let c =
|
|
1829
|
+
let c = z({
|
|
1830
1830
|
action: "UPDATE CMS FIELDS",
|
|
1831
1831
|
context: t,
|
|
1832
1832
|
payload: {
|
|
@@ -1845,14 +1845,14 @@ async function Dn(e, t) {
|
|
|
1845
1845
|
subject: `${i.contentType} ${String(a)}`
|
|
1846
1846
|
});
|
|
1847
1847
|
if (c) return c;
|
|
1848
|
-
let l = await
|
|
1849
|
-
typeof o.feature_image_id == "string" && (o.feature_image_id = await
|
|
1848
|
+
let l = await _(t, i.contentType, a);
|
|
1849
|
+
typeof o.feature_image_id == "string" && (o.feature_image_id = await N(o.feature_image_id, t, typeof i.title == "string" ? i.title : void 0));
|
|
1850
1850
|
let u = i.contentType === "page" ? "pages" : i.contentType === "post" ? "posts" : "products", { data: d, error: f } = await r.from(u).update({
|
|
1851
1851
|
...o,
|
|
1852
1852
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1853
1853
|
}).eq("id", a).select("id, language_id, slug, status, title").single();
|
|
1854
|
-
if (f || !d) throw Error(`Failed to update current ${i.contentType}: ${
|
|
1855
|
-
return await
|
|
1854
|
+
if (f || !d) throw Error(`Failed to update current ${i.contentType}: ${F(f)}`);
|
|
1855
|
+
return await v(t, i.contentType, a, l), P(t, i, d.slug), {
|
|
1856
1856
|
contentType: i.contentType,
|
|
1857
1857
|
entityId: a,
|
|
1858
1858
|
mutationExecuted: !0,
|
|
@@ -1861,19 +1861,19 @@ async function Dn(e, t) {
|
|
|
1861
1861
|
updatedFields: s
|
|
1862
1862
|
};
|
|
1863
1863
|
}
|
|
1864
|
-
async function
|
|
1865
|
-
let n =
|
|
1866
|
-
if (o || !a) throw Error(`Failed to read block ${n.blockId}: ${
|
|
1867
|
-
|
|
1864
|
+
async function kn(e, t) {
|
|
1865
|
+
let n = O.parse(e), r = j(t), i = await X(n.cmsTarget, t), { data: a, error: o } = await r.from("blocks").select("id, page_id, post_id, product_id, language_id, block_type, content, order").eq("id", n.blockId).single();
|
|
1866
|
+
if (o || !a) throw Error(`Failed to read block ${n.blockId}: ${F(o)}`);
|
|
1867
|
+
ot(a, i), t = await W(t, [
|
|
1868
1868
|
a.block_type,
|
|
1869
1869
|
a.content,
|
|
1870
1870
|
n.content
|
|
1871
1871
|
]);
|
|
1872
|
-
let s =
|
|
1873
|
-
|
|
1874
|
-
let c =
|
|
1872
|
+
let s = G(a.block_type, `Block ${n.blockId}`, t);
|
|
1873
|
+
lt(n.blockType, s, `Block ${n.blockId}`);
|
|
1874
|
+
let c = _t(s, V(a.content, `Block ${n.blockId}`), n.content, t);
|
|
1875
1875
|
K(s, c, `Block ${n.blockId}`, t);
|
|
1876
|
-
let l =
|
|
1876
|
+
let l = z({
|
|
1877
1877
|
action: "UPDATE CONTENT BLOCK",
|
|
1878
1878
|
context: t,
|
|
1879
1879
|
payload: {
|
|
@@ -1886,24 +1886,24 @@ async function On(e, t) {
|
|
|
1886
1886
|
blockId: n.blockId,
|
|
1887
1887
|
blockType: s,
|
|
1888
1888
|
contentType: i.contentType,
|
|
1889
|
-
entityId:
|
|
1889
|
+
entityId: M(i)
|
|
1890
1890
|
},
|
|
1891
1891
|
subject: `${s} block ${n.blockId}`
|
|
1892
1892
|
});
|
|
1893
1893
|
if (l) return l;
|
|
1894
|
-
let u = await
|
|
1894
|
+
let u = await _(t, i.contentType, M(i)), { data: d, error: f } = await r.from("blocks").update({
|
|
1895
1895
|
content: c,
|
|
1896
1896
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1897
1897
|
}).eq("id", n.blockId).select("id, block_type, order").single();
|
|
1898
|
-
if (f || !d) throw Error(`Failed to update block ${n.blockId}: ${
|
|
1899
|
-
return await
|
|
1898
|
+
if (f || !d) throw Error(`Failed to update block ${n.blockId}: ${F(f)}`);
|
|
1899
|
+
return await v(t, i.contentType, M(i), u), await Be({
|
|
1900
1900
|
patch: ({ blocks: e }) => ({ blocks: e.map((e) => String(e?.id) === String(n.blockId) ? {
|
|
1901
1901
|
...e,
|
|
1902
1902
|
content: c
|
|
1903
1903
|
} : e) }),
|
|
1904
1904
|
productId: a.product_id,
|
|
1905
1905
|
supabase: r
|
|
1906
|
-
}),
|
|
1906
|
+
}), Er([{ content: c }], r), P(t, i), {
|
|
1907
1907
|
blockId: d.id,
|
|
1908
1908
|
blockType: d.block_type,
|
|
1909
1909
|
contentUpdated: !0,
|
|
@@ -1911,12 +1911,12 @@ async function On(e, t) {
|
|
|
1911
1911
|
success: !0
|
|
1912
1912
|
};
|
|
1913
1913
|
}
|
|
1914
|
-
async function
|
|
1915
|
-
let n =
|
|
1916
|
-
t = await
|
|
1917
|
-
let r =
|
|
1914
|
+
async function An(e, t) {
|
|
1915
|
+
let n = de.parse(e);
|
|
1916
|
+
t = await W(t, n.block);
|
|
1917
|
+
let r = j(t), i = await Y(n, t), a = i.contentType === "product" ? i.item.id : Number(i.item.id), o = i.contentType === "page" ? "page_id" : i.contentType === "post" ? "post_id" : "product_id", s = async () => {
|
|
1918
1918
|
let { data: e, error: t } = await r.from("blocks").select("id, page_id, post_id, product_id, language_id, block_type, content, order").eq(o, a);
|
|
1919
|
-
if (t) throw Error(`Failed to read ${i.contentType} blocks: ${
|
|
1919
|
+
if (t) throw Error(`Failed to read ${i.contentType} blocks: ${F(t)}`);
|
|
1920
1920
|
return (Array.isArray(e) ? e : []).sort((e, t) => Number(e.order) - Number(t.order));
|
|
1921
1921
|
}, c = (e) => {
|
|
1922
1922
|
if (n.position === "start") return 0;
|
|
@@ -1928,14 +1928,14 @@ async function kn(e, t) {
|
|
|
1928
1928
|
if (!t) throw Error(n.anchorBlockType ? `Could not find a ${n.anchorBlockType} block to insert ${n.position}.` : `Could not find block ${n.anchorBlockId} to insert ${n.position}.`);
|
|
1929
1929
|
let r = Number(t.order);
|
|
1930
1930
|
return n.position === "before" ? r : r + 1;
|
|
1931
|
-
}, l =
|
|
1931
|
+
}, l = Yt(n.block, 0, t), u = c(await s()), d = {
|
|
1932
1932
|
contentType: i.contentType,
|
|
1933
1933
|
entityId: i.item.id,
|
|
1934
1934
|
languageId: i.item.language_id,
|
|
1935
1935
|
slug: i.item.slug,
|
|
1936
1936
|
title: i.item.title,
|
|
1937
1937
|
translationGroupId: i.item.translation_group_id
|
|
1938
|
-
}, f =
|
|
1938
|
+
}, f = z({
|
|
1939
1939
|
action: "INSERT CONTENT BLOCK",
|
|
1940
1940
|
context: t,
|
|
1941
1941
|
payload: {
|
|
@@ -1962,13 +1962,13 @@ async function kn(e, t) {
|
|
|
1962
1962
|
subject: `${l.block_type} block on ${i.contentType} ${i.item.id}`
|
|
1963
1963
|
});
|
|
1964
1964
|
if (f) return f;
|
|
1965
|
-
let p = await s(), m = c(p), h = p.filter((e) => Number(e.order) >= m).sort((e, t) => Number(t.order) - Number(e.order)),
|
|
1965
|
+
let p = await s(), m = c(p), h = p.filter((e) => Number(e.order) >= m).sort((e, t) => Number(t.order) - Number(e.order)), g = await _(t, i.contentType, a);
|
|
1966
1966
|
for (let e of h) {
|
|
1967
1967
|
let { error: t } = await r.from("blocks").update({
|
|
1968
1968
|
order: Number(e.order) + 1,
|
|
1969
1969
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1970
1970
|
}).eq("id", e.id);
|
|
1971
|
-
if (t) throw Error(`Failed to shift block ${e.id}: ${
|
|
1971
|
+
if (t) throw Error(`Failed to shift block ${e.id}: ${F(t)}`);
|
|
1972
1972
|
}
|
|
1973
1973
|
let { data: y, error: b } = await r.from("blocks").insert({
|
|
1974
1974
|
block_type: l.block_type,
|
|
@@ -1979,8 +1979,8 @@ async function kn(e, t) {
|
|
|
1979
1979
|
post_id: i.contentType === "post" ? a : null,
|
|
1980
1980
|
product_id: i.contentType === "product" ? a : null
|
|
1981
1981
|
}).select("id, block_type, order").single();
|
|
1982
|
-
if (b || !y) throw Error(`Failed to insert content block: ${
|
|
1983
|
-
return i.contentType === "product" && await
|
|
1982
|
+
if (b || !y) throw Error(`Failed to insert content block: ${F(b)}`);
|
|
1983
|
+
return i.contentType === "product" && await Be({
|
|
1984
1984
|
patch: ({ blocks: e }) => ({ blocks: [...e.map((e) => Number(e?.order) >= m ? {
|
|
1985
1985
|
...e,
|
|
1986
1986
|
order: Number(e.order) + 1
|
|
@@ -1996,7 +1996,7 @@ async function kn(e, t) {
|
|
|
1996
1996
|
}].sort((e, t) => Number(e.order) - Number(t.order)) }),
|
|
1997
1997
|
productId: a,
|
|
1998
1998
|
supabase: r
|
|
1999
|
-
}), await
|
|
1999
|
+
}), await v(t, i.contentType, a, g), Er([l], r), P(t, d), {
|
|
2000
2000
|
blockId: y.id,
|
|
2001
2001
|
blockType: y.block_type,
|
|
2002
2002
|
contentType: i.contentType,
|
|
@@ -2006,22 +2006,22 @@ async function kn(e, t) {
|
|
|
2006
2006
|
success: !0
|
|
2007
2007
|
};
|
|
2008
2008
|
}
|
|
2009
|
-
async function
|
|
2010
|
-
let n =
|
|
2011
|
-
if (o || !a) throw Error(`Failed to read parent block ${n.parentBlockId}: ${
|
|
2012
|
-
|
|
2009
|
+
async function jn(e, t) {
|
|
2010
|
+
let n = k.parse(e), r = j(t), i = await X(n.cmsTarget, t), { data: a, error: o } = await r.from("blocks").select("id, page_id, post_id, product_id, language_id, block_type, content, order").eq("id", n.parentBlockId).single();
|
|
2011
|
+
if (o || !a) throw Error(`Failed to read parent block ${n.parentBlockId}: ${F(o)}`);
|
|
2012
|
+
ot(a, i), t = await W(t, [
|
|
2013
2013
|
a.block_type,
|
|
2014
2014
|
a.content,
|
|
2015
2015
|
n.content
|
|
2016
2016
|
]);
|
|
2017
|
-
let s =
|
|
2017
|
+
let s = G(a.block_type, `Parent block ${n.parentBlockId}`, t);
|
|
2018
2018
|
if (s !== "section") throw Error(`Parent block ${n.parentBlockId} must be a section block, not "${s}".`);
|
|
2019
|
-
let c =
|
|
2019
|
+
let c = V(a.content, `Parent block ${n.parentBlockId}`);
|
|
2020
2020
|
K(s, c, `Parent block ${n.parentBlockId}`, t);
|
|
2021
2021
|
let l = c.column_blocks?.[n.columnIndex]?.[n.blockIndex];
|
|
2022
2022
|
if (!l) throw Error(`Nested block was not found at column ${n.columnIndex}, index ${n.blockIndex}.`);
|
|
2023
|
-
let u =
|
|
2024
|
-
|
|
2023
|
+
let u = G(l.block_type, `Nested block ${n.columnIndex}:${n.blockIndex}`, t);
|
|
2024
|
+
lt(n.blockType, u, `Nested block ${n.columnIndex}:${n.blockIndex}`), K(u, n.content, `Nested block ${n.columnIndex}:${n.blockIndex}`, t);
|
|
2025
2025
|
let d = c.column_blocks.map((e, t) => t === n.columnIndex ? e.map((e, t) => t === n.blockIndex ? {
|
|
2026
2026
|
...e,
|
|
2027
2027
|
content: n.content
|
|
@@ -2030,7 +2030,7 @@ async function An(e, t) {
|
|
|
2030
2030
|
column_blocks: d
|
|
2031
2031
|
};
|
|
2032
2032
|
K(s, f, `Updated parent block ${n.parentBlockId}`, t);
|
|
2033
|
-
let p =
|
|
2033
|
+
let p = z({
|
|
2034
2034
|
action: "UPDATE NESTED BLOCK",
|
|
2035
2035
|
context: t,
|
|
2036
2036
|
payload: {
|
|
@@ -2051,19 +2051,19 @@ async function An(e, t) {
|
|
|
2051
2051
|
subject: `${u} nested block ${n.columnIndex}:${n.blockIndex}`
|
|
2052
2052
|
});
|
|
2053
2053
|
if (p) return p;
|
|
2054
|
-
let m = await
|
|
2054
|
+
let m = await _(t, i.contentType, M(i)), { data: h, error: g } = await r.from("blocks").update({
|
|
2055
2055
|
content: f,
|
|
2056
2056
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
2057
2057
|
}).eq("id", n.parentBlockId).select("id, block_type").single();
|
|
2058
|
-
if (
|
|
2059
|
-
return await
|
|
2058
|
+
if (g || !h) throw Error(`Failed to update parent block ${n.parentBlockId}: ${F(g)}`);
|
|
2059
|
+
return await Be({
|
|
2060
2060
|
patch: ({ blocks: e }) => ({ blocks: e.map((e) => String(e?.id) === String(n.parentBlockId) ? {
|
|
2061
2061
|
...e,
|
|
2062
2062
|
content: f
|
|
2063
2063
|
} : e) }),
|
|
2064
2064
|
productId: a.product_id,
|
|
2065
2065
|
supabase: r
|
|
2066
|
-
}), await
|
|
2066
|
+
}), await v(t, i.contentType, M(i), m), P(t, i), {
|
|
2067
2067
|
blockIndex: n.blockIndex,
|
|
2068
2068
|
columnIndex: n.columnIndex,
|
|
2069
2069
|
mutationExecuted: !0,
|
|
@@ -2073,17 +2073,17 @@ async function An(e, t) {
|
|
|
2073
2073
|
success: !0
|
|
2074
2074
|
};
|
|
2075
2075
|
}
|
|
2076
|
-
async function
|
|
2077
|
-
let n =
|
|
2078
|
-
t = await
|
|
2079
|
-
let r =
|
|
2076
|
+
async function Mn(e, t) {
|
|
2077
|
+
let n = fe.parse(e);
|
|
2078
|
+
t = await W(t, n.blocks);
|
|
2079
|
+
let r = j(t), i = Qe(t), a = await St(r, n.languageCode), o = B(n.slug || n.title), s = Zt(n.blocks, n.contactEmail, n.title, t), c = await Qt({
|
|
2080
2080
|
contentType: "page",
|
|
2081
2081
|
languageId: a.id,
|
|
2082
2082
|
slug: o,
|
|
2083
2083
|
supabase: r
|
|
2084
2084
|
});
|
|
2085
2085
|
if (c) return c;
|
|
2086
|
-
let l = await
|
|
2086
|
+
let l = await $t({
|
|
2087
2087
|
contentType: "page",
|
|
2088
2088
|
languageCode: a.code,
|
|
2089
2089
|
languageId: a.id,
|
|
@@ -2104,7 +2104,7 @@ async function jn(e, t) {
|
|
|
2104
2104
|
translation_group_id: l.translationGroupId
|
|
2105
2105
|
},
|
|
2106
2106
|
tool: "create_cms_page"
|
|
2107
|
-
}, d =
|
|
2107
|
+
}, d = z({
|
|
2108
2108
|
action: "CREATE PAGE",
|
|
2109
2109
|
context: t,
|
|
2110
2110
|
payload: u,
|
|
@@ -2119,15 +2119,15 @@ async function jn(e, t) {
|
|
|
2119
2119
|
subject: o
|
|
2120
2120
|
});
|
|
2121
2121
|
if (d) return d;
|
|
2122
|
-
let f = l.translationGroupId ||
|
|
2122
|
+
let f = l.translationGroupId || $e(), p = await N(u.item.feature_image_id, t, n.title), { data: m, error: h } = await r.from("pages").insert({
|
|
2123
2123
|
...u.item,
|
|
2124
2124
|
author_id: i,
|
|
2125
2125
|
feature_image_id: p,
|
|
2126
2126
|
translation_group_id: f
|
|
2127
2127
|
}).select("id, language_id, slug, status, title, translation_group_id").single();
|
|
2128
|
-
if (h || !m?.id) throw Error(`Failed to create page: ${
|
|
2128
|
+
if (h || !m?.id) throw Error(`Failed to create page: ${F(h)}`);
|
|
2129
2129
|
try {
|
|
2130
|
-
await
|
|
2130
|
+
await en({
|
|
2131
2131
|
blocks: s,
|
|
2132
2132
|
contentType: "page",
|
|
2133
2133
|
itemId: Number(m.id),
|
|
@@ -2135,13 +2135,13 @@ async function jn(e, t) {
|
|
|
2135
2135
|
supabase: r
|
|
2136
2136
|
});
|
|
2137
2137
|
} catch (e) {
|
|
2138
|
-
throw await
|
|
2138
|
+
throw await tn({
|
|
2139
2139
|
contentType: "page",
|
|
2140
2140
|
itemId: Number(m.id),
|
|
2141
2141
|
supabase: r
|
|
2142
2142
|
}), e;
|
|
2143
2143
|
}
|
|
2144
|
-
return
|
|
2144
|
+
return P(t, {
|
|
2145
2145
|
contentType: "page",
|
|
2146
2146
|
entityId: Number(m.id),
|
|
2147
2147
|
languageId: a.id,
|
|
@@ -2150,7 +2150,7 @@ async function jn(e, t) {
|
|
|
2150
2150
|
}, o), t?.revalidatePath?.("/cms/pages"), {
|
|
2151
2151
|
blockCount: s.length,
|
|
2152
2152
|
contentType: "page",
|
|
2153
|
-
editPath:
|
|
2153
|
+
editPath: nn("page", m.id),
|
|
2154
2154
|
entityId: m.id,
|
|
2155
2155
|
mutationExecuted: !0,
|
|
2156
2156
|
slug: o,
|
|
@@ -2159,17 +2159,17 @@ async function jn(e, t) {
|
|
|
2159
2159
|
translationGroupId: m.translation_group_id
|
|
2160
2160
|
};
|
|
2161
2161
|
}
|
|
2162
|
-
async function
|
|
2163
|
-
let n =
|
|
2164
|
-
t = await
|
|
2165
|
-
let r =
|
|
2162
|
+
async function Nn(e, t) {
|
|
2163
|
+
let n = pe.parse(e);
|
|
2164
|
+
t = await W(t, n.blocks);
|
|
2165
|
+
let r = j(t), i = Qe(t), a = await St(r, n.languageCode), o = B(n.slug || n.title), s = Zt(n.blocks, void 0, void 0, t), c = await Qt({
|
|
2166
2166
|
contentType: "post",
|
|
2167
2167
|
languageId: a.id,
|
|
2168
2168
|
slug: o,
|
|
2169
2169
|
supabase: r
|
|
2170
2170
|
});
|
|
2171
2171
|
if (c) return c;
|
|
2172
|
-
let l = await
|
|
2172
|
+
let l = await $t({
|
|
2173
2173
|
contentType: "post",
|
|
2174
2174
|
languageCode: a.code,
|
|
2175
2175
|
languageId: a.id,
|
|
@@ -2194,7 +2194,7 @@ async function Mn(e, t) {
|
|
|
2194
2194
|
translation_group_id: l.translationGroupId
|
|
2195
2195
|
},
|
|
2196
2196
|
tool: "create_cms_post"
|
|
2197
|
-
}, f =
|
|
2197
|
+
}, f = z({
|
|
2198
2198
|
action: "CREATE POST",
|
|
2199
2199
|
context: t,
|
|
2200
2200
|
payload: d,
|
|
@@ -2209,15 +2209,15 @@ async function Mn(e, t) {
|
|
|
2209
2209
|
subject: o
|
|
2210
2210
|
});
|
|
2211
2211
|
if (f) return f;
|
|
2212
|
-
let p = l.translationGroupId ||
|
|
2212
|
+
let p = l.translationGroupId || $e(), m = await N(d.item.feature_image_id, t, n.title), { data: h, error: g } = await r.from("posts").insert({
|
|
2213
2213
|
...d.item,
|
|
2214
2214
|
author_id: i,
|
|
2215
2215
|
feature_image_id: m,
|
|
2216
2216
|
translation_group_id: p
|
|
2217
2217
|
}).select("id, language_id, slug, status, title, translation_group_id").single();
|
|
2218
|
-
if (g || !h?.id) throw Error(`Failed to create post: ${
|
|
2218
|
+
if (g || !h?.id) throw Error(`Failed to create post: ${F(g)}`);
|
|
2219
2219
|
try {
|
|
2220
|
-
await
|
|
2220
|
+
await en({
|
|
2221
2221
|
blocks: s,
|
|
2222
2222
|
contentType: "post",
|
|
2223
2223
|
itemId: Number(h.id),
|
|
@@ -2225,13 +2225,13 @@ async function Mn(e, t) {
|
|
|
2225
2225
|
supabase: r
|
|
2226
2226
|
});
|
|
2227
2227
|
} catch (e) {
|
|
2228
|
-
throw await
|
|
2228
|
+
throw await tn({
|
|
2229
2229
|
contentType: "post",
|
|
2230
2230
|
itemId: Number(h.id),
|
|
2231
2231
|
supabase: r
|
|
2232
2232
|
}), e;
|
|
2233
2233
|
}
|
|
2234
|
-
return
|
|
2234
|
+
return P(t, {
|
|
2235
2235
|
contentType: "post",
|
|
2236
2236
|
entityId: Number(h.id),
|
|
2237
2237
|
languageId: a.id,
|
|
@@ -2240,7 +2240,7 @@ async function Mn(e, t) {
|
|
|
2240
2240
|
}, o), t?.revalidatePath?.("/cms/posts"), t?.revalidatePath?.("/articles"), {
|
|
2241
2241
|
blockCount: s.length,
|
|
2242
2242
|
contentType: "post",
|
|
2243
|
-
editPath:
|
|
2243
|
+
editPath: nn("post", h.id),
|
|
2244
2244
|
entityId: h.id,
|
|
2245
2245
|
mutationExecuted: !0,
|
|
2246
2246
|
slug: o,
|
|
@@ -2249,22 +2249,22 @@ async function Mn(e, t) {
|
|
|
2249
2249
|
translationGroupId: h.translation_group_id
|
|
2250
2250
|
};
|
|
2251
2251
|
}
|
|
2252
|
-
function
|
|
2253
|
-
return (t ||
|
|
2252
|
+
function Pn(e, t) {
|
|
2253
|
+
return (t || B(e) || "product").replace(/-/g, "").slice(0, 24).toUpperCase();
|
|
2254
2254
|
}
|
|
2255
|
-
function
|
|
2255
|
+
function Fn(e) {
|
|
2256
2256
|
if (e == null) return;
|
|
2257
|
-
if (typeof e == "string") return
|
|
2257
|
+
if (typeof e == "string") return m(e) ?? void 0;
|
|
2258
2258
|
let t = Array.isArray(e) ? {
|
|
2259
2259
|
content: e,
|
|
2260
2260
|
type: "doc"
|
|
2261
|
-
} :
|
|
2261
|
+
} : U(e) && e.type !== "doc" && Array.isArray(e.content) ? {
|
|
2262
2262
|
...e,
|
|
2263
2263
|
type: "doc"
|
|
2264
|
-
} : e, n =
|
|
2264
|
+
} : e, n = Ae().safeParse(t);
|
|
2265
2265
|
if (!n.success) {
|
|
2266
|
-
if (
|
|
2267
|
-
let t =
|
|
2266
|
+
if (U(e) && typeof e.type == "string") {
|
|
2267
|
+
let t = Ae().safeParse({
|
|
2268
2268
|
content: [e],
|
|
2269
2269
|
type: "doc"
|
|
2270
2270
|
});
|
|
@@ -2274,23 +2274,23 @@ function Pn(e) {
|
|
|
2274
2274
|
}
|
|
2275
2275
|
return n.data;
|
|
2276
2276
|
}
|
|
2277
|
-
function
|
|
2278
|
-
let t = (e) => !!(e && Array.isArray(e.content) && e.content.length > 0), n =
|
|
2277
|
+
function In(e) {
|
|
2278
|
+
let t = (e) => !!(e && Array.isArray(e.content) && e.content.length > 0), n = Fn(e.description_json);
|
|
2279
2279
|
if (t(n)) return n;
|
|
2280
|
-
let r = e.description_html ?
|
|
2280
|
+
let r = e.description_html ? m(e.description_html) : null;
|
|
2281
2281
|
return t(r) ? r : void 0;
|
|
2282
2282
|
}
|
|
2283
|
-
async function
|
|
2284
|
-
let n =
|
|
2285
|
-
t = await
|
|
2286
|
-
let r =
|
|
2283
|
+
async function Ln(e, t) {
|
|
2284
|
+
let n = me.parse(e);
|
|
2285
|
+
t = await W(t, n.blocks);
|
|
2286
|
+
let r = j(t), i = await St(r, n.languageCode), a = B(n.slug || n.title), o = Zt(n.blocks, void 0, void 0, t), s = await Qt({
|
|
2287
2287
|
contentType: "product",
|
|
2288
2288
|
languageId: i.id,
|
|
2289
2289
|
slug: a,
|
|
2290
2290
|
supabase: r
|
|
2291
2291
|
});
|
|
2292
2292
|
if (s) return s;
|
|
2293
|
-
let c = await
|
|
2293
|
+
let c = await $t({
|
|
2294
2294
|
contentType: "product",
|
|
2295
2295
|
languageCode: i.code,
|
|
2296
2296
|
languageId: i.id,
|
|
@@ -2298,8 +2298,8 @@ async function In(e, t) {
|
|
|
2298
2298
|
supabase: r
|
|
2299
2299
|
});
|
|
2300
2300
|
if (c.result) return c.result;
|
|
2301
|
-
let { createProduct: l, productSchema: u } = await
|
|
2302
|
-
description_json:
|
|
2301
|
+
let { createProduct: l, productSchema: u } = await Ge(), d = n.product_type === "digital" && n.payment_provider === "freemius" ? n.trial_period_days : 0, f = u.parse({
|
|
2302
|
+
description_json: In(n),
|
|
2303
2303
|
freemius_plan_id: n.freemius_plan_id || "",
|
|
2304
2304
|
freemius_product_id: n.freemius_product_id || "",
|
|
2305
2305
|
is_taxable: n.is_taxable,
|
|
@@ -2314,7 +2314,7 @@ async function In(e, t) {
|
|
|
2314
2314
|
sale_price: n.sale_price ?? null,
|
|
2315
2315
|
sale_prices: n.sale_prices || {},
|
|
2316
2316
|
short_description: n.short_description ?? "",
|
|
2317
|
-
sku: n.sku ||
|
|
2317
|
+
sku: n.sku || Pn(n.title, a),
|
|
2318
2318
|
slug: a,
|
|
2319
2319
|
status: n.status,
|
|
2320
2320
|
stock: n.stock,
|
|
@@ -2325,7 +2325,7 @@ async function In(e, t) {
|
|
|
2325
2325
|
upc: n.upc ?? "",
|
|
2326
2326
|
variation_attributes: [],
|
|
2327
2327
|
variants: []
|
|
2328
|
-
}), p = n.images ?? [], m =
|
|
2328
|
+
}), p = n.images ?? [], m = z({
|
|
2329
2329
|
action: "CREATE PRODUCT",
|
|
2330
2330
|
context: t,
|
|
2331
2331
|
payload: {
|
|
@@ -2352,7 +2352,7 @@ async function In(e, t) {
|
|
|
2352
2352
|
if (m) return m;
|
|
2353
2353
|
let h = [], g = null;
|
|
2354
2354
|
if (p.length > 0) try {
|
|
2355
|
-
if (h = [...new Set(await
|
|
2355
|
+
if (h = [...new Set(await Re(p, t, n.title))], h.length === 0) throw Error("None of the provided images could be resolved to a media item.");
|
|
2356
2356
|
} catch (e) {
|
|
2357
2357
|
g = e instanceof Error ? e.message : String(e);
|
|
2358
2358
|
}
|
|
@@ -2362,7 +2362,7 @@ async function In(e, t) {
|
|
|
2362
2362
|
});
|
|
2363
2363
|
if (!_?.id) throw Error("Failed to create product.");
|
|
2364
2364
|
try {
|
|
2365
|
-
await
|
|
2365
|
+
await en({
|
|
2366
2366
|
blocks: o,
|
|
2367
2367
|
contentType: "product",
|
|
2368
2368
|
itemId: _.id,
|
|
@@ -2370,13 +2370,13 @@ async function In(e, t) {
|
|
|
2370
2370
|
supabase: r
|
|
2371
2371
|
});
|
|
2372
2372
|
} catch (e) {
|
|
2373
|
-
throw await
|
|
2373
|
+
throw await tn({
|
|
2374
2374
|
contentType: "product",
|
|
2375
2375
|
itemId: _.id,
|
|
2376
2376
|
supabase: r
|
|
2377
2377
|
}), e;
|
|
2378
2378
|
}
|
|
2379
|
-
return
|
|
2379
|
+
return P(t, {
|
|
2380
2380
|
contentType: "product",
|
|
2381
2381
|
entityId: _.id,
|
|
2382
2382
|
languageId: i.id,
|
|
@@ -2385,7 +2385,7 @@ async function In(e, t) {
|
|
|
2385
2385
|
}, a), t?.revalidatePath?.("/cms/products"), {
|
|
2386
2386
|
blockCount: o.length,
|
|
2387
2387
|
contentType: "product",
|
|
2388
|
-
editPath:
|
|
2388
|
+
editPath: nn("product", _.id),
|
|
2389
2389
|
entityId: _.id,
|
|
2390
2390
|
imageCount: h.length,
|
|
2391
2391
|
...g ? { imageError: g } : {},
|
|
@@ -2396,54 +2396,54 @@ async function In(e, t) {
|
|
|
2396
2396
|
translationGroupId: _.translation_group_id
|
|
2397
2397
|
};
|
|
2398
2398
|
}
|
|
2399
|
-
function
|
|
2399
|
+
function Rn(e) {
|
|
2400
2400
|
return e.trim().replace(/[\s-]+/g, "_").toLowerCase();
|
|
2401
2401
|
}
|
|
2402
|
-
function
|
|
2403
|
-
let n = typeof t == "string" ?
|
|
2402
|
+
function zn(e, t) {
|
|
2403
|
+
let n = typeof t == "string" ? Rn(t) : t;
|
|
2404
2404
|
return e === "product" ? n === "public" || n === "publish" || n === "published" ? "active" : n : n === "public" || n === "active" || n === "publish" ? "published" : n;
|
|
2405
2405
|
}
|
|
2406
|
-
function
|
|
2407
|
-
let t =
|
|
2406
|
+
function Bn(e) {
|
|
2407
|
+
let t = Rn(e.field);
|
|
2408
2408
|
return !!(e.startsAt || e.endsAt || t.includes("start") || t.includes("end") || t.includes("schedule") || t.includes("special_date"));
|
|
2409
2409
|
}
|
|
2410
|
-
async function
|
|
2410
|
+
async function Vn(e, t, n) {
|
|
2411
2411
|
if (e === "price" || e === "sale_price") {
|
|
2412
2412
|
if (t == null) return { [e]: null };
|
|
2413
|
-
let r = await
|
|
2414
|
-
return { [e]:
|
|
2413
|
+
let r = await Ct(n);
|
|
2414
|
+
return { [e]: rt(Number(t), r) };
|
|
2415
2415
|
}
|
|
2416
2416
|
if (e === "prices" || e === "sale_prices") {
|
|
2417
|
-
let r = await
|
|
2418
|
-
return { [e]:
|
|
2417
|
+
let r = await Ct(n);
|
|
2418
|
+
return { [e]: it(t, r) };
|
|
2419
2419
|
}
|
|
2420
|
-
return e === "description_json" ? { description_json:
|
|
2420
|
+
return e === "description_json" ? { description_json: Fn(t) } : { [e]: t };
|
|
2421
2421
|
}
|
|
2422
|
-
var
|
|
2422
|
+
var Hn = /* @__PURE__ */ new Set([
|
|
2423
2423
|
"language_id",
|
|
2424
2424
|
"price",
|
|
2425
2425
|
"sale_price",
|
|
2426
2426
|
"stock",
|
|
2427
2427
|
"trial_period_days"
|
|
2428
|
-
]),
|
|
2429
|
-
function
|
|
2428
|
+
]), Un = /* @__PURE__ */ new Set(["is_taxable", "trial_requires_payment_method"]);
|
|
2429
|
+
function Wn(e, t) {
|
|
2430
2430
|
if (typeof t != "string") return t;
|
|
2431
2431
|
let n = t.trim();
|
|
2432
|
-
if (
|
|
2432
|
+
if (Hn.has(e)) {
|
|
2433
2433
|
if (n.toLowerCase() === "null") return null;
|
|
2434
2434
|
if (n === "") return t;
|
|
2435
2435
|
let e = Number(n);
|
|
2436
2436
|
return Number.isFinite(e) ? e : t;
|
|
2437
2437
|
}
|
|
2438
|
-
if (
|
|
2438
|
+
if (Un.has(e)) {
|
|
2439
2439
|
let e = n.toLowerCase();
|
|
2440
2440
|
if (e === "true") return !0;
|
|
2441
2441
|
if (e === "false") return !1;
|
|
2442
2442
|
}
|
|
2443
2443
|
return t;
|
|
2444
2444
|
}
|
|
2445
|
-
function
|
|
2446
|
-
let n =
|
|
2445
|
+
function Gn(e, t) {
|
|
2446
|
+
let n = Rn(e.field), r = {
|
|
2447
2447
|
description: "description_json",
|
|
2448
2448
|
feature_image: "feature_image_id",
|
|
2449
2449
|
feature_image_id: "feature_image_id",
|
|
@@ -2461,12 +2461,12 @@ function Wn(e, t) {
|
|
|
2461
2461
|
trial_days: "trial_period_days",
|
|
2462
2462
|
trial_payment_method_required: "trial_requires_payment_method",
|
|
2463
2463
|
type: "product_type"
|
|
2464
|
-
}[n] || n, i = r === "status" ?
|
|
2464
|
+
}[n] || n, i = r === "status" ? zn(t.contentType, e.value) : Wn(r, e.value);
|
|
2465
2465
|
if (t.contentType !== "product") {
|
|
2466
|
-
if (!(t.contentType === "page" ?
|
|
2467
|
-
return r === "status" &&
|
|
2466
|
+
if (!(t.contentType === "page" ? bn : xn).has(r)) throw Error(`Field "${e.field}" cannot be updated for ${t.contentType}.`);
|
|
2467
|
+
return r === "status" && En(t.contentType, i), {
|
|
2468
2468
|
field: r,
|
|
2469
|
-
payload: { [r]:
|
|
2469
|
+
payload: { [r]: Tn(r, i) }
|
|
2470
2470
|
};
|
|
2471
2471
|
}
|
|
2472
2472
|
if (!(/* @__PURE__ */ new Set([
|
|
@@ -2493,7 +2493,7 @@ function Wn(e, t) {
|
|
|
2493
2493
|
"trial_requires_payment_method",
|
|
2494
2494
|
"upc"
|
|
2495
2495
|
])).has(r)) throw Error(`Field "${e.field}" cannot be updated for product.`);
|
|
2496
|
-
if (r === "status" &&
|
|
2496
|
+
if (r === "status" && En("product", i), (r === "price" || r === "sale_price") && i !== null && (typeof i != "number" || i < 0)) throw Error(`${r} must be a non-negative number or null.`);
|
|
2497
2497
|
if (r === "stock" && (!Number.isInteger(i) || Number(i) < 0)) throw Error("stock must be a non-negative integer.");
|
|
2498
2498
|
if (r === "trial_period_days" && (!Number.isInteger(i) || Number(i) < 0)) throw Error("trial_period_days must be a non-negative integer.");
|
|
2499
2499
|
if (r === "trial_requires_payment_method" && typeof i != "boolean") throw Error("trial_requires_payment_method must be a boolean.");
|
|
@@ -2502,23 +2502,23 @@ function Wn(e, t) {
|
|
|
2502
2502
|
payload: { [r]: i }
|
|
2503
2503
|
};
|
|
2504
2504
|
}
|
|
2505
|
-
async function
|
|
2506
|
-
let n =
|
|
2507
|
-
if (
|
|
2505
|
+
async function Kn(e, t) {
|
|
2506
|
+
let n = he.parse(e);
|
|
2507
|
+
if (Bn(n)) return {
|
|
2508
2508
|
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.",
|
|
2509
2509
|
mutationExecuted: !1,
|
|
2510
2510
|
success: !1,
|
|
2511
2511
|
unsupported: !0
|
|
2512
2512
|
};
|
|
2513
|
-
let r = await Y(n, t), i =
|
|
2513
|
+
let r = await Y(n, t), i = Gn(n, r), a = i.field, o = i.payload;
|
|
2514
2514
|
if (a === "language_id" && typeof o.language_id == "string") {
|
|
2515
|
-
let e = await J(
|
|
2515
|
+
let e = await J(j(t), o.language_id);
|
|
2516
2516
|
o = {
|
|
2517
2517
|
...o,
|
|
2518
2518
|
language_id: e.id
|
|
2519
2519
|
};
|
|
2520
2520
|
}
|
|
2521
|
-
let s =
|
|
2521
|
+
let s = z({
|
|
2522
2522
|
action: "UPDATE FIELD",
|
|
2523
2523
|
context: t,
|
|
2524
2524
|
payload: {
|
|
@@ -2539,20 +2539,20 @@ async function Gn(e, t) {
|
|
|
2539
2539
|
subject: `${r.contentType} ${r.item.slug || r.item.id} ${a}`
|
|
2540
2540
|
});
|
|
2541
2541
|
if (s) return s;
|
|
2542
|
-
let c = await
|
|
2542
|
+
let c = await _(t, r.contentType, r.item.id);
|
|
2543
2543
|
if (r.contentType === "product") {
|
|
2544
|
-
let e =
|
|
2544
|
+
let e = j(t), n = await Vn(a, o[a], e), { data: i, error: s } = await e.from("products").update({
|
|
2545
2545
|
...n,
|
|
2546
2546
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
2547
2547
|
}).eq("id", r.item.id).select("id, language_id, slug, status, title").single();
|
|
2548
|
-
if (s || !i) throw Error(`Failed to update product: ${
|
|
2549
|
-
return
|
|
2548
|
+
if (s || !i) throw Error(`Failed to update product: ${F(s)}`);
|
|
2549
|
+
return P(t, {
|
|
2550
2550
|
contentType: "product",
|
|
2551
2551
|
entityId: String(i.id),
|
|
2552
2552
|
languageId: i.language_id,
|
|
2553
2553
|
slug: i.slug,
|
|
2554
2554
|
title: i.title
|
|
2555
|
-
}, i.slug), await
|
|
2555
|
+
}, i.slug), await v(t, "product", i.id, c), {
|
|
2556
2556
|
contentType: "product",
|
|
2557
2557
|
entityId: i.id,
|
|
2558
2558
|
field: a,
|
|
@@ -2564,20 +2564,20 @@ async function Gn(e, t) {
|
|
|
2564
2564
|
}
|
|
2565
2565
|
a === "feature_image_id" && typeof o.feature_image_id == "string" && (o = {
|
|
2566
2566
|
...o,
|
|
2567
|
-
feature_image_id: await
|
|
2567
|
+
feature_image_id: await N(o.feature_image_id, t, typeof r.item.title == "string" ? r.item.title : void 0)
|
|
2568
2568
|
});
|
|
2569
|
-
let l = r.contentType === "page" ? "pages" : "posts", { data: u, error: d } = await
|
|
2569
|
+
let l = r.contentType === "page" ? "pages" : "posts", { data: u, error: d } = await j(t).from(l).update({
|
|
2570
2570
|
...o,
|
|
2571
2571
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
2572
2572
|
}).eq("id", r.item.id).select("id, language_id, slug, status, title").single();
|
|
2573
|
-
if (d || !u) throw Error(`Failed to update ${r.contentType}: ${
|
|
2574
|
-
return
|
|
2573
|
+
if (d || !u) throw Error(`Failed to update ${r.contentType}: ${F(d)}`);
|
|
2574
|
+
return P(t, {
|
|
2575
2575
|
contentType: r.contentType,
|
|
2576
2576
|
entityId: Number(u.id),
|
|
2577
2577
|
languageId: u.language_id,
|
|
2578
2578
|
slug: u.slug,
|
|
2579
2579
|
title: u.title
|
|
2580
|
-
}, u.slug), await
|
|
2580
|
+
}, u.slug), await v(t, r.contentType, u.id, c), {
|
|
2581
2581
|
contentType: r.contentType,
|
|
2582
2582
|
entityId: u.id,
|
|
2583
2583
|
field: a,
|
|
@@ -2587,25 +2587,25 @@ async function Gn(e, t) {
|
|
|
2587
2587
|
updatedFields: [a]
|
|
2588
2588
|
};
|
|
2589
2589
|
}
|
|
2590
|
-
async function
|
|
2591
|
-
let n = await Y(
|
|
2590
|
+
async function qn(e, t) {
|
|
2591
|
+
let n = await Y(ge.parse(e), t);
|
|
2592
2592
|
if (n.contentType === "product") return {
|
|
2593
2593
|
affectedCount: 1,
|
|
2594
|
-
collectionPath:
|
|
2594
|
+
collectionPath: rn("product"),
|
|
2595
2595
|
contentType: "product",
|
|
2596
2596
|
item: n.item,
|
|
2597
2597
|
navigationLinkCount: 0,
|
|
2598
2598
|
publicPaths: n.item.slug ? [`/product/${n.item.slug}`] : [],
|
|
2599
2599
|
targetIds: [n.item.id]
|
|
2600
2600
|
};
|
|
2601
|
-
let r = n.contentType === "page" ? "pages" : "posts", { data: i, error: a } = await
|
|
2602
|
-
if (a) throw Error(`Failed to inspect related ${n.contentType}s: ${
|
|
2603
|
-
let o = Array.isArray(i) ? i : [], s = o.map((e) => n.contentType === "page" ? e.slug === "home" ? "/" : `/${e.slug}` : `/article/${e.slug}`).filter(Boolean), c = new Set(s), { data: l, error: u } = await
|
|
2604
|
-
if (u) throw Error(`Failed to inspect related navigation links: ${
|
|
2601
|
+
let r = n.contentType === "page" ? "pages" : "posts", { data: i, error: a } = await j(t).from(r).select("id, slug, title, translation_group_id").eq("translation_group_id", n.item.translation_group_id);
|
|
2602
|
+
if (a) throw Error(`Failed to inspect related ${n.contentType}s: ${F(a)}`);
|
|
2603
|
+
let o = Array.isArray(i) ? i : [], s = o.map((e) => n.contentType === "page" ? e.slug === "home" ? "/" : `/${e.slug}` : `/article/${e.slug}`).filter(Boolean), c = new Set(s), { data: l, error: u } = await j(t).from("navigation_items").select("id, url");
|
|
2604
|
+
if (u) throw Error(`Failed to inspect related navigation links: ${F(u)}`);
|
|
2605
2605
|
let d = (Array.isArray(l) ? l : []).filter((e) => c.has(e.url)).length;
|
|
2606
2606
|
return {
|
|
2607
2607
|
affectedCount: o.length,
|
|
2608
|
-
collectionPath:
|
|
2608
|
+
collectionPath: rn(n.contentType),
|
|
2609
2609
|
contentType: n.contentType,
|
|
2610
2610
|
item: n.item,
|
|
2611
2611
|
navigationLinkCount: d,
|
|
@@ -2613,16 +2613,16 @@ async function Kn(e, t) {
|
|
|
2613
2613
|
targetIds: o.map((e) => e.id)
|
|
2614
2614
|
};
|
|
2615
2615
|
}
|
|
2616
|
-
function
|
|
2616
|
+
function Jn(e) {
|
|
2617
2617
|
let t = e.item.title || e.item.slug || "selected item", n = e.item.slug ? ` (${e.item.slug})` : "";
|
|
2618
2618
|
if (e.contentType === "product") return `Delete product "${t}"${n}.`;
|
|
2619
|
-
let r = [`${
|
|
2619
|
+
let r = [`${R(e.affectedCount, "language version")}`, e.navigationLinkCount > 0 ? `${R(e.navigationLinkCount, "navigation link")}` : null].filter(Boolean);
|
|
2620
2620
|
return `Delete ${e.contentType} "${t}"${n}, including ${r.join(" and ")}.`;
|
|
2621
2621
|
}
|
|
2622
|
-
async function
|
|
2623
|
-
let n = await
|
|
2622
|
+
async function Yn(e, t) {
|
|
2623
|
+
let n = await qn(e, t);
|
|
2624
2624
|
return {
|
|
2625
|
-
...
|
|
2625
|
+
...Xe({
|
|
2626
2626
|
action: `DELETE ${n.contentType}`,
|
|
2627
2627
|
payload: {
|
|
2628
2628
|
affectedCount: n.affectedCount,
|
|
@@ -2637,7 +2637,7 @@ async function Jn(e, t) {
|
|
|
2637
2637
|
navigationLinkCount: n.navigationLinkCount,
|
|
2638
2638
|
publicPaths: n.publicPaths,
|
|
2639
2639
|
slug: n.item.slug,
|
|
2640
|
-
summary:
|
|
2640
|
+
summary: Jn(n),
|
|
2641
2641
|
title: n.item.title
|
|
2642
2642
|
},
|
|
2643
2643
|
subject: `${n.item.id} ${n.item.slug || ""}`
|
|
@@ -2645,8 +2645,8 @@ async function Jn(e, t) {
|
|
|
2645
2645
|
preparedDelete: !0
|
|
2646
2646
|
};
|
|
2647
2647
|
}
|
|
2648
|
-
async function
|
|
2649
|
-
let n = await
|
|
2648
|
+
async function Xn(e, t) {
|
|
2649
|
+
let n = await qn(A.parse(e), t), r = z({
|
|
2650
2650
|
action: `DELETE ${n.contentType}`,
|
|
2651
2651
|
context: t,
|
|
2652
2652
|
payload: {
|
|
@@ -2662,22 +2662,22 @@ async function Yn(e, t) {
|
|
|
2662
2662
|
navigationLinkCount: n.navigationLinkCount,
|
|
2663
2663
|
publicPaths: n.publicPaths,
|
|
2664
2664
|
slug: n.item.slug,
|
|
2665
|
-
summary:
|
|
2665
|
+
summary: Jn(n),
|
|
2666
2666
|
title: n.item.title
|
|
2667
2667
|
},
|
|
2668
2668
|
subject: `${n.item.id} ${n.item.slug || ""}`
|
|
2669
2669
|
});
|
|
2670
2670
|
if (r) return r;
|
|
2671
|
-
let i =
|
|
2671
|
+
let i = j(t);
|
|
2672
2672
|
if (n.contentType === "product") {
|
|
2673
2673
|
let { error: e } = await i.from("products").delete().eq("id", n.item.id);
|
|
2674
|
-
if (e) throw Error(`Failed to delete product: ${
|
|
2674
|
+
if (e) throw Error(`Failed to delete product: ${F(e)}`);
|
|
2675
2675
|
} else {
|
|
2676
2676
|
for (let e of n.publicPaths) await i.from("navigation_items").delete().eq("url", e);
|
|
2677
2677
|
let e = n.contentType === "page" ? "pages" : "posts", { error: t } = await i.from(e).delete().eq("translation_group_id", n.item.translation_group_id);
|
|
2678
|
-
if (t) throw Error(`Failed to delete ${n.contentType}: ${
|
|
2678
|
+
if (t) throw Error(`Failed to delete ${n.contentType}: ${F(t)}`);
|
|
2679
2679
|
}
|
|
2680
|
-
let a = t?.revalidatePath ??
|
|
2680
|
+
let a = t?.revalidatePath ?? je();
|
|
2681
2681
|
return a && (a(n.collectionPath), a("/cms/navigation"), n.publicPaths.forEach((e) => a(e))), {
|
|
2682
2682
|
affectedCount: n.affectedCount,
|
|
2683
2683
|
collectionPath: n.collectionPath,
|
|
@@ -2687,23 +2687,23 @@ async function Yn(e, t) {
|
|
|
2687
2687
|
success: !0
|
|
2688
2688
|
};
|
|
2689
2689
|
}
|
|
2690
|
-
async function
|
|
2690
|
+
async function Zn(e, t) {
|
|
2691
2691
|
switch (e.tool) {
|
|
2692
|
-
case "create_cms_page": return
|
|
2693
|
-
case "create_cms_post": return
|
|
2694
|
-
case "create_cms_product": return
|
|
2695
|
-
case "delete_cms_item": return
|
|
2696
|
-
case "update_cms_item_field": return
|
|
2697
|
-
case "update_content_block": return
|
|
2698
|
-
case "insert_content_block": return
|
|
2699
|
-
case "update_current_cms_fields": return
|
|
2700
|
-
case "update_footer": return
|
|
2701
|
-
case "update_navigation_bar": return
|
|
2702
|
-
case "update_section_column_block": return
|
|
2703
|
-
case "set_content_images": return
|
|
2704
|
-
}
|
|
2705
|
-
}
|
|
2706
|
-
function
|
|
2692
|
+
case "create_cms_page": return Mn(e.input, t);
|
|
2693
|
+
case "create_cms_post": return Nn(e.input, t);
|
|
2694
|
+
case "create_cms_product": return Ln(e.input, t);
|
|
2695
|
+
case "delete_cms_item": return Xn(e.input, t);
|
|
2696
|
+
case "update_cms_item_field": return Kn(e.input, t);
|
|
2697
|
+
case "update_content_block": return kn(e.input, t);
|
|
2698
|
+
case "insert_content_block": return An(e.input, t);
|
|
2699
|
+
case "update_current_cms_fields": return On(e.input, t);
|
|
2700
|
+
case "update_footer": return on(e.input, t);
|
|
2701
|
+
case "update_navigation_bar": return an(e.input, t);
|
|
2702
|
+
case "update_section_column_block": return jn(e.input, t);
|
|
2703
|
+
case "set_content_images": return Yr(e.input, t);
|
|
2704
|
+
}
|
|
2705
|
+
}
|
|
2706
|
+
function Qn(e, t) {
|
|
2707
2707
|
if (e.tool !== "create_cms_page" && e.tool !== "create_cms_post" && e.tool !== "create_cms_product" || e.input.translationGroupId || !e.input.languageCode) return e;
|
|
2708
2708
|
let n = t[e.tool];
|
|
2709
2709
|
return n ? {
|
|
@@ -2714,14 +2714,14 @@ function Zn(e, t) {
|
|
|
2714
2714
|
}
|
|
2715
2715
|
} : e;
|
|
2716
2716
|
}
|
|
2717
|
-
function
|
|
2717
|
+
function $n(e) {
|
|
2718
2718
|
return e === "create_cms_page" ? "page" : e === "create_cms_post" ? "post" : "product";
|
|
2719
2719
|
}
|
|
2720
|
-
function
|
|
2720
|
+
function er(e, t, n) {
|
|
2721
2721
|
if (e.tool !== "set_content_images") return e;
|
|
2722
2722
|
let r = e.input;
|
|
2723
2723
|
if (r.entityId !== void 0) return e;
|
|
2724
|
-
let i = r.slug ? t.get(`${r.contentType || "product"}:${
|
|
2724
|
+
let i = r.slug ? t.get(`${r.contentType || "product"}:${B(r.slug)}`) : n;
|
|
2725
2725
|
return i ? {
|
|
2726
2726
|
...e,
|
|
2727
2727
|
input: {
|
|
@@ -2731,24 +2731,24 @@ function $n(e, t, n) {
|
|
|
2731
2731
|
}
|
|
2732
2732
|
} : e;
|
|
2733
2733
|
}
|
|
2734
|
-
async function
|
|
2735
|
-
let n =
|
|
2734
|
+
async function tr(e, t) {
|
|
2735
|
+
let n = xe.parse(e), r = new Set(n.actions.filter((e) => e.tool === "create_cms_page" || e.tool === "create_cms_post" || e.tool === "create_cms_product").map((e) => {
|
|
2736
2736
|
let t = e.input;
|
|
2737
|
-
return `${
|
|
2737
|
+
return `${$n(e.tool)}:${B(t.slug || t.title || "")}`;
|
|
2738
2738
|
})), i = (e) => {
|
|
2739
2739
|
if (e.tool !== "set_content_images") return !1;
|
|
2740
2740
|
let t = e.input;
|
|
2741
|
-
return t.slug ? r.has(`${t.contentType || "product"}:${
|
|
2741
|
+
return t.slug ? r.has(`${t.contentType || "product"}:${B(t.slug)}`) : r.size > 0;
|
|
2742
2742
|
};
|
|
2743
2743
|
if (!t?.skipConfirmation) {
|
|
2744
2744
|
let e = [];
|
|
2745
2745
|
for (let r of n.actions) {
|
|
2746
2746
|
if (i(r)) {
|
|
2747
2747
|
let t = r.input;
|
|
2748
|
-
e.push(`Set ${
|
|
2748
|
+
e.push(`Set ${R(t.images.length, "image")} on the ${t.slug ? `"${t.slug}"` : "new"} item created in this plan.`);
|
|
2749
2749
|
continue;
|
|
2750
2750
|
}
|
|
2751
|
-
let n = await
|
|
2751
|
+
let n = await Zn(r, {
|
|
2752
2752
|
...t,
|
|
2753
2753
|
latestUserMessage: null
|
|
2754
2754
|
});
|
|
@@ -2758,9 +2758,9 @@ async function er(e, t) {
|
|
|
2758
2758
|
success: !1
|
|
2759
2759
|
};
|
|
2760
2760
|
if (n.success === !1 || n.unsupported === !0) return n;
|
|
2761
|
-
n.requiresConfirmation === !0 && n.preview ? e.push(
|
|
2761
|
+
n.requiresConfirmation === !0 && n.preview ? e.push(Ze(r.tool, n.preview)) : e.push(`Run ${r.tool.replace(/_/g, " ")}.`);
|
|
2762
2762
|
}
|
|
2763
|
-
let r = n.summary || `Complete ${
|
|
2763
|
+
let r = n.summary || `Complete ${R(n.actions.length, "CMS action")}.`, a = z({
|
|
2764
2764
|
action: "EXECUTE CMS ACTION PLAN",
|
|
2765
2765
|
context: t,
|
|
2766
2766
|
payload: {
|
|
@@ -2781,14 +2781,14 @@ async function er(e, t) {
|
|
|
2781
2781
|
skipConfirmation: !0
|
|
2782
2782
|
}, o = [], s = !1, c = null, l = null, u = {}, d = /* @__PURE__ */ new Map(), f = null;
|
|
2783
2783
|
for (let [e, t] of n.actions.entries()) {
|
|
2784
|
-
let r =
|
|
2784
|
+
let r = er(Qn(t, u), d, f), i = await Zn(r, a);
|
|
2785
2785
|
if (o.push({
|
|
2786
2786
|
output: i,
|
|
2787
2787
|
tool: r.tool
|
|
2788
2788
|
}), i && typeof i == "object") {
|
|
2789
2789
|
let t = i;
|
|
2790
2790
|
if (t.mutationExecuted === !0 && (s = !0), !c && typeof t.editPath == "string" && (c = t.editPath), typeof t.redirectPath == "string" && (l = t.redirectPath), (r.tool === "create_cms_page" || r.tool === "create_cms_post" || r.tool === "create_cms_product") && (typeof t.translationGroupId == "string" && (u[r.tool] = t.translationGroupId), t.entityId !== void 0 && t.entityId !== null)) {
|
|
2791
|
-
let e =
|
|
2791
|
+
let e = $n(r.tool), n = {
|
|
2792
2792
|
contentType: e,
|
|
2793
2793
|
entityId: t.entityId
|
|
2794
2794
|
};
|
|
@@ -2817,20 +2817,20 @@ async function er(e, t) {
|
|
|
2817
2817
|
summary: n.summary ?? null
|
|
2818
2818
|
};
|
|
2819
2819
|
}
|
|
2820
|
-
var
|
|
2820
|
+
var nr = e.strictObject({
|
|
2821
2821
|
maxChars: e.number().int().min(500).max(2e4).default(8e3).describe("Maximum characters of readable body text to return."),
|
|
2822
2822
|
url: e.string().trim().min(1).max(2048).refine((e) => /^https?:\/\//i.test(e), "URL must start with http:// or https://.")
|
|
2823
|
-
}),
|
|
2824
|
-
function
|
|
2823
|
+
}), rr = 12e3, ir = 2e6;
|
|
2824
|
+
function ar(e) {
|
|
2825
2825
|
return e.replace(/<[^>]+>/g, " ").replace(/ /gi, " ").replace(/&/gi, "&").replace(/</gi, "<").replace(/>/gi, ">").replace(/"/gi, "\"").replace(/'/gi, "'").replace(/\s+/g, " ").trim();
|
|
2826
2826
|
}
|
|
2827
|
-
function
|
|
2827
|
+
function or(e) {
|
|
2828
2828
|
return e.trim().replace(/&/gi, "&").replace(/&/g, "&").replace(/"/gi, "\"").replace(/'/g, "'");
|
|
2829
2829
|
}
|
|
2830
|
-
var
|
|
2831
|
-
function
|
|
2830
|
+
var sr = /\.(avif|gif|jpe?g|png|webp)(?:[?#]|$)/i, cr = /(?:^|[/_-])(?: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;
|
|
2831
|
+
function lr(e, t) {
|
|
2832
2832
|
if (typeof e != "string") return null;
|
|
2833
|
-
let n =
|
|
2833
|
+
let n = or(e);
|
|
2834
2834
|
if (!n || n.startsWith("data:")) return null;
|
|
2835
2835
|
try {
|
|
2836
2836
|
let e = new URL(n, t);
|
|
@@ -2839,7 +2839,7 @@ function cr(e, t) {
|
|
|
2839
2839
|
return null;
|
|
2840
2840
|
}
|
|
2841
2841
|
}
|
|
2842
|
-
function
|
|
2842
|
+
function ur(e) {
|
|
2843
2843
|
let t = null;
|
|
2844
2844
|
for (let n of e.split(",")) {
|
|
2845
2845
|
let e = n.trim().split(/\s+/), r = e[0];
|
|
@@ -2856,10 +2856,10 @@ function $(e, t) {
|
|
|
2856
2856
|
let n = e.match(RegExp(`\\b${t}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`, "i"));
|
|
2857
2857
|
return n ? n[1] ?? n[2] ?? n[3] ?? null : null;
|
|
2858
2858
|
}
|
|
2859
|
-
function
|
|
2859
|
+
function dr(e, t) {
|
|
2860
2860
|
let n = [], r = [], i = (e, n) => {
|
|
2861
2861
|
if (typeof e == "string") {
|
|
2862
|
-
let r =
|
|
2862
|
+
let r = lr(e, t);
|
|
2863
2863
|
r && n.push(r);
|
|
2864
2864
|
return;
|
|
2865
2865
|
}
|
|
@@ -2886,8 +2886,8 @@ function ur(e, t) {
|
|
|
2886
2886
|
}
|
|
2887
2887
|
return [...n, ...r];
|
|
2888
2888
|
}
|
|
2889
|
-
var
|
|
2890
|
-
function
|
|
2889
|
+
var fr = /(?:^|[/_-])(?:thumbnails?|thumbs?|small|mini)(?:[/_.-]|$)/i;
|
|
2890
|
+
function pr(e) {
|
|
2891
2891
|
try {
|
|
2892
2892
|
let { pathname: t } = new URL(e);
|
|
2893
2893
|
return decodeURIComponent(t.slice(t.lastIndexOf("/") + 1)).toLowerCase() || null;
|
|
@@ -2895,47 +2895,47 @@ function fr(e) {
|
|
|
2895
2895
|
return null;
|
|
2896
2896
|
}
|
|
2897
2897
|
}
|
|
2898
|
-
function
|
|
2898
|
+
function mr(e, t) {
|
|
2899
2899
|
let n = /* @__PURE__ */ new Map();
|
|
2900
2900
|
for (let r of e.matchAll(/<a\b[^>]*>/gi)) {
|
|
2901
|
-
let e =
|
|
2902
|
-
if (!e || !
|
|
2903
|
-
let i =
|
|
2901
|
+
let e = lr($(r[0], "href"), t);
|
|
2902
|
+
if (!e || !sr.test(e) || fr.test(e) || cr.test(e)) continue;
|
|
2903
|
+
let i = pr(e);
|
|
2904
2904
|
i && !n.has(i) && n.set(i, e);
|
|
2905
2905
|
}
|
|
2906
2906
|
return n;
|
|
2907
2907
|
}
|
|
2908
|
-
function
|
|
2909
|
-
let n = [...
|
|
2908
|
+
function hr(e, t) {
|
|
2909
|
+
let n = [...dr(e, t)];
|
|
2910
2910
|
for (let r of [
|
|
2911
2911
|
/<meta\b[^>]*\b(?:property|name)\s*=\s*["'](?:og:image:secure_url|og:image:url|og:image)["'][^>]*>/gi,
|
|
2912
2912
|
/<meta\b[^>]*\b(?:property|name)\s*=\s*["'](?:twitter:image:src|twitter:image)["'][^>]*>/gi,
|
|
2913
2913
|
/<meta\b[^>]*\bitemprop\s*=\s*["']image["'][^>]*>/gi,
|
|
2914
2914
|
/<link\b[^>]*\brel\s*=\s*["']image_src["'][^>]*>/gi
|
|
2915
2915
|
]) for (let i of e.matchAll(r)) {
|
|
2916
|
-
let e = i[0], r =
|
|
2916
|
+
let e = i[0], r = lr($(e, "content") || $(e, "href"), t);
|
|
2917
2917
|
r && n.push(r);
|
|
2918
2918
|
}
|
|
2919
2919
|
let r = [];
|
|
2920
2920
|
for (let n of e.matchAll(/<img\b[^>]*>/gi)) {
|
|
2921
2921
|
let e = n[0], i = $(e, "srcset") || $(e, "data-srcset"), a = [
|
|
2922
|
-
i ?
|
|
2922
|
+
i ? ur(i) : null,
|
|
2923
2923
|
$(e, "src"),
|
|
2924
2924
|
$(e, "data-src"),
|
|
2925
2925
|
$(e, "data-original"),
|
|
2926
2926
|
$(e, "data-lazy-src"),
|
|
2927
2927
|
$(e, "data-image")
|
|
2928
2928
|
], o = null;
|
|
2929
|
-
for (let e of a) if (o =
|
|
2930
|
-
if (!o ||
|
|
2929
|
+
for (let e of a) if (o = lr(e, t), o) break;
|
|
2930
|
+
if (!o || cr.test(o)) continue;
|
|
2931
2931
|
let s = Number($(e, "width"));
|
|
2932
2932
|
Number.isFinite(s) && s > 0 && s < 200 || r.push(o);
|
|
2933
2933
|
}
|
|
2934
|
-
let i = (e) =>
|
|
2934
|
+
let i = (e) => sr.test(e);
|
|
2935
2935
|
n.push(...r.filter(i), ...r.filter((e) => !i(e)));
|
|
2936
|
-
let a =
|
|
2937
|
-
if (!
|
|
2938
|
-
let t =
|
|
2936
|
+
let a = mr(e, t), o = (e) => {
|
|
2937
|
+
if (!fr.test(e)) return e;
|
|
2938
|
+
let t = pr(e);
|
|
2939
2939
|
return t && a.get(t) || e;
|
|
2940
2940
|
}, s = /* @__PURE__ */ new Set(), c = [];
|
|
2941
2941
|
for (let e of n) {
|
|
@@ -2947,20 +2947,20 @@ function mr(e, t) {
|
|
|
2947
2947
|
mainImage: c[0] ?? null
|
|
2948
2948
|
};
|
|
2949
2949
|
}
|
|
2950
|
-
function
|
|
2951
|
-
let 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: i, mainImage: a } =
|
|
2950
|
+
function gr(e, t, n) {
|
|
2951
|
+
let 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: i, mainImage: a } = hr(e, n), o = e.match(/<title\b[^>]*>([\s\S]*?)<\/title>/i), s = e.match(/<meta[^>]+name=["']description["'][^>]*content=["']([^"']*)["'][^>]*>/i) || e.match(/<meta[^>]+content=["']([^"']*)["'][^>]*name=["']description["'][^>]*>/i), c = [...r.matchAll(/<h([1-3])\b[^>]*>([\s\S]*?)<\/h\1>/gi)].map((e) => ar(e[2])).filter(Boolean).slice(0, 40), l = ar(r.match(/<body\b[^>]*>([\s\S]*?)<\/body>/i)?.[1] ?? r);
|
|
2952
2952
|
return {
|
|
2953
|
-
description: s ?
|
|
2953
|
+
description: s ? ar(s[1]) : "",
|
|
2954
2954
|
headings: c,
|
|
2955
2955
|
images: i,
|
|
2956
2956
|
mainImage: a,
|
|
2957
2957
|
text: l.slice(0, t),
|
|
2958
|
-
title: o ?
|
|
2958
|
+
title: o ? ar(o[1]) : "",
|
|
2959
2959
|
truncated: l.length > t
|
|
2960
2960
|
};
|
|
2961
2961
|
}
|
|
2962
|
-
async function
|
|
2963
|
-
let t =
|
|
2962
|
+
async function _r(e) {
|
|
2963
|
+
let t = nr.parse(e), n;
|
|
2964
2964
|
try {
|
|
2965
2965
|
n = new URL(t.url);
|
|
2966
2966
|
} catch {
|
|
@@ -2975,12 +2975,12 @@ async function gr(e) {
|
|
|
2975
2975
|
success: !1,
|
|
2976
2976
|
url: t.url
|
|
2977
2977
|
};
|
|
2978
|
-
if (d(n.hostname)) return {
|
|
2978
|
+
if (d(n.hostname) || await f(n.hostname)) return {
|
|
2979
2979
|
message: "Refusing to fetch a local, private, or internal address.",
|
|
2980
2980
|
success: !1,
|
|
2981
2981
|
url: t.url
|
|
2982
2982
|
};
|
|
2983
|
-
let r = new AbortController(), i = setTimeout(() => r.abort(),
|
|
2983
|
+
let r = new AbortController(), i = setTimeout(() => r.abort(), rr);
|
|
2984
2984
|
try {
|
|
2985
2985
|
let e = await fetch(n.toString(), {
|
|
2986
2986
|
headers: {
|
|
@@ -2998,7 +2998,8 @@ async function gr(e) {
|
|
|
2998
2998
|
};
|
|
2999
2999
|
let i = e.url || n.toString();
|
|
3000
3000
|
try {
|
|
3001
|
-
|
|
3001
|
+
let e = new URL(i).hostname;
|
|
3002
|
+
if (d(e) || await f(e)) return {
|
|
3002
3003
|
message: "The URL redirected to a blocked internal address.",
|
|
3003
3004
|
success: !1,
|
|
3004
3005
|
url: t.url
|
|
@@ -3011,7 +3012,7 @@ async function gr(e) {
|
|
|
3011
3012
|
success: !1,
|
|
3012
3013
|
url: t.url
|
|
3013
3014
|
};
|
|
3014
|
-
let o = await e.text(), s =
|
|
3015
|
+
let o = await e.text(), s = gr(o.length > ir ? o.slice(0, ir) : o, t.maxChars, i);
|
|
3015
3016
|
return !s.text && !s.title ? {
|
|
3016
3017
|
message: "The URL returned no readable text content.",
|
|
3017
3018
|
success: !1,
|
|
@@ -3030,7 +3031,7 @@ async function gr(e) {
|
|
|
3030
3031
|
};
|
|
3031
3032
|
} catch (e) {
|
|
3032
3033
|
return {
|
|
3033
|
-
message: e instanceof Error && (e.name === "AbortError" || /abort/i.test(e.message)) ? "Fetching the URL timed out." : `Failed to fetch the URL: ${
|
|
3034
|
+
message: e instanceof Error && (e.name === "AbortError" || /abort/i.test(e.message)) ? "Fetching the URL timed out." : `Failed to fetch the URL: ${F(e)}`,
|
|
3034
3035
|
success: !1,
|
|
3035
3036
|
url: t.url
|
|
3036
3037
|
};
|
|
@@ -3038,7 +3039,7 @@ async function gr(e) {
|
|
|
3038
3039
|
clearTimeout(i);
|
|
3039
3040
|
}
|
|
3040
3041
|
}
|
|
3041
|
-
var
|
|
3042
|
+
var vr = e.strictObject({
|
|
3042
3043
|
count: e.number().int().min(1).max(15).default(6),
|
|
3043
3044
|
orientation: e.enum([
|
|
3044
3045
|
"landscape",
|
|
@@ -3046,8 +3047,8 @@ var _r = e.strictObject({
|
|
|
3046
3047
|
"square"
|
|
3047
3048
|
]).optional().describe("Preferred image orientation. Use landscape for hero/section backgrounds."),
|
|
3048
3049
|
query: e.string().trim().min(2).max(200).describe("What the photos should depict, e.g. \"herbal supplements\".")
|
|
3049
|
-
}),
|
|
3050
|
-
async function
|
|
3050
|
+
}), yr = 12e3;
|
|
3051
|
+
async function br(e) {
|
|
3051
3052
|
let t = null, n = null;
|
|
3052
3053
|
if (e) try {
|
|
3053
3054
|
let { CORTEX_AI_PEXELS_SETTING_KEY: r, CORTEX_AI_UNSPLASH_SETTING_KEY: i, decryptStoredOpenRouterApiKey: a } = await import("./ai-config.es.js"), o = (e) => {
|
|
@@ -3071,18 +3072,18 @@ async function yr(e) {
|
|
|
3071
3072
|
provider: "unsplash"
|
|
3072
3073
|
}), r;
|
|
3073
3074
|
}
|
|
3074
|
-
async function br(e) {
|
|
3075
|
-
return (await yr(e))[0] ?? null;
|
|
3076
|
-
}
|
|
3077
3075
|
async function xr(e) {
|
|
3076
|
+
return (await br(e))[0] ?? null;
|
|
3077
|
+
}
|
|
3078
|
+
async function Sr(e) {
|
|
3078
3079
|
if (e) try {
|
|
3079
3080
|
let { 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;
|
|
3080
3081
|
if (typeof r == "string" && r.trim()) return r.trim();
|
|
3081
3082
|
} catch {}
|
|
3082
3083
|
return process.env.UNSPLASH_APP_NAME?.trim() || null;
|
|
3083
3084
|
}
|
|
3084
|
-
async function
|
|
3085
|
-
let n = new AbortController(), r = setTimeout(() => n.abort(),
|
|
3085
|
+
async function Cr(e, t) {
|
|
3086
|
+
let n = new AbortController(), r = setTimeout(() => n.abort(), yr);
|
|
3086
3087
|
try {
|
|
3087
3088
|
let r = await fetch(e, {
|
|
3088
3089
|
headers: t,
|
|
@@ -3094,62 +3095,62 @@ async function Sr(e, t) {
|
|
|
3094
3095
|
clearTimeout(r);
|
|
3095
3096
|
}
|
|
3096
3097
|
}
|
|
3097
|
-
function
|
|
3098
|
+
function wr(e) {
|
|
3098
3099
|
let t = Number(e);
|
|
3099
3100
|
return Number.isFinite(t) && t > 0 ? t : null;
|
|
3100
3101
|
}
|
|
3101
|
-
function
|
|
3102
|
-
if (!
|
|
3102
|
+
function Tr(e, t) {
|
|
3103
|
+
if (!U(e)) return;
|
|
3103
3104
|
let n = (e) => {
|
|
3104
|
-
|
|
3105
|
+
U(e) && e.provider === "unsplash" && typeof e.downloadLocation == "string" && e.downloadLocation.trim() && t.add(e.downloadLocation.trim());
|
|
3105
3106
|
};
|
|
3106
|
-
if (n(e.attribution),
|
|
3107
|
-
for (let n of e.column_blocks) if (Array.isArray(n)) for (let e of n)
|
|
3107
|
+
if (n(e.attribution), U(e.background) && U(e.background.image) && n(e.background.image.attribution), Array.isArray(e.column_blocks)) {
|
|
3108
|
+
for (let n of e.column_blocks) if (Array.isArray(n)) for (let e of n) U(e) && Tr(e.content, t);
|
|
3108
3109
|
}
|
|
3109
|
-
if (Array.isArray(e.slides)) for (let n of e.slides)
|
|
3110
|
+
if (Array.isArray(e.slides)) for (let n of e.slides) Tr(n, t);
|
|
3110
3111
|
}
|
|
3111
|
-
async function
|
|
3112
|
+
async function Er(e, t) {
|
|
3112
3113
|
try {
|
|
3113
3114
|
let n = /* @__PURE__ */ new Set();
|
|
3114
|
-
for (let t of e)
|
|
3115
|
+
for (let t of e) Tr(t?.content, n);
|
|
3115
3116
|
if (n.size === 0) return;
|
|
3116
|
-
let r = (await
|
|
3117
|
+
let r = (await br(t)).find((e) => e.provider === "unsplash");
|
|
3117
3118
|
if (!r) return;
|
|
3118
3119
|
await Promise.all([...n].map((e) => fetch(e, { headers: { Authorization: `Client-ID ${r.apiKey}` } }).catch(() => void 0)));
|
|
3119
3120
|
} catch {}
|
|
3120
3121
|
}
|
|
3121
|
-
async function
|
|
3122
|
+
async function Dr(e, t, n) {
|
|
3122
3123
|
let r = new URLSearchParams({
|
|
3123
3124
|
per_page: String(t.count),
|
|
3124
3125
|
query: t.query
|
|
3125
3126
|
});
|
|
3126
3127
|
if (t.orientation && r.set("orientation", t.orientation), e.provider === "pexels") {
|
|
3127
|
-
let n = await
|
|
3128
|
+
let n = await Cr(`https://api.pexels.com/v1/search?${r.toString()}`, { Authorization: e.apiKey });
|
|
3128
3129
|
return (Array.isArray(n?.photos) ? n.photos : []).map((e) => {
|
|
3129
3130
|
let n = typeof e?.photographer == "string" ? e.photographer : null;
|
|
3130
3131
|
return {
|
|
3131
3132
|
alt: typeof e?.alt == "string" && e.alt.trim() ? e.alt.trim() : t.query,
|
|
3132
3133
|
credit: n ? `Photo by ${n} on Pexels` : "Photo on Pexels",
|
|
3133
3134
|
downloadLocation: null,
|
|
3134
|
-
height:
|
|
3135
|
+
height: wr(e?.height),
|
|
3135
3136
|
photographer: n,
|
|
3136
3137
|
photographerUrl: typeof e?.photographer_url == "string" ? e.photographer_url : null,
|
|
3137
3138
|
provider: "pexels",
|
|
3138
3139
|
sourceUrl: typeof e?.url == "string" ? e.url : null,
|
|
3139
3140
|
thumbnailUrl: e?.src?.medium || e?.src?.large || null,
|
|
3140
3141
|
url: e?.src?.large2x || e?.src?.large || e?.src?.original || null,
|
|
3141
|
-
width:
|
|
3142
|
+
width: wr(e?.width)
|
|
3142
3143
|
};
|
|
3143
3144
|
}).filter((e) => typeof e.url == "string");
|
|
3144
3145
|
}
|
|
3145
|
-
let i = await
|
|
3146
|
+
let i = await Cr(`https://api.unsplash.com/search/photos?${r.toString()}`, { Authorization: `Client-ID ${e.apiKey}` });
|
|
3146
3147
|
return (Array.isArray(i?.results) ? i.results : []).map((e) => {
|
|
3147
3148
|
let r = typeof e?.user?.name == "string" ? e.user.name : null;
|
|
3148
3149
|
return {
|
|
3149
3150
|
alt: typeof e?.alt_description == "string" && e.alt_description.trim() || typeof e?.description == "string" && e.description.trim() || t.query,
|
|
3150
3151
|
credit: r ? `Photo by ${r} on Unsplash` : "Photo on Unsplash",
|
|
3151
3152
|
downloadLocation: typeof e?.links?.download_location == "string" ? e.links.download_location : null,
|
|
3152
|
-
height:
|
|
3153
|
+
height: wr(e?.height),
|
|
3153
3154
|
photographer: r,
|
|
3154
3155
|
photographerUrl: typeof e?.user?.links?.html == "string" ? e.user.links.html : null,
|
|
3155
3156
|
provider: "unsplash",
|
|
@@ -3157,22 +3158,22 @@ async function Er(e, t, n) {
|
|
|
3157
3158
|
thumbnailUrl: e?.urls?.small || e?.urls?.thumb || null,
|
|
3158
3159
|
url: e?.urls?.regular || e?.urls?.full || e?.urls?.raw || null,
|
|
3159
3160
|
utmSource: n || null,
|
|
3160
|
-
width:
|
|
3161
|
+
width: wr(e?.width)
|
|
3161
3162
|
};
|
|
3162
3163
|
}).filter((e) => typeof e.url == "string");
|
|
3163
3164
|
}
|
|
3164
|
-
async function
|
|
3165
|
-
let n =
|
|
3165
|
+
async function Or(e, t) {
|
|
3166
|
+
let n = vr.parse(e), r = await br(t?.supabase);
|
|
3166
3167
|
if (r.length === 0) return {
|
|
3167
3168
|
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).",
|
|
3168
3169
|
photos: [],
|
|
3169
3170
|
success: !1
|
|
3170
3171
|
};
|
|
3171
|
-
let i = r.some((e) => e.provider === "unsplash") ? await
|
|
3172
|
+
let i = r.some((e) => e.provider === "unsplash") ? await Sr(t?.supabase) : null, a = [], o = null;
|
|
3172
3173
|
for (let e of r) {
|
|
3173
3174
|
a.push(e.provider);
|
|
3174
3175
|
try {
|
|
3175
|
-
let t = await
|
|
3176
|
+
let t = await Dr(e, n, i);
|
|
3176
3177
|
if (t.length > 0) return {
|
|
3177
3178
|
attemptedProviders: a,
|
|
3178
3179
|
photos: t,
|
|
@@ -3187,13 +3188,13 @@ async function Dr(e, t) {
|
|
|
3187
3188
|
}
|
|
3188
3189
|
return {
|
|
3189
3190
|
attemptedProviders: a,
|
|
3190
|
-
message: o ? `Stock photo search failed across ${a.join(", ")}: ${
|
|
3191
|
+
message: o ? `Stock photo search failed across ${a.join(", ")}: ${F(o)}` : `No matching stock photos found for "${n.query}".`,
|
|
3191
3192
|
photos: [],
|
|
3192
3193
|
success: !1
|
|
3193
3194
|
};
|
|
3194
3195
|
}
|
|
3195
|
-
var
|
|
3196
|
-
blocks: e.array(
|
|
3196
|
+
var kr = T.extend({
|
|
3197
|
+
blocks: e.array(le).min(1).max(20),
|
|
3197
3198
|
meta: e.strictObject({
|
|
3198
3199
|
meta_description: e.string().max(500).nullable().optional(),
|
|
3199
3200
|
meta_title: e.string().max(160).nullable().optional(),
|
|
@@ -3205,7 +3206,7 @@ var Or = T.extend({
|
|
|
3205
3206
|
]).optional(),
|
|
3206
3207
|
title: e.string().trim().min(1).max(300).optional()
|
|
3207
3208
|
}).partial().optional()
|
|
3208
|
-
}),
|
|
3209
|
+
}), Ar = [
|
|
3209
3210
|
"custom_canonical",
|
|
3210
3211
|
"excerpt",
|
|
3211
3212
|
"feature_image_id",
|
|
@@ -3220,26 +3221,26 @@ var Or = T.extend({
|
|
|
3220
3221
|
"title",
|
|
3221
3222
|
"translation_group_id"
|
|
3222
3223
|
];
|
|
3223
|
-
function
|
|
3224
|
+
function jr(e) {
|
|
3224
3225
|
let t = {};
|
|
3225
|
-
for (let n of
|
|
3226
|
+
for (let n of Ar) n in e && e[n] !== void 0 && (t[n] = e[n]);
|
|
3226
3227
|
return t;
|
|
3227
3228
|
}
|
|
3228
|
-
function
|
|
3229
|
+
function Mr(e, t) {
|
|
3229
3230
|
if (!t) return null;
|
|
3230
3231
|
let n = e === "page" ? t === "home" ? "/" : `/${t}` : `/article/${t}`;
|
|
3231
3232
|
return `/api/draft/start?path=${encodeURIComponent(n)}`;
|
|
3232
3233
|
}
|
|
3233
|
-
async function
|
|
3234
|
-
let n =
|
|
3235
|
-
t = await
|
|
3236
|
-
let r =
|
|
3234
|
+
async function Nr(e, t) {
|
|
3235
|
+
let n = kr.parse(e);
|
|
3236
|
+
t = await W(t, n.blocks);
|
|
3237
|
+
let r = j(t), i = Qe(t), a = await Y(n, t);
|
|
3237
3238
|
if (a.contentType === "product") throw Error("rewrite_page_draft supports pages and posts only. Products use description_json, not page blocks.");
|
|
3238
3239
|
let o = a.contentType, s = Number(a.item.id);
|
|
3239
3240
|
if (!Number.isInteger(s) || s <= 0) throw Error("Could not resolve a valid page/post id for the draft rewrite.");
|
|
3240
3241
|
let c = Number(a.item.language_id);
|
|
3241
3242
|
if (!Number.isInteger(c) || c <= 0) throw Error("The target page/post is missing a language id.");
|
|
3242
|
-
let l =
|
|
3243
|
+
let l = Zt(n.blocks, void 0, void 0, t).map((e, t) => ({
|
|
3243
3244
|
block_type: e.block_type,
|
|
3244
3245
|
content: e.content,
|
|
3245
3246
|
language_id: c,
|
|
@@ -3247,9 +3248,9 @@ async function Mr(e, t) {
|
|
|
3247
3248
|
page_id: o === "page" ? s : null,
|
|
3248
3249
|
post_id: o === "post" ? s : null,
|
|
3249
3250
|
product_id: null
|
|
3250
|
-
})), u =
|
|
3251
|
+
})), u = jr(a.item);
|
|
3251
3252
|
if (n.meta) for (let [e, t] of Object.entries(n.meta)) t !== void 0 && (u[e] = t);
|
|
3252
|
-
let d =
|
|
3253
|
+
let d = Ve(typeof u.slug == "string" ? u.slug : a.item.slug), f = typeof u.title == "string" && u.title.trim() ? u.title : String(a.item.title || d || "Untitled"), p = o === "page" ? `/cms/pages/${s}/edit` : `/cms/posts/${s}/edit`, m = Mr(o, d), h = z({
|
|
3253
3254
|
action: "REWRITE DRAFT",
|
|
3254
3255
|
context: t,
|
|
3255
3256
|
payload: {
|
|
@@ -3263,14 +3264,14 @@ async function Mr(e, t) {
|
|
|
3263
3264
|
blockCount: l.length,
|
|
3264
3265
|
contentType: o,
|
|
3265
3266
|
slug: d,
|
|
3266
|
-
summary: `Stage a Live Draft that replaces the ${o} "${f}" with ${
|
|
3267
|
+
summary: `Stage a Live Draft that replaces the ${o} "${f}" with ${R(l.length, "new block")}. Nothing goes live until you review the draft and click Publish (which also saves a revision snapshot).`,
|
|
3267
3268
|
title: f
|
|
3268
3269
|
},
|
|
3269
3270
|
subject: `${o}-${s}`
|
|
3270
3271
|
});
|
|
3271
3272
|
if (h) return h;
|
|
3272
3273
|
let g = Number(a.item.version) || 1, { error: _ } = await r.from("content_drafts").delete().eq("parent_type", o).eq("parent_id", s);
|
|
3273
|
-
if (_) throw Error(`Failed to clear the existing draft: ${
|
|
3274
|
+
if (_) throw Error(`Failed to clear the existing draft: ${F(_)}`);
|
|
3274
3275
|
let { error: v } = await r.from("content_drafts").insert({
|
|
3275
3276
|
author_id: i,
|
|
3276
3277
|
base_version: g,
|
|
@@ -3279,8 +3280,8 @@ async function Mr(e, t) {
|
|
|
3279
3280
|
parent_id: s,
|
|
3280
3281
|
parent_type: o
|
|
3281
3282
|
});
|
|
3282
|
-
if (v) throw Error(`Failed to save the draft: ${
|
|
3283
|
-
return
|
|
3283
|
+
if (v) throw Error(`Failed to save the draft: ${F(v)}`);
|
|
3284
|
+
return Er(l, r), P(t, {
|
|
3284
3285
|
contentType: o,
|
|
3285
3286
|
entityId: s,
|
|
3286
3287
|
languageId: c,
|
|
@@ -3299,7 +3300,7 @@ async function Mr(e, t) {
|
|
|
3299
3300
|
title: f
|
|
3300
3301
|
};
|
|
3301
3302
|
}
|
|
3302
|
-
var
|
|
3303
|
+
var Pr = e.strictObject({
|
|
3303
3304
|
attributes: e.array(e.strictObject({
|
|
3304
3305
|
name: e.string().trim().min(1).max(120).describe("Attribute name, e.g. \"Size\" or \"Flavour\"."),
|
|
3305
3306
|
terms: e.array(e.string().trim().min(1).max(120)).min(1).max(50).describe("Every possible value for this attribute, e.g. [\"100 ml\", \"500 ml\"].")
|
|
@@ -3318,19 +3319,19 @@ var Nr = e.strictObject({
|
|
|
3318
3319
|
upc: e.string().trim().max(120).nullable().optional()
|
|
3319
3320
|
})).min(1).max(50)
|
|
3320
3321
|
});
|
|
3321
|
-
async function
|
|
3322
|
-
let n =
|
|
3322
|
+
async function Fr(e, t) {
|
|
3323
|
+
let n = B(t.name), { data: r } = await e.from("product_attributes").select("id").eq("slug", n).maybeSingle(), i = r?.id;
|
|
3323
3324
|
if (!i) {
|
|
3324
3325
|
let { data: r, error: a } = await e.from("product_attributes").insert({
|
|
3325
3326
|
name: t.name,
|
|
3326
3327
|
slug: n
|
|
3327
3328
|
}).select("id").single();
|
|
3328
|
-
if (a || !r?.id) throw Error(`Could not create the "${t.name}" attribute: ${
|
|
3329
|
+
if (a || !r?.id) throw Error(`Could not create the "${t.name}" attribute: ${F(a)}`);
|
|
3329
3330
|
i = r.id;
|
|
3330
3331
|
}
|
|
3331
3332
|
let a = /* @__PURE__ */ new Map();
|
|
3332
3333
|
for (let n = 0; n < t.terms.length; n += 1) {
|
|
3333
|
-
let r = t.terms[n], o =
|
|
3334
|
+
let r = t.terms[n], o = B(r), { data: s } = await e.from("product_attribute_terms").select("id").eq("attribute_id", i).eq("slug", o).maybeSingle();
|
|
3334
3335
|
if (s?.id) {
|
|
3335
3336
|
a.set(r, s.id);
|
|
3336
3337
|
continue;
|
|
@@ -3341,7 +3342,7 @@ async function Pr(e, t) {
|
|
|
3341
3342
|
sort_order: n,
|
|
3342
3343
|
value: r
|
|
3343
3344
|
}).select("id").single();
|
|
3344
|
-
if (l || !c?.id) throw Error(`Could not create the "${r}" option: ${
|
|
3345
|
+
if (l || !c?.id) throw Error(`Could not create the "${r}" option: ${F(l)}`);
|
|
3345
3346
|
a.set(r, c.id);
|
|
3346
3347
|
}
|
|
3347
3348
|
return {
|
|
@@ -3349,13 +3350,13 @@ async function Pr(e, t) {
|
|
|
3349
3350
|
termIdByValue: a
|
|
3350
3351
|
};
|
|
3351
3352
|
}
|
|
3352
|
-
async function
|
|
3353
|
-
let n =
|
|
3353
|
+
async function Ir(e, t) {
|
|
3354
|
+
let n = Pr.parse(e), r = j(t), i = (await Y({
|
|
3354
3355
|
contentType: "product",
|
|
3355
3356
|
...n.entityId === void 0 ? {} : { entityId: n.entityId },
|
|
3356
3357
|
...n.slug ? { slug: n.slug } : {},
|
|
3357
3358
|
...n.title ? { title: n.title } : {}
|
|
3358
|
-
}, t)).item, a = String(i.id), o =
|
|
3359
|
+
}, t)).item, a = String(i.id), o = z({
|
|
3359
3360
|
action: "SET VARIANTS",
|
|
3360
3361
|
context: t,
|
|
3361
3362
|
payload: {
|
|
@@ -3366,7 +3367,7 @@ async function Fr(e, t) {
|
|
|
3366
3367
|
preview: {
|
|
3367
3368
|
contentType: "product",
|
|
3368
3369
|
slug: i.slug,
|
|
3369
|
-
summary: `${n.mode === "replace" ? "Replace" : "Add"} ${
|
|
3370
|
+
summary: `${n.mode === "replace" ? "Replace" : "Add"} ${R(n.variants.length, "variant")} on "${i.title}". Product stock becomes the sum of variant stock.`,
|
|
3370
3371
|
title: i.title
|
|
3371
3372
|
},
|
|
3372
3373
|
subject: `product-${a}-variants`
|
|
@@ -3374,47 +3375,47 @@ async function Fr(e, t) {
|
|
|
3374
3375
|
if (o) return o;
|
|
3375
3376
|
let s = /* @__PURE__ */ new Map();
|
|
3376
3377
|
for (let e of n.attributes ?? []) {
|
|
3377
|
-
let { termIdByValue: t } = await
|
|
3378
|
+
let { termIdByValue: t } = await Fr(r, e);
|
|
3378
3379
|
s.set(e.name, t);
|
|
3379
3380
|
}
|
|
3380
3381
|
for (let e of n.variants) for (let [t, n] of Object.entries(e.options)) {
|
|
3381
3382
|
if (s.get(t)?.has(n)) continue;
|
|
3382
|
-
let { data: e } = await r.from("product_attributes").select("id").eq("slug",
|
|
3383
|
+
let { data: e } = await r.from("product_attributes").select("id").eq("slug", B(t)).maybeSingle();
|
|
3383
3384
|
if (!e?.id) throw Error(`Unknown attribute "${t}". Pass it in \`attributes\` with its full list of terms.`);
|
|
3384
|
-
let { data: i } = await r.from("product_attribute_terms").select("id").eq("attribute_id", e.id).eq("slug",
|
|
3385
|
+
let { data: i } = await r.from("product_attribute_terms").select("id").eq("attribute_id", e.id).eq("slug", B(n)).maybeSingle();
|
|
3385
3386
|
if (!i?.id) throw Error(`Unknown option "${n}" for attribute "${t}". Add it to that attribute's \`terms\`.`);
|
|
3386
3387
|
let a = s.get(t) ?? /* @__PURE__ */ new Map();
|
|
3387
3388
|
a.set(n, i.id), s.set(t, a);
|
|
3388
3389
|
}
|
|
3389
3390
|
if (n.mode === "replace") {
|
|
3390
3391
|
let { error: e } = await r.from("product_variants").delete().eq("product_id", a);
|
|
3391
|
-
if (e) throw Error(`Could not clear the existing variants: ${
|
|
3392
|
+
if (e) throw Error(`Could not clear the existing variants: ${F(e)}`);
|
|
3392
3393
|
}
|
|
3393
|
-
let c = await
|
|
3394
|
+
let c = await Ct(r), l = Number(i.price) || 0, u = [];
|
|
3394
3395
|
for (let e of n.variants) {
|
|
3395
|
-
let n = e.image ? await
|
|
3396
|
+
let n = e.image ? await N(e.image, t, `${i.title} ${e.sku}`) : null, { data: o, error: d } = await r.from("product_variants").insert({
|
|
3396
3397
|
main_media_id: n,
|
|
3397
|
-
price: e.price === void 0 ? l :
|
|
3398
|
+
price: e.price === void 0 ? l : rt(e.price, c),
|
|
3398
3399
|
product_id: a,
|
|
3399
|
-
sale_price: e.sale_price === void 0 || e.sale_price === null ? null :
|
|
3400
|
+
sale_price: e.sale_price === void 0 || e.sale_price === null ? null : rt(e.sale_price, c),
|
|
3400
3401
|
sku: e.sku,
|
|
3401
3402
|
stock_quantity: e.stock,
|
|
3402
3403
|
upc: e.upc ?? null
|
|
3403
3404
|
}).select("id").single();
|
|
3404
|
-
if (d || !o?.id) throw Error(`Could not create variant "${e.sku}": ${
|
|
3405
|
+
if (d || !o?.id) throw Error(`Could not create variant "${e.sku}": ${F(d)}`);
|
|
3405
3406
|
let f = Object.entries(e.options).map(([e, t]) => ({
|
|
3406
3407
|
attribute_term_id: s.get(e)?.get(t),
|
|
3407
3408
|
variant_id: o.id
|
|
3408
3409
|
}));
|
|
3409
3410
|
if (f.length > 0) {
|
|
3410
3411
|
let { error: t } = await r.from("variant_attribute_mapping").insert(f);
|
|
3411
|
-
if (t) throw Error(`Could not link variant "${e.sku}" to its options: ${
|
|
3412
|
+
if (t) throw Error(`Could not link variant "${e.sku}" to its options: ${F(t)}`);
|
|
3412
3413
|
}
|
|
3413
3414
|
u.push(e.sku);
|
|
3414
3415
|
}
|
|
3415
3416
|
let { data: d } = await r.from("product_variants").select("stock_quantity").eq("product_id", a), f = (d ?? []).reduce((e, t) => e + (Number(t?.stock_quantity) || 0), 0), { error: p } = await r.from("products").update({ stock: f }).eq("id", a);
|
|
3416
|
-
if (p) throw Error(`Variants saved, but the product stock total failed: ${
|
|
3417
|
-
return
|
|
3417
|
+
if (p) throw Error(`Variants saved, but the product stock total failed: ${F(p)}`);
|
|
3418
|
+
return P(t, {
|
|
3418
3419
|
contentType: "product",
|
|
3419
3420
|
entityId: a,
|
|
3420
3421
|
slug: i.slug,
|
|
@@ -3431,7 +3432,7 @@ async function Fr(e, t) {
|
|
|
3431
3432
|
variantCount: u.length
|
|
3432
3433
|
};
|
|
3433
3434
|
}
|
|
3434
|
-
var
|
|
3435
|
+
var Lr = e.strictObject({
|
|
3435
3436
|
items: e.array(e.strictObject({
|
|
3436
3437
|
contentType: e.enum(["page", "post"]).default("page"),
|
|
3437
3438
|
slug: e.string().trim().min(1).max(300).describe("Slug of the source page or post."),
|
|
@@ -3440,8 +3441,8 @@ var Ir = e.strictObject({
|
|
|
3440
3441
|
})).min(1).max(25),
|
|
3441
3442
|
targetLanguageCode: e.string().trim().min(2).max(80).describe("Target language code or name, e.g. \"fr\". The language must already exist — create it with manage_language first.")
|
|
3442
3443
|
});
|
|
3443
|
-
async function
|
|
3444
|
-
let n =
|
|
3444
|
+
async function Rr(e, t) {
|
|
3445
|
+
let n = Lr.parse(e), r = z({
|
|
3445
3446
|
action: "TRANSLATE BULK",
|
|
3446
3447
|
context: t,
|
|
3447
3448
|
payload: {
|
|
@@ -3450,7 +3451,7 @@ async function Lr(e, t) {
|
|
|
3450
3451
|
},
|
|
3451
3452
|
preview: {
|
|
3452
3453
|
contentType: "page",
|
|
3453
|
-
summary: `Create ${n.targetLanguageCode} translations of ${
|
|
3454
|
+
summary: `Create ${n.targetLanguageCode} translations of ${R(n.items.length, "item")}: ${n.items.map((e) => e.slug).join(", ")}.`,
|
|
3454
3455
|
title: `Bulk translate to ${n.targetLanguageCode}`
|
|
3455
3456
|
},
|
|
3456
3457
|
subject: `bulk-translate-${n.targetLanguageCode}`
|
|
@@ -3458,7 +3459,7 @@ async function Lr(e, t) {
|
|
|
3458
3459
|
if (r) return r;
|
|
3459
3460
|
let i = [], a = [];
|
|
3460
3461
|
for (let e of n.items) try {
|
|
3461
|
-
let r = await
|
|
3462
|
+
let r = await Jr({
|
|
3462
3463
|
cmsTarget: {
|
|
3463
3464
|
contentType: e.contentType,
|
|
3464
3465
|
slug: e.slug
|
|
@@ -3487,28 +3488,28 @@ async function Lr(e, t) {
|
|
|
3487
3488
|
translatedCount: i.length
|
|
3488
3489
|
};
|
|
3489
3490
|
}
|
|
3490
|
-
var
|
|
3491
|
+
var zr = e.strictObject({
|
|
3491
3492
|
action: e.enum(["publish", "discard"]).default("publish").describe("\"publish\" applies the draft to the live page/post; \"discard\" deletes it and leaves the live content untouched."),
|
|
3492
3493
|
contentType: e.enum(["page", "post"]).optional(),
|
|
3493
3494
|
entityId: e.union([e.number().int().positive(), e.string().trim().min(1).max(120)]).optional(),
|
|
3494
3495
|
slug: e.string().trim().min(1).max(300).optional(),
|
|
3495
3496
|
title: e.string().trim().min(1).max(300).optional()
|
|
3496
|
-
}),
|
|
3497
|
+
}), Br = ["title", "slug"], Vr = [
|
|
3497
3498
|
"custom_canonical",
|
|
3498
3499
|
"feature_image_id",
|
|
3499
3500
|
"meta_description",
|
|
3500
3501
|
"meta_title"
|
|
3501
3502
|
];
|
|
3502
|
-
async function
|
|
3503
|
-
let n =
|
|
3503
|
+
async function Hr(e, t) {
|
|
3504
|
+
let n = zr.parse(e), r = j(t), i = await X({
|
|
3504
3505
|
...n.contentType ? { contentType: n.contentType } : {},
|
|
3505
3506
|
...n.entityId === void 0 ? {} : { entityId: n.entityId },
|
|
3506
3507
|
...n.slug ? { slug: n.slug } : {},
|
|
3507
3508
|
...n.title ? { title: n.title } : {}
|
|
3508
3509
|
}, t);
|
|
3509
3510
|
if (i.contentType === "product") throw Error("publish_content_draft supports pages and posts. Product drafts live in product_drafts and are published from the product editor.");
|
|
3510
|
-
let a = i.contentType, o =
|
|
3511
|
-
if (l) throw Error(`Failed to read the draft: ${
|
|
3511
|
+
let a = i.contentType, o = Pe(i), s = a === "page" ? "pages" : "posts", { data: c, error: l } = await r.from("content_drafts").select("*").eq("parent_type", a).eq("parent_id", o).maybeSingle();
|
|
3512
|
+
if (l) throw Error(`Failed to read the draft: ${F(l)}`);
|
|
3512
3513
|
if (!c) return {
|
|
3513
3514
|
contentType: a,
|
|
3514
3515
|
entityId: o,
|
|
@@ -3516,7 +3517,7 @@ async function Vr(e, t) {
|
|
|
3516
3517
|
mutationExecuted: !1,
|
|
3517
3518
|
success: !1
|
|
3518
3519
|
};
|
|
3519
|
-
let u = i.title || i.slug || `${a} ${o}`, d =
|
|
3520
|
+
let u = i.title || i.slug || `${a} ${o}`, d = z({
|
|
3520
3521
|
action: n.action === "publish" ? "PUBLISH DRAFT" : "DISCARD DRAFT",
|
|
3521
3522
|
context: t,
|
|
3522
3523
|
payload: {
|
|
@@ -3536,8 +3537,8 @@ async function Vr(e, t) {
|
|
|
3536
3537
|
let f = c.meta ?? {}, p = Array.isArray(c.blocks) ? c.blocks : [];
|
|
3537
3538
|
if (n.action === "discard") {
|
|
3538
3539
|
let { error: e } = await r.from("content_drafts").delete().eq("id", c.id);
|
|
3539
|
-
if (e) throw Error(`Failed to discard the draft: ${
|
|
3540
|
-
return
|
|
3540
|
+
if (e) throw Error(`Failed to discard the draft: ${F(e)}`);
|
|
3541
|
+
return P(t, i, i.slug), {
|
|
3541
3542
|
action: "discard",
|
|
3542
3543
|
contentType: a,
|
|
3543
3544
|
entityId: o,
|
|
@@ -3545,21 +3546,21 @@ async function Vr(e, t) {
|
|
|
3545
3546
|
success: !0
|
|
3546
3547
|
};
|
|
3547
3548
|
}
|
|
3548
|
-
let m = await
|
|
3549
|
-
for (let e of
|
|
3549
|
+
let m = await _(t, a, o), h = {};
|
|
3550
|
+
for (let e of Br) {
|
|
3550
3551
|
let t = f[e];
|
|
3551
3552
|
typeof t == "string" && t.trim() && (h[e] = t.trim());
|
|
3552
3553
|
}
|
|
3553
|
-
for (let e of
|
|
3554
|
+
for (let e of Vr) if (Object.prototype.hasOwnProperty.call(f, e)) {
|
|
3554
3555
|
let t = f[e];
|
|
3555
3556
|
h[e] = typeof t == "string" && t.trim() ? t.trim() : null;
|
|
3556
3557
|
}
|
|
3557
3558
|
if (Object.keys(h).length > 0) {
|
|
3558
3559
|
let { error: e } = await r.from(s).update(h).eq("id", o);
|
|
3559
|
-
if (e) throw Error(`Failed to apply the draft metadata: ${
|
|
3560
|
+
if (e) throw Error(`Failed to apply the draft metadata: ${F(e)}`);
|
|
3560
3561
|
}
|
|
3561
|
-
let
|
|
3562
|
-
if (y) throw Error(`Failed to clear the live blocks: ${
|
|
3562
|
+
let g = a === "page" ? "page_id" : "post_id", { error: y } = await r.from("blocks").delete().eq(g, o);
|
|
3563
|
+
if (y) throw Error(`Failed to clear the live blocks: ${F(y)}`);
|
|
3563
3564
|
let b = Number(f.language_id) || Number(i.languageId) || Number(p[0]?.language_id) || 0;
|
|
3564
3565
|
if (p.length > 0) {
|
|
3565
3566
|
let e = p.map((e, t) => ({
|
|
@@ -3571,11 +3572,11 @@ async function Vr(e, t) {
|
|
|
3571
3572
|
post_id: a === "post" ? o : null,
|
|
3572
3573
|
product_id: null
|
|
3573
3574
|
})), { error: t } = await r.from("blocks").insert(e);
|
|
3574
|
-
if (t) throw Error(`Failed to publish the draft blocks: ${
|
|
3575
|
+
if (t) throw Error(`Failed to publish the draft blocks: ${F(t)}`);
|
|
3575
3576
|
}
|
|
3576
|
-
await
|
|
3577
|
+
await v(t, a, o, m);
|
|
3577
3578
|
let { error: x } = await r.from("content_drafts").delete().eq("id", c.id), S = typeof h.slug == "string" ? h.slug : i.slug;
|
|
3578
|
-
return
|
|
3579
|
+
return P(t, {
|
|
3579
3580
|
...i,
|
|
3580
3581
|
slug: S
|
|
3581
3582
|
}, S ?? void 0), {
|
|
@@ -3586,10 +3587,10 @@ async function Vr(e, t) {
|
|
|
3586
3587
|
mutationExecuted: !0,
|
|
3587
3588
|
slug: S,
|
|
3588
3589
|
success: !0,
|
|
3589
|
-
...x ? { warning: `Published, but the draft row was not removed: ${
|
|
3590
|
+
...x ? { warning: `Published, but the draft row was not removed: ${F(x)}` } : {}
|
|
3590
3591
|
};
|
|
3591
3592
|
}
|
|
3592
|
-
var
|
|
3593
|
+
var Ur = /* @__PURE__ */ new Set([
|
|
3593
3594
|
"alt_text",
|
|
3594
3595
|
"author_name",
|
|
3595
3596
|
"author_title",
|
|
@@ -3604,7 +3605,7 @@ var Hr = /* @__PURE__ */ new Set([
|
|
|
3604
3605
|
"text_content",
|
|
3605
3606
|
"title"
|
|
3606
3607
|
]);
|
|
3607
|
-
function
|
|
3608
|
+
function Wr(e, t, n) {
|
|
3608
3609
|
if (!e) return e;
|
|
3609
3610
|
if (Object.prototype.hasOwnProperty.call(t, e)) return t[e];
|
|
3610
3611
|
let r = e.trim();
|
|
@@ -3613,41 +3614,41 @@ function Ur(e, t, n) {
|
|
|
3613
3614
|
for (let [e, t] of n) e && i.includes(e) && (i = i.split(e).join(t));
|
|
3614
3615
|
return i;
|
|
3615
3616
|
}
|
|
3616
|
-
function
|
|
3617
|
-
if (Array.isArray(e)) return e.map((e) =>
|
|
3617
|
+
function Gr(e, t, n, r) {
|
|
3618
|
+
if (Array.isArray(e)) return e.map((e) => Gr(e, t, n, r));
|
|
3618
3619
|
if (e && typeof e == "object") {
|
|
3619
3620
|
let i = {};
|
|
3620
|
-
for (let [a, o] of Object.entries(e)) i[a] = typeof o == "string" && (
|
|
3621
|
+
for (let [a, o] of Object.entries(e)) i[a] = typeof o == "string" && (Ur.has(a) || r?.has(a)) ? Wr(o, t, n) : o && typeof o == "object" ? Gr(o, t, n, r) : o;
|
|
3621
3622
|
return i;
|
|
3622
3623
|
}
|
|
3623
3624
|
return e;
|
|
3624
3625
|
}
|
|
3625
|
-
function
|
|
3626
|
+
function Kr(e, t) {
|
|
3626
3627
|
if (typeof e != "string" || r(e)) return;
|
|
3627
|
-
let n =
|
|
3628
|
+
let n = st(e, t);
|
|
3628
3629
|
if (n) return new Set(a(n).filter((e) => e.type === "text" || e.type === "rich-text").map((e) => e.key));
|
|
3629
3630
|
}
|
|
3630
|
-
var
|
|
3631
|
-
cmsTarget:
|
|
3631
|
+
var qr = e.strictObject({
|
|
3632
|
+
cmsTarget: E,
|
|
3632
3633
|
targetLanguageCode: e.string().trim().min(2).max(80).describe("Target language code or name, e.g. \"fr\" or \"French\"."),
|
|
3633
3634
|
title: e.string().trim().min(1).max(300).optional().describe("Translated page title (defaults to translating the source title)."),
|
|
3634
3635
|
translations: e.record(e.string(), e.string()).describe("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.")
|
|
3635
3636
|
});
|
|
3636
|
-
async function
|
|
3637
|
-
let n =
|
|
3637
|
+
async function Jr(e, t) {
|
|
3638
|
+
let n = qr.parse(e), r = await X(n.cmsTarget, t);
|
|
3638
3639
|
if (r.contentType === "product") throw Error("translate_page supports pages and posts only.");
|
|
3639
|
-
let i =
|
|
3640
|
-
if (l || !c) throw Error(`Could not read the source ${r.contentType} to translate: ${
|
|
3640
|
+
let i = j(t), a = Pe(r), o = r.contentType === "page" ? "pages" : "posts", s = r.contentType === "page" ? "page_id" : "post_id", { data: c, error: l } = await i.from(o).select("*").eq("id", a).single();
|
|
3641
|
+
if (l || !c) throw Error(`Could not read the source ${r.contentType} to translate: ${F(l)}`);
|
|
3641
3642
|
let { data: u, error: d } = await i.from("blocks").select("id, block_type, content, order").eq(s, a);
|
|
3642
|
-
if (d) throw Error(`Could not read the source blocks: ${
|
|
3643
|
+
if (d) throw Error(`Could not read the source blocks: ${F(d)}`);
|
|
3643
3644
|
let f = (Array.isArray(u) ? u : []).slice().sort((e, t) => Number(e.order) - Number(t.order));
|
|
3644
3645
|
if (f.length === 0) throw Error(`The source ${r.contentType} has no content blocks to translate.`);
|
|
3645
|
-
t = await
|
|
3646
|
+
t = await W(t, f);
|
|
3646
3647
|
let p = n.translations || {}, m = Object.entries(p).filter(([e]) => !!e).sort((e, t) => t[0].length - e[0].length), h = f.map((e, n) => ({
|
|
3647
3648
|
blockType: e.block_type,
|
|
3648
|
-
content:
|
|
3649
|
+
content: Gr(H(e.content), p, m, Kr(e.block_type, t)),
|
|
3649
3650
|
order: n
|
|
3650
|
-
})), g = await
|
|
3651
|
+
})), g = await St(i, n.targetLanguageCode), _ = String(c.title || ""), v = n.title || Wr(_, p, m) || _ || "Untitled", y = (e) => typeof e == "string" && e.trim() ? Wr(e, p, m) : void 0, b = B(v) || c.slug || "translated-page", x = {
|
|
3651
3652
|
blocks: h,
|
|
3652
3653
|
feature_image_id: c.feature_image_id ?? void 0,
|
|
3653
3654
|
languageCode: g.code,
|
|
@@ -3663,7 +3664,7 @@ async function qr(e, t) {
|
|
|
3663
3664
|
label: y(c.label),
|
|
3664
3665
|
published_at: c.published_at ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
3665
3666
|
subtitle: y(c.subtitle)
|
|
3666
|
-
} : x, C =
|
|
3667
|
+
} : x, C = z({
|
|
3667
3668
|
action: "TRANSLATE",
|
|
3668
3669
|
context: t,
|
|
3669
3670
|
payload: {
|
|
@@ -3677,24 +3678,24 @@ async function qr(e, t) {
|
|
|
3677
3678
|
languageCode: g.code,
|
|
3678
3679
|
slug: x.slug,
|
|
3679
3680
|
status: x.status,
|
|
3680
|
-
summary: `Publish a ${g.code.toUpperCase()} translation of "${_}" — it goes live immediately, linked to the original ${r.contentType}, at /${x.slug} with ${
|
|
3681
|
+
summary: `Publish a ${g.code.toUpperCase()} translation of "${_}" — it goes live immediately, linked to the original ${r.contentType}, at /${x.slug} with ${R(h.length, "translated block")}.`,
|
|
3681
3682
|
title: v
|
|
3682
3683
|
},
|
|
3683
3684
|
subject: `translate ${r.contentType} ${c.id} to ${g.code}`
|
|
3684
3685
|
});
|
|
3685
3686
|
if (C) return C;
|
|
3686
|
-
let
|
|
3687
|
+
let ee = {
|
|
3687
3688
|
...t,
|
|
3688
3689
|
skipConfirmation: !0
|
|
3689
3690
|
};
|
|
3690
3691
|
return {
|
|
3691
|
-
...r.contentType === "post" ? await
|
|
3692
|
+
...r.contentType === "post" ? await Nn(S, ee) : await Mn(S, ee),
|
|
3692
3693
|
isTranslation: !0,
|
|
3693
3694
|
languageCode: g.code
|
|
3694
3695
|
};
|
|
3695
3696
|
}
|
|
3696
|
-
async function
|
|
3697
|
-
let n =
|
|
3697
|
+
async function Yr(e, t) {
|
|
3698
|
+
let n = ue.parse(e), r = n.entityId !== void 0 || !!n.slug || !!n.title, i = j(t), a, o;
|
|
3698
3699
|
if (r) {
|
|
3699
3700
|
let e = await Y({
|
|
3700
3701
|
contentType: n.contentType,
|
|
@@ -3708,8 +3709,8 @@ async function Jr(e, t) {
|
|
|
3708
3709
|
slug: typeof r.slug == "string" ? r.slug : "",
|
|
3709
3710
|
title: typeof r.title == "string" ? r.title : ""
|
|
3710
3711
|
};
|
|
3711
|
-
} else a =
|
|
3712
|
-
let s = a.title || a.slug || "current item", c = a.contentType === "product", l =
|
|
3712
|
+
} else a = Ne(t), o = M(a);
|
|
3713
|
+
let s = a.title || a.slug || "current item", c = a.contentType === "product", l = z({
|
|
3713
3714
|
action: "SET IMAGES",
|
|
3714
3715
|
context: t,
|
|
3715
3716
|
payload: {
|
|
@@ -3722,23 +3723,23 @@ async function Jr(e, t) {
|
|
|
3722
3723
|
contentType: a.contentType,
|
|
3723
3724
|
imageCount: n.images.length,
|
|
3724
3725
|
slug: a.slug,
|
|
3725
|
-
summary: c ? `Set ${
|
|
3726
|
+
summary: c ? `Set ${R(n.images.length, "image")} on product "${s}" (the first becomes the main product image, the rest the gallery).` : `Set the feature image on the ${a.contentType} "${s}".`,
|
|
3726
3727
|
title: a.title
|
|
3727
3728
|
},
|
|
3728
3729
|
subject: `set images on ${a.contentType} ${String(o)}`
|
|
3729
3730
|
});
|
|
3730
3731
|
if (l) return l;
|
|
3731
|
-
let u = await
|
|
3732
|
+
let u = await Re(n.images, t, s);
|
|
3732
3733
|
if (u.length === 0) throw Error("None of the provided images could be resolved to a media item.");
|
|
3733
3734
|
if (c) {
|
|
3734
3735
|
let { data: e, error: n } = await i.from("products").select("id, slug, language_id, title").eq("id", o).maybeSingle();
|
|
3735
|
-
if (n || !e) throw Error(`Could not load the product to set images: ${
|
|
3736
|
-
let r = await
|
|
3736
|
+
if (n || !e) throw Error(`Could not load the product to set images: ${F(n)}`);
|
|
3737
|
+
let r = await ze({
|
|
3737
3738
|
mediaIds: u,
|
|
3738
3739
|
productId: o,
|
|
3739
3740
|
supabase: i
|
|
3740
3741
|
});
|
|
3741
|
-
return await
|
|
3742
|
+
return await Be({
|
|
3742
3743
|
patch: ({ meta: e }) => Array.isArray(e.product_media) ? { meta: {
|
|
3743
3744
|
...e,
|
|
3744
3745
|
product_media: r.map((e, t) => ({
|
|
@@ -3748,7 +3749,7 @@ async function Jr(e, t) {
|
|
|
3748
3749
|
} } : {},
|
|
3749
3750
|
productId: o,
|
|
3750
3751
|
supabase: i
|
|
3751
|
-
}),
|
|
3752
|
+
}), P(t, {
|
|
3752
3753
|
contentType: "product",
|
|
3753
3754
|
entityId: String(o),
|
|
3754
3755
|
languageId: e.language_id,
|
|
@@ -3763,12 +3764,12 @@ async function Jr(e, t) {
|
|
|
3763
3764
|
success: !0
|
|
3764
3765
|
};
|
|
3765
3766
|
}
|
|
3766
|
-
let d = await
|
|
3767
|
+
let d = await _(t, a.contentType, o), f = a.contentType === "page" ? "pages" : "posts", { data: p, error: m } = await i.from(f).update({
|
|
3767
3768
|
feature_image_id: u[0],
|
|
3768
3769
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
3769
3770
|
}).eq("id", o).select("id, language_id, slug, status, title").single();
|
|
3770
|
-
if (m || !p) throw Error(`Failed to set the feature image: ${
|
|
3771
|
-
return await
|
|
3771
|
+
if (m || !p) throw Error(`Failed to set the feature image: ${F(m)}`);
|
|
3772
|
+
return await v(t, a.contentType, o, d), P(t, a, p.slug), {
|
|
3772
3773
|
contentType: a.contentType,
|
|
3773
3774
|
entityId: o,
|
|
3774
3775
|
extraImagesIgnored: u.length - 1,
|
|
@@ -3778,158 +3779,158 @@ async function Jr(e, t) {
|
|
|
3778
3779
|
success: !0
|
|
3779
3780
|
};
|
|
3780
3781
|
}
|
|
3781
|
-
function
|
|
3782
|
+
function Xr(e) {
|
|
3782
3783
|
return {
|
|
3783
3784
|
...c(e),
|
|
3784
3785
|
...t(e),
|
|
3785
|
-
...
|
|
3786
|
+
...p(e),
|
|
3786
3787
|
...l(e),
|
|
3787
3788
|
...u(e),
|
|
3788
|
-
fetch_ecommerce_stats:
|
|
3789
|
+
fetch_ecommerce_stats: h({
|
|
3789
3790
|
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.",
|
|
3790
|
-
execute: (t) =>
|
|
3791
|
-
inputSchema:
|
|
3791
|
+
execute: (t) => vn(t, e),
|
|
3792
|
+
inputSchema: re,
|
|
3792
3793
|
strict: !0
|
|
3793
3794
|
}),
|
|
3794
|
-
read_current_cms_item:
|
|
3795
|
+
read_current_cms_item: h({
|
|
3795
3796
|
description: "Read a CMS item: page/post/product metadata plus page/post block summaries or content. Defaults to the item currently open in the CMS editor; with no editor open (MCP clients) pass `cmsTarget` with contentType plus slug, entityId, or title. Read-only.",
|
|
3796
|
-
execute: (t) =>
|
|
3797
|
+
execute: (t) => yn(t, e),
|
|
3797
3798
|
inputSchema: oe,
|
|
3798
3799
|
strict: !0
|
|
3799
3800
|
}),
|
|
3800
|
-
search_documentation:
|
|
3801
|
+
search_documentation: h({
|
|
3801
3802
|
description: "Search the NextBlock documentation database and return concise source snippets for factual CMS guidance.",
|
|
3802
|
-
execute: (t) =>
|
|
3803
|
-
inputSchema:
|
|
3803
|
+
execute: (t) => dn(t, e),
|
|
3804
|
+
inputSchema: ne,
|
|
3804
3805
|
strict: !0
|
|
3805
3806
|
}),
|
|
3806
|
-
fetch_url_content:
|
|
3807
|
+
fetch_url_content: h({
|
|
3807
3808
|
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.",
|
|
3808
|
-
execute: (e) =>
|
|
3809
|
-
inputSchema:
|
|
3809
|
+
execute: (e) => _r(e),
|
|
3810
|
+
inputSchema: nr,
|
|
3810
3811
|
strict: !0
|
|
3811
3812
|
}),
|
|
3812
|
-
search_stock_photos:
|
|
3813
|
+
search_stock_photos: h({
|
|
3813
3814
|
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 (copy `width` and `height` into the same image content, so the page does not shift while the photo loads) 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.",
|
|
3814
|
-
execute: (t) =>
|
|
3815
|
-
inputSchema:
|
|
3815
|
+
execute: (t) => Or(t, e),
|
|
3816
|
+
inputSchema: vr,
|
|
3816
3817
|
strict: !0
|
|
3817
3818
|
}),
|
|
3818
|
-
manage_product_variants:
|
|
3819
|
+
manage_product_variants: h({
|
|
3819
3820
|
description: "Give a product sellable variations — size, flavour, colour, format — each with its own SKU, price, stock, and optional image. Define the option axes in `attributes` (name plus every term) and one entry in `variants` per purchasable combination, naming its term per attribute in `options`. Attributes and terms are global and reused across products, so an existing \"Size\" is matched rather than duplicated. Prices are in major units (25 = $25.00). The product's stock becomes the sum of its variants. Use mode \"replace\" to rebuild the variant set, \"append\" to add to it. Mutating: first returns a confirmation phrase; only executes after exact confirmation.",
|
|
3820
|
-
execute: (t) =>
|
|
3821
|
-
inputSchema:
|
|
3821
|
+
execute: (t) => Ir(t, e),
|
|
3822
|
+
inputSchema: Pr,
|
|
3822
3823
|
strict: !0
|
|
3823
3824
|
}),
|
|
3824
|
-
translate_content_bulk:
|
|
3825
|
+
translate_content_bulk: h({
|
|
3825
3826
|
description: "Translate SEVERAL pages or posts into one language in a single call. Use this instead of repeating translate_page when making a site multilingual: pass the target language once and one entry per item, each with its own source-string -> translation map. Layout, blocks, and imagery are copied automatically and each copy is linked to its original as a translation. The language must exist first (manage_language). Items are processed independently, so one bad entry does not abandon the rest — check `failed` in the result. Mutating: first returns a confirmation phrase; only executes after exact confirmation.",
|
|
3826
|
-
execute: (t) =>
|
|
3827
|
-
inputSchema:
|
|
3827
|
+
execute: (t) => Rr(t, e),
|
|
3828
|
+
inputSchema: Lr,
|
|
3828
3829
|
strict: !0
|
|
3829
3830
|
}),
|
|
3830
|
-
publish_content_draft:
|
|
3831
|
+
publish_content_draft: h({
|
|
3831
3832
|
description: "Publish (or discard) the Live Draft staged on a page or post by generate_jsonb_layout / rewrite_page_draft. Publishing applies the draft blocks and metadata to the live record and snapshots a revision first, so it is reversible from Revision History; visibility (status/published_at) is never changed. Use this to finish a build that staged a draft — without it the new layout stays invisible on the public site. Target the record with contentType plus slug, entityId, or title. Mutating: first returns a confirmation phrase; only executes after exact confirmation.",
|
|
3832
|
-
execute: (t) =>
|
|
3833
|
-
inputSchema:
|
|
3833
|
+
execute: (t) => Hr(t, e),
|
|
3834
|
+
inputSchema: zr,
|
|
3834
3835
|
strict: !0
|
|
3835
3836
|
}),
|
|
3836
|
-
rewrite_page_draft:
|
|
3837
|
+
rewrite_page_draft: h({
|
|
3837
3838
|
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:
|
|
3839
|
+
execute: (t) => Nr(t, e),
|
|
3840
|
+
inputSchema: kr,
|
|
3840
3841
|
strict: !0
|
|
3841
3842
|
}),
|
|
3842
|
-
translate_page:
|
|
3843
|
+
translate_page: h({
|
|
3843
3844
|
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. Targets the open page/post by default; with no editor open (MCP clients) pass `cmsTarget` with contentType plus slug, entityId, or title. Mutating: first returns a confirmation phrase; only creates the translation after exact confirmation.",
|
|
3844
|
-
execute: (t) =>
|
|
3845
|
-
inputSchema:
|
|
3845
|
+
execute: (t) => Jr(t, e),
|
|
3846
|
+
inputSchema: qr,
|
|
3846
3847
|
strict: !0
|
|
3847
3848
|
}),
|
|
3848
|
-
set_content_images:
|
|
3849
|
+
set_content_images: h({
|
|
3849
3850
|
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). On a PAGE the feature image renders as a full-width title banner above the blocks, so never set one on the home page or on a page that opens with its own hero section — use update_site_identity `social_image` for that page's share preview instead; posts should always have one. 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:
|
|
3851
|
+
execute: (t) => Yr(t, e),
|
|
3852
|
+
inputSchema: ue,
|
|
3852
3853
|
strict: !0
|
|
3853
3854
|
}),
|
|
3854
|
-
create_cms_page:
|
|
3855
|
+
create_cms_page: h({
|
|
3855
3856
|
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 a form block with fields; the destination address is configured once in CMS -> Messages and is never stored on the block.",
|
|
3856
|
-
execute: (t) =>
|
|
3857
|
-
inputSchema:
|
|
3857
|
+
execute: (t) => Mn(t, e),
|
|
3858
|
+
inputSchema: fe,
|
|
3858
3859
|
strict: !0
|
|
3859
3860
|
}),
|
|
3860
|
-
create_cms_post:
|
|
3861
|
+
create_cms_post: h({
|
|
3861
3862
|
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:
|
|
3863
|
+
execute: (t) => Nn(t, e),
|
|
3864
|
+
inputSchema: pe,
|
|
3864
3865
|
strict: !0
|
|
3865
3866
|
}),
|
|
3866
|
-
create_cms_product:
|
|
3867
|
+
create_cms_product: h({
|
|
3867
3868
|
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:
|
|
3869
|
+
execute: (t) => Ln(t, e),
|
|
3870
|
+
inputSchema: me,
|
|
3870
3871
|
strict: !0
|
|
3871
3872
|
}),
|
|
3872
|
-
delete_cms_item:
|
|
3873
|
+
delete_cms_item: h({
|
|
3873
3874
|
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:
|
|
3875
|
+
execute: (t) => Xn(t, e),
|
|
3876
|
+
inputSchema: A,
|
|
3876
3877
|
strict: !0
|
|
3877
3878
|
}),
|
|
3878
|
-
prepare_delete_cms_item:
|
|
3879
|
+
prepare_delete_cms_item: h({
|
|
3879
3880
|
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:
|
|
3881
|
+
execute: (t) => Yn(t, e),
|
|
3882
|
+
inputSchema: ge,
|
|
3882
3883
|
strict: !0
|
|
3883
3884
|
}),
|
|
3884
|
-
update_footer:
|
|
3885
|
+
update_footer: h({
|
|
3885
3886
|
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:
|
|
3887
|
+
execute: (t) => on(t, e),
|
|
3888
|
+
inputSchema: te,
|
|
3888
3889
|
strict: !0
|
|
3889
3890
|
}),
|
|
3890
|
-
update_content_block:
|
|
3891
|
+
update_content_block: h({
|
|
3891
3892
|
description: "Update the JSON content of an existing top-level page/post block. The block must belong to the item being edited — the open CMS editor, or the item named by `cmsTarget` (contentType plus slug, entityId, or title) when no editor is open, as with MCP clients. 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:
|
|
3893
|
+
execute: (t) => kn(t, e),
|
|
3894
|
+
inputSchema: O,
|
|
3894
3895
|
strict: !0
|
|
3895
3896
|
}),
|
|
3896
|
-
insert_content_block:
|
|
3897
|
+
insert_content_block: h({
|
|
3897
3898
|
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:
|
|
3899
|
+
execute: (t) => An(t, e),
|
|
3900
|
+
inputSchema: de,
|
|
3900
3901
|
strict: !0
|
|
3901
3902
|
}),
|
|
3902
|
-
update_current_cms_fields:
|
|
3903
|
+
update_current_cms_fields: h({
|
|
3903
3904
|
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:
|
|
3905
|
+
execute: (t) => On(t, e),
|
|
3906
|
+
inputSchema: D,
|
|
3906
3907
|
strict: !0
|
|
3907
3908
|
}),
|
|
3908
|
-
update_cms_item_field:
|
|
3909
|
+
update_cms_item_field: h({
|
|
3909
3910
|
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:
|
|
3911
|
+
execute: (t) => Kn(t, e),
|
|
3912
|
+
inputSchema: he,
|
|
3912
3913
|
strict: !0
|
|
3913
3914
|
}),
|
|
3914
|
-
update_navigation_bar:
|
|
3915
|
+
update_navigation_bar: h({
|
|
3915
3916
|
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
|
+
execute: (t) => an(t, e),
|
|
3917
3918
|
inputSchema: w,
|
|
3918
3919
|
strict: !0
|
|
3919
3920
|
}),
|
|
3920
|
-
update_section_column_block:
|
|
3921
|
+
update_section_column_block: h({
|
|
3921
3922
|
description: "Update the content of one existing nested block inside a section block. The parent section must belong to the item being edited — the open CMS editor, or the item named by `cmsTarget` (contentType plus slug, entityId, or title) when no editor is open, as with MCP clients. 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:
|
|
3923
|
+
execute: (t) => jn(t, e),
|
|
3924
|
+
inputSchema: k,
|
|
3924
3925
|
strict: !0
|
|
3925
3926
|
}),
|
|
3926
|
-
execute_cms_action_plan:
|
|
3927
|
+
execute_cms_action_plan: h({
|
|
3927
3928
|
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:
|
|
3929
|
+
execute: (t) => tr(t, e),
|
|
3930
|
+
inputSchema: xe,
|
|
3930
3931
|
strict: !0
|
|
3931
3932
|
})
|
|
3932
3933
|
};
|
|
3933
3934
|
}
|
|
3934
3935
|
//#endregion
|
|
3935
|
-
export {
|
|
3936
|
+
export { ke as buildVisibleContactIntroActionPlan, ie as cortexAiPageContextSchema, fe as createCmsPageInputSchema, pe as createCmsPostInputSchema, me as createCmsProductInputSchema, Xr as createCortexGlobalAgentTools, A as deleteCmsItemInputSchema, tr as executeCmsActionPlan, xe as executeCmsActionPlanInputSchema, Mn as executeCreateCmsPage, Nn as executeCreateCmsPost, Ln as executeCreateCmsProduct, Xn as executeDeleteCmsItem, vn as executeFetchEcommerceStats, _r as executeFetchUrlContent, An as executeInsertContentBlock, Ir as executeManageProductVariants, Yn as executePrepareDeleteCmsItem, Hr as executePublishContentDraft, yn as executeReadCurrentCmsItem, Nr as executeRewritePageDraft, un as executeSearchDocumentation, dn as executeSearchDocumentationWithTimeout, Or as executeSearchStockPhotos, Yr as executeSetContentImages, Rr as executeTranslateContentBulk, Jr as executeTranslatePage, Kn as executeUpdateCmsItemField, kn as executeUpdateContentBlock, On as executeUpdateCurrentCmsFields, on as executeUpdateFooter, an as executeUpdateNavigationBar, jn as executeUpdateSectionColumnBlock, re as fetchEcommerceStatsInputSchema, nr as fetchUrlContentInputSchema, de as insertContentBlockInputSchema, d as isBlockedFetchHost, Pr as manageProductVariantsInputSchema, Er as maybeTriggerStockPhotoDownloads, C as navigationItemInputSchema, ge as prepareDeleteCmsItemInputSchema, zr as publishContentDraftInputSchema, oe as readCurrentCmsItemInputSchema, xr as resolveCortexAiStockPhotoProvider, br as resolveCortexAiStockPhotoProviders, kr as rewritePageDraftInputSchema, ne as searchDocumentationInputSchema, vr as searchStockPhotosInputSchema, ue as setContentImagesInputSchema, Lr as translateContentBulkInputSchema, qr as translatePageInputSchema, he as updateCmsItemFieldInputSchema, O as updateContentBlockInputSchema, D as updateCurrentCmsFieldsInputSchema, te as updateFooterInputSchema, w as updateNavigationBarInputSchema, k as updateSectionColumnBlockInputSchema };
|