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