@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.
@@ -1,9 +1,9 @@
1
- import { tool as w } from "ai";
2
- import { createCortexDatabaseAgentTools as St } from "./ai-global-agent-db-tools.es.js";
3
- import { createCortexCustomBlockTools as Et } from "./ai-global-agent-custom-block-tools.es.js";
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 o } from "zod";
6
- const O = [
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
- ], At = 1e4, Pt = {
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
- }, Re = o.string().trim().min(1).max(2048).refine(
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
- ), Be = o.strictObject({
40
- label: o.string().trim().min(1).max(120),
41
- target: o.enum(["_self", "_blank"]).optional(),
42
- url: Re
43
- }), Ge = Be.extend({
44
- children: o.array(Be).max(20).optional()
45
- }), Bt = o.strictObject({
46
- label: o.string().trim().min(1).max(120).optional(),
47
- url: Re.optional()
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
- }), ee = o.strictObject({
51
- items: o.array(Ge).min(1).max(30),
52
- languageCode: o.string().trim().min(2).max(80).default("en").describe('Locale code or language name, for example "en", "fr", "English", or "French".'),
53
- match: Bt.optional().describe('For mode "update", identifies the existing navigation item to update.'),
54
- mode: o.enum(["append", "replace", "update"]).default("append")
55
- }), te = o.strictObject({
56
- copyright: o.record(o.string().trim().min(2).max(12), o.string().trim().min(1).max(500)).optional(),
57
- languageCode: o.string().trim().min(2).max(80).default("en").describe('Locale code or language name, for example "en", "fr", "English", or "French".'),
58
- links: o.array(Ge).min(1).max(30).optional()
59
- }), ye = o.strictObject({
60
- limit: o.number().int().min(1).max(8).default(4),
61
- query: o.string().trim().min(2).max(300)
62
- }), ze = o.object({
63
- currency: o.string().trim().min(3).max(3).optional().describe(
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: o.string().describe("The analytical question about orders, products, or revenue."),
67
- reportType: o.enum(["revenue", "orders", "products", "general"]).optional().default("general").describe("The focus area of the statistical report."),
68
- timeRange: o.enum(["today", "this_month", "last_7_days", "last_30_days", "last_month", "last_90_days", "all_time"]).optional().default("all_time").describe("The time period for the report. Use all_time for current order-status counts unless the user names a specific period.")
69
- }), Ke = o.strictObject({
70
- contentType: o.enum(["page", "post", "product"]),
71
- currentEditor: o.strictObject({
72
- blockId: o.union([o.number().int().positive(), o.string().trim().min(1).max(120)]).nullable().optional(),
73
- blockType: o.string().trim().min(1).max(80).nullable().optional(),
74
- field: o.string().trim().min(1).max(120).nullable().optional()
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: o.union([o.number().int().positive(), o.string().trim().min(1).max(120)]),
77
- languageId: o.number().int().positive().nullable().optional(),
78
- slug: o.string().trim().min(1).max(300).nullable().optional(),
79
- title: o.string().trim().min(1).max(300).nullable().optional(),
80
- translationGroupId: o.string().trim().min(1).max(120).nullable().optional()
81
- }), Ve = o.strictObject({
82
- includeBlockContent: o.boolean().default(!1),
83
- includeBlocks: o.boolean().default(!0)
84
- }), ne = o.strictObject({
85
- fields: o.strictObject({
86
- description_json: o.unknown().optional(),
87
- excerpt: o.string().max(2e3).nullable().optional(),
88
- feature_image_id: o.string().trim().min(1).max(120).nullable().optional(),
89
- label: o.string().max(120).nullable().optional(),
90
- meta_description: o.string().max(500).nullable().optional(),
91
- meta_title: o.string().max(160).nullable().optional(),
92
- published_at: o.string().max(80).nullable().optional(),
93
- short_description: o.string().max(2e3).nullable().optional(),
94
- slug: o.string().trim().min(1).max(300).optional(),
95
- status: o.enum(["draft", "published", "active", "archived"]).optional(),
96
- subtitle: o.string().max(300).nullable().optional(),
97
- title: o.string().trim().min(1).max(300).optional()
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
- }), oe = o.strictObject({
100
- blockId: o.number().int().positive(),
101
- blockType: o.enum(O).optional(),
102
- content: o.record(o.string(), o.unknown())
103
- }), re = o.strictObject({
104
- blockIndex: o.number().int().min(0),
105
- blockType: o.enum(O).optional(),
106
- columnIndex: o.number().int().min(0),
107
- content: o.record(o.string(), o.unknown()),
108
- parentBlockId: o.number().int().positive()
109
- }), Ft = o.enum(["page", "post", "product"]), ie = o.strictObject({
110
- contentType: Ft.optional(),
111
- entityId: o.union([o.number().int().positive(), o.string().trim().min(1).max(120)]).optional(),
112
- slug: o.string().trim().min(1).max(300).optional(),
113
- title: o.string().trim().min(1).max(300).optional()
114
- }), he = o.strictObject({
115
- blockType: o.enum(O),
116
- content: o.record(o.string(), o.unknown()),
117
- order: o.number().int().min(0).optional()
118
- }), ae = ie.extend({
119
- anchorBlockId: o.number().int().positive().optional(),
120
- anchorBlockType: o.enum(O).optional(),
121
- block: he,
122
- position: o.enum(["before", "after", "start", "end"]).default("end")
123
- }), se = o.strictObject({
124
- blocks: o.array(he).max(20).optional(),
125
- contactEmail: o.string().email().optional(),
126
- feature_image_id: o.string().trim().min(1).max(120).nullable().optional(),
127
- languageCode: o.string().trim().min(2).max(80).optional(),
128
- meta_description: o.string().max(500).nullable().optional(),
129
- meta_title: o.string().max(160).nullable().optional(),
130
- slug: o.string().trim().min(1).max(300).optional(),
131
- status: o.enum(["draft", "published", "archived"]).default("draft"),
132
- title: o.string().trim().min(1).max(300),
133
- translationGroupId: o.string().trim().min(1).max(120).optional()
134
- }), le = o.strictObject({
135
- blocks: o.array(he).max(20).optional(),
136
- excerpt: o.string().max(2e3).nullable().optional(),
137
- feature_image_id: o.string().trim().min(1).max(120).nullable().optional(),
138
- label: o.string().max(120).nullable().optional(),
139
- languageCode: o.string().trim().min(2).max(80).optional(),
140
- meta_description: o.string().max(500).nullable().optional(),
141
- meta_title: o.string().max(160).nullable().optional(),
142
- published_at: o.string().max(80).nullable().optional(),
143
- slug: o.string().trim().min(1).max(300).optional(),
144
- status: o.enum(["draft", "published", "archived"]).default("draft"),
145
- subtitle: o.string().max(300).nullable().optional(),
146
- title: o.string().trim().min(1).max(300),
147
- translationGroupId: o.string().trim().min(1).max(120).optional()
148
- }), ce = o.strictObject({
149
- description_json: o.unknown().optional(),
150
- freemius_plan_id: o.string().optional(),
151
- freemius_product_id: o.string().optional(),
152
- is_taxable: o.boolean().default(!0),
153
- languageCode: o.string().trim().min(2).max(80).optional(),
154
- meta_description: o.string().max(500).nullable().optional(),
155
- meta_title: o.string().max(160).nullable().optional(),
156
- payment_provider: o.enum(["stripe", "freemius"]).default("stripe"),
157
- price: o.number().min(0).default(0),
158
- prices: o.record(o.string(), o.number().min(0)).optional(),
159
- product_type: o.enum(["physical", "digital"]).default("physical"),
160
- sale_price: o.number().min(0).nullable().optional(),
161
- sale_prices: o.record(o.string(), o.number().min(0).nullable()).optional(),
162
- short_description: o.string().max(2e3).nullable().optional(),
163
- sku: o.string().trim().min(1).max(120).optional(),
164
- slug: o.string().trim().min(1).max(300).optional(),
165
- status: o.enum(["draft", "active", "archived"]).default("draft"),
166
- stock: o.number().int().min(0).default(0),
167
- title: o.string().trim().min(1).max(300),
168
- trial_period_days: o.number().int().min(0).default(0),
169
- trial_requires_payment_method: o.boolean().default(!1),
170
- translationGroupId: o.string().trim().min(1).max(120).optional(),
171
- upc: o.string().max(120).nullable().optional()
172
- }), ue = ie.extend({
173
- currencyCode: o.string().trim().min(3).max(3).optional(),
174
- endsAt: o.string().max(80).nullable().optional(),
175
- field: o.string().trim().min(1).max(120),
176
- startsAt: o.string().max(80).nullable().optional(),
177
- value: o.unknown()
178
- }), Je = ie, de = ie, We = o.discriminatedUnion("tool", [
179
- o.strictObject({ input: se, tool: o.literal("create_cms_page") }),
180
- o.strictObject({ input: le, tool: o.literal("create_cms_post") }),
181
- o.strictObject({ input: ce, tool: o.literal("create_cms_product") }),
182
- o.strictObject({ input: de, tool: o.literal("delete_cms_item") }),
183
- o.strictObject({ input: ue, tool: o.literal("update_cms_item_field") }),
184
- o.strictObject({ input: oe, tool: o.literal("update_content_block") }),
185
- o.strictObject({ input: ae, tool: o.literal("insert_content_block") }),
186
- o.strictObject({ input: ne, tool: o.literal("update_current_cms_fields") }),
187
- o.strictObject({ input: te, tool: o.literal("update_footer") }),
188
- o.strictObject({ input: ee, tool: o.literal("update_navigation_bar") }),
189
- o.strictObject({ input: re, tool: o.literal("update_section_column_block") })
190
- ]), Nt = o.union([
191
- se.extend({ tool: o.literal("create_cms_page") }).transform(({ tool: e, ...n }) => ({ input: n, tool: e })),
192
- le.extend({ tool: o.literal("create_cms_post") }).transform(({ tool: e, ...n }) => ({ input: n, tool: e })),
193
- ce.extend({ tool: o.literal("create_cms_product") }).transform(({ tool: e, ...n }) => ({ input: n, tool: e })),
194
- de.extend({ tool: o.literal("delete_cms_item") }).transform(({ tool: e, ...n }) => ({ input: n, tool: e })),
195
- ue.extend({ tool: o.literal("update_cms_item_field") }).transform(({ tool: e, ...n }) => ({ input: n, tool: e })),
196
- oe.extend({ tool: o.literal("update_content_block") }).transform(({ tool: e, ...n }) => ({ input: n, tool: e })),
197
- ae.extend({ tool: o.literal("insert_content_block") }).transform(({ tool: e, ...n }) => ({ input: n, tool: e })),
198
- ne.extend({ tool: o.literal("update_current_cms_fields") }).transform(({ tool: e, ...n }) => ({ input: n, tool: e })),
199
- te.extend({ tool: o.literal("update_footer") }).transform(({ tool: e, ...n }) => ({ input: n, tool: e })),
200
- ee.extend({ tool: o.literal("update_navigation_bar") }).transform(({ tool: e, ...n }) => ({ input: n, tool: e })),
201
- re.extend({ tool: o.literal("update_section_column_block") }).transform(({ tool: e, ...n }) => ({ input: n, tool: e }))
202
- ]), jt = o.string().transform((e, n) => {
203
- const t = Mt(e);
204
- return t.success ? t.action : (n.addIssue({
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: t.message
207
- }), o.NEVER);
208
- }), qt = o.union([
209
- We,
210
- Nt,
211
- jt
212
- ]), He = o.strictObject({
213
- actions: o.array(qt).min(1).max(8),
214
- summary: o.string().trim().min(1).max(500).optional()
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 Ot(e) {
217
- const n = [];
218
- let t = "", r = 0, i = null, a = !1;
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 (i) {
221
- t += s, a ? a = !1 : s === "\\" ? a = !0 : s === i && (i = null);
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
- i = s, t += s;
225
+ o = s, n += s;
226
226
  continue;
227
227
  }
228
228
  if (s === "[" || s === "{" || s === "(") {
229
- r++, t += s;
229
+ r++, n += s;
230
230
  continue;
231
231
  }
232
232
  if (s === "]" || s === "}" || s === ")") {
233
- r = Math.max(0, r - 1), t += s;
233
+ r = Math.max(0, r - 1), n += s;
234
234
  continue;
235
235
  }
236
236
  if (s === "," && r === 0) {
237
- t.trim() && n.push(t.trim()), t = "";
237
+ n.trim() && t.push(n.trim()), n = "";
238
238
  continue;
239
239
  }
240
- t += s;
240
+ n += s;
241
241
  }
242
- return t.trim() && n.push(t.trim()), n;
242
+ return n.trim() && t.push(n.trim()), t;
243
243
  }
244
- function Fe(e) {
245
- let n = "";
246
- for (let t = 0; t < e.length; t++) {
247
- const r = e[t];
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
- n += r;
249
+ t += r;
250
250
  continue;
251
251
  }
252
- let i = "", a = !1;
253
- for (t++; t < e.length; t++) {
254
- const s = e[t];
252
+ let o = "", a = !1;
253
+ for (n++; n < e.length; n++) {
254
+ const s = e[n];
255
255
  if (a) {
256
- i += s, a = !1;
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
- i += s;
265
+ o += s;
266
266
  }
267
- n += JSON.stringify(i);
267
+ t += JSON.stringify(o);
268
268
  }
269
- return n.replace(/\bTrue\b/g, "true").replace(/\bFalse\b/g, "false").replace(/\bNone\b/g, "null");
269
+ return t.replace(/\bTrue\b/g, "true").replace(/\bFalse\b/g, "false").replace(/\bNone\b/g, "null");
270
270
  }
271
- function Ut(e) {
272
- const n = e.trim();
273
- return n.startsWith("'") && n.endsWith("'") || n.startsWith('"') && n.endsWith('"') || n.startsWith("[") || n.startsWith("{") ? JSON.parse(Fe(n)) : /^-?\d+(?:\.\d+)?$/.test(n) ? Number(n) : n === "true" || n === "True" ? !0 : n === "false" || n === "False" ? !1 : n === "null" || n === "None" ? null : n;
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 Dt(e) {
276
- const n = {};
277
- for (const t of Ot(e)) {
278
- const r = t.indexOf("=");
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 "${t}".`);
281
- const i = t.slice(0, r).trim();
282
- if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(i))
283
- throw new Error(`Invalid argument name "${i}".`);
284
- n[i] = Ut(t.slice(r + 1));
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 n;
286
+ return t;
287
287
  }
288
- function Mt(e) {
289
- const t = e.trim().match(/^([a-z_]+)\(([\s\S]*)\)$/);
290
- if (!t)
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 = t[1];
296
- let i;
295
+ const r = n[1];
296
+ let o;
297
297
  try {
298
- i = Dt(t[2]);
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: i, tool: r }, s = We.safeParse(a);
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 Lt(e) {
314
+ function an(e) {
315
315
  return e.normalize("NFD").replace(/[\u0300-\u036f]/g, "").toLowerCase().replace(/\s+/g, " ").trim();
316
316
  }
317
- function V(e, n) {
318
- return n.some((t) => e.includes(t));
317
+ function Q(e, t) {
318
+ return t.some((n) => e.includes(n));
319
319
  }
320
- function Yn(e) {
321
- const n = Lt(e), t = V(n, ["add ", "insert ", "put ", "create "]), r = V(n, [
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
- ]), i = n.includes("form") && V(n, ["above", "before"]), a = n.includes("contact page") || n.includes("contact pages") || n.includes("contact us") || n.includes("contactez-nous"), s = n.includes("english") && V(n, ["french", "francais", "francaise"]);
329
- return !t || !r || !i || !a || !s ? null : {
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 Rt = o.enum(O), Ne = o.object({
366
- direction: o.string().optional(),
367
- stops: o.array(o.object({ color: o.string(), position: o.number() })),
368
- type: o.enum(["linear", "radial"])
369
- }), Gt = o.object({
370
- gradient: Ne.optional(),
371
- image: o.object({
372
- alt_text: o.string().optional(),
373
- blur_data_url: o.string().optional(),
374
- height: o.number().optional(),
375
- media_id: o.string(),
376
- object_key: o.string(),
377
- overlay: o.object({
378
- gradient: Ne,
379
- type: o.literal("gradient")
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: o.enum(["center", "top", "bottom", "left", "right"]),
382
- quality: o.number().nullable().optional(),
383
- size: o.enum(["cover", "contain"]),
384
- width: o.number().optional()
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: o.string().optional(),
387
- solid_color: o.string().optional(),
388
- theme: o.enum(["primary", "secondary", "muted", "accent", "destructive"]).optional(),
389
- type: o.enum(["none", "theme", "solid", "gradient", "image"])
390
- }), zt = o.object({
391
- block_type: Rt,
392
- content: o.record(o.string(), o.any()),
393
- temp_id: o.string().optional()
394
- }), Kt = o.object({
395
- background: Gt,
396
- column_blocks: o.array(o.array(zt)),
397
- column_gap: o.enum(["none", "sm", "md", "lg", "xl"]),
398
- container_type: o.enum(["full-width", "container", "container-sm", "container-lg", "container-xl"]),
399
- padding: o.object({
400
- bottom: o.enum(["none", "sm", "md", "lg", "xl"]),
401
- top: o.enum(["none", "sm", "md", "lg", "xl"])
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: o.object({
404
- desktop: o.union([o.literal(1), o.literal(2), o.literal(3), o.literal(4)]),
405
- mobile: o.union([o.literal(1), o.literal(2)]),
406
- tablet: o.union([o.literal(1), o.literal(2), o.literal(3)])
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: o.enum(["start", "center", "end", "stretch"]).optional()
409
- }), Vt = {
410
- button: o.object({
411
- position: o.enum(["left", "center", "right"]).optional(),
412
- size: o.enum(["default", "sm", "lg", "full"]).optional(),
413
- text: o.string(),
414
- url: o.string(),
415
- variant: o.enum(["default", "outline", "secondary", "ghost", "link"]).optional()
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: o.object({}),
418
- checkout: o.object({}),
419
- featured_product: o.object({
420
- imagePosition: o.enum(["left", "right"]).default("left"),
421
- productId: o.string().min(1),
422
- showBackground: o.boolean().default(!1)
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: o.object({
425
- fields: o.array(
426
- o.object({
427
- field_type: o.enum(["text", "email", "textarea", "select", "radio", "checkbox"]),
428
- is_required: o.boolean(),
429
- label: o.string(),
430
- options: o.array(o.object({ label: o.string(), value: o.string() })).optional(),
431
- placeholder: o.string().optional(),
432
- temp_id: o.string()
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: o.string().email(),
436
- submit_button_text: o.string(),
437
- success_message: o.string()
436
+ recipient_email: i.string().email(),
437
+ submit_button_text: i.string(),
438
+ success_message: i.string()
438
439
  }),
439
- heading: o.object({
440
- level: o.union([o.literal(1), o.literal(2), o.literal(3), o.literal(4), o.literal(5), o.literal(6)]),
441
- textAlign: o.enum(["left", "center", "right", "justify"]).optional(),
442
- textColor: o.enum(["primary", "secondary", "accent", "muted", "destructive", "background"]).optional(),
443
- text_content: o.string()
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: o.object({
446
- alt_text: o.string().optional(),
447
- caption: o.string().optional(),
448
- height: o.number().nullable().optional(),
449
- media_id: o.string().nullable(),
450
- object_key: o.string().nullable().optional(),
451
- width: o.number().nullable().optional()
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: o.object({
454
- columns: o.number().min(1).max(6),
455
- postsPerPage: o.number().min(1).max(50),
456
- showPagination: o.boolean(),
457
- title: o.string().optional()
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: o.object({}),
460
- product_grid: o.object({
461
- categoryId: o.string().optional(),
462
- limit: o.number().min(1).max(20).default(6),
463
- title: o.string().optional(),
464
- type: o.enum(["latest", "category"]).default("latest")
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: Kt,
467
- testimonial: o.object({
468
- author_name: o.string().min(1),
469
- author_title: o.string().optional(),
470
- image_url: o.string().url().optional().or(o.literal("")),
471
- quote: o.string().min(1)
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: o.object({
474
- html_content: o.string()
475
+ text: i.object({
476
+ html_content: i.string()
475
477
  }),
476
- video_embed: o.object({
477
- autoplay: o.boolean().optional(),
478
- controls: o.boolean().optional(),
479
- title: o.string().optional(),
480
- url: o.string()
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 Jt(e) {
484
- return O.includes(e);
485
+ function pn(e) {
486
+ return M.includes(e);
485
487
  }
486
- function Wt(e) {
488
+ function mn(e) {
487
489
  return typeof e?.validateBlockContent == "function" ? e.validateBlockContent : null;
488
490
  }
489
- function Ht(e, n, t) {
490
- const r = Wt(t);
491
+ function gn(e, t, n) {
492
+ const r = mn(n);
491
493
  if (r)
492
- return r(e, n);
493
- const i = Vt[e].safeParse(n);
494
- return i.success ? { errors: [], isValid: !0, warnings: [] } : {
495
- errors: i.error.issues.map((a) => {
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 Yt() {
504
- return o.object({
505
- content: o.array(o.any()).optional(),
506
- type: o.literal("doc")
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 ke() {
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 h(e) {
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 Qt(e, n, t) {
524
+ function hn(e, t, n) {
523
525
  let r;
524
- const i = new Promise((a) => {
525
- r = setTimeout(() => a(t()), n);
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
- i
533
+ o
532
534
  ]);
533
535
  }
534
- function pe(e) {
535
- const n = Ke.safeParse(e?.pageContext);
536
- if (!n.success)
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 n.data;
542
+ return t.data;
541
543
  }
542
- function Ye(e) {
543
- const n = typeof e.entityId == "number" ? e.entityId : Number.parseInt(e.entityId, 10);
544
- if (!Number.isInteger(n) || n <= 0)
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 n;
548
+ return t;
547
549
  }
548
- function Xt(e) {
549
- const n = String(e.entityId || "").trim();
550
- if (!n)
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 n;
554
+ return t;
555
+ }
556
+ function be(e) {
557
+ return e.contentType === "product" ? _n(e) : Ue(e);
553
558
  }
554
- function we(e) {
555
- return e.contentType === "product" ? Xt(e) : Ye(e);
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 Zt(e) {
583
+ function pt(e) {
558
584
  return typeof e == "string" ? e.trim().replace(/^\/+|\/+$/g, "") : "";
559
585
  }
560
- function en(e, n) {
561
- const t = Zt(n ?? e.slug);
562
- return t ? e.contentType === "page" ? t === "home" ? "/" : `/${t}` : e.contentType === "post" ? `/article/${t}` : `/product/${t}` : null;
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 tn(e) {
565
- const n = String(e.entityId);
566
- return e.contentType === "page" ? `/cms/pages/${n}/edit` : e.contentType === "post" ? `/cms/posts/${n}/edit` : `/cms/products/${n}/edit`;
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 F(e, n, t) {
569
- const r = e?.revalidatePath ?? ke();
594
+ function N(e, t, n) {
595
+ const r = e?.revalidatePath ?? Ne();
570
596
  if (!r)
571
597
  return;
572
- r(tn(n));
573
- const i = en(n, t);
574
- i && r(i), n.contentType === "product" && r("/cms/products");
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 Qe(e) {
577
- const n = e?.revalidatePath ?? ke();
578
- n && (n("/", "layout"), n("/cms/navigation"));
602
+ function mt(e) {
603
+ const t = e?.revalidatePath ?? Ne();
604
+ t && (t("/", "layout"), t("/cms/navigation"));
579
605
  }
580
- function f(e) {
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 Ie() {
609
+ async function In() {
584
610
  return import("./ai-global-agent-ecommerce.es.js");
585
611
  }
586
- function ge(e) {
587
- return e === null || typeof e != "object" ? JSON.stringify(e) : Array.isArray(e) ? `[${e.map((n) => ge(n)).join(",")}]` : `{${Object.keys(e).filter((n) => n !== "temp_id").sort().map((n) => `${JSON.stringify(n)}:${ge(e[n])}`).join(",")}}`;
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 nn(e) {
590
- let n = 2166136261;
591
- const t = ge(e);
592
- for (let r = 0; r < t.length; r++)
593
- n ^= t.charCodeAt(r), n = Math.imul(n, 16777619);
594
- return (n >>> 0).toString(16).padStart(8, "0");
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 fe(e) {
622
+ function xe(e) {
597
623
  return e.replace(/\s+/g, " ").trim().toUpperCase();
598
624
  }
599
- function on(e, n, t) {
600
- return `${fe(`CONFIRM ${e} ${n}`)} #${nn(t)}`;
625
+ function xn(e, t, n) {
626
+ return `${xe(`CONFIRM ${e} ${t}`)} #${Tn(n)}`;
601
627
  }
602
- function Xe(e) {
628
+ function gt(e) {
603
629
  return {
604
- confirmationPhrase: on(
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 v(e, n) {
616
- const t = e[n];
617
- return typeof t == "string" && t.trim() ? t.trim() : null;
641
+ function U(e, t) {
642
+ const n = e[t];
643
+ return typeof n == "string" && n.trim() ? n.trim() : null;
618
644
  }
619
- function J(e, n) {
620
- const t = Number(e[n]);
621
- return Number.isFinite(t) ? t : null;
645
+ function Z(e, t) {
646
+ const n = Number(e[t]);
647
+ return Number.isFinite(n) ? n : null;
622
648
  }
623
- function N(e, n, t = `${n}s`) {
624
- return `${e} ${e === 1 ? n : t}`;
649
+ function F(e, t, n = `${t}s`) {
650
+ return `${e} ${e === 1 ? t : n}`;
625
651
  }
626
- function rn(e, n) {
627
- const t = v(n, "summary");
628
- if (t)
629
- return t;
630
- const r = v(n, "title"), i = v(n, "slug"), a = v(n, "status"), s = v(n, "contentType"), l = v(n, "field"), m = v(n, "mode"), u = v(n, "languageCode"), c = J(n, "blockCount"), d = J(n, "itemCount"), g = J(n, "affectedCount");
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 || i || "Untitled"}"${i ? ` at slug "${i}"` : ""}${c !== null ? ` with ${N(c, "content block")}` : ""}.`;
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 || i || "Untitled"}"${i ? ` at slug "${i}"` : ""}.`;
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 || i || "selected item"}".`;
662
+ return `Update ${l || "one field"} on the ${s || "CMS item"} "${r || o || "selected item"}".`;
637
663
  if (e === "update_navigation_bar")
638
- return `${m === "append" ? "Add" : m === "update" ? "Update" : "Replace"} ${d !== null ? N(d, "navigation item") : "navigation items"} in the ${u || "selected"} header navigation.`;
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 p = J(n, "linkCount");
641
- return `Update the ${u || "selected"} footer${p !== null ? ` with ${N(p, "link")}` : ""}.`;
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 ${v(n, "blockType") || "content"} block.` : e === "insert_content_block" ? `Insert ${v(n, "blockType") || "content"} block on the ${s || "CMS item"} "${r || i || "selected item"}".` : e === "update_section_column_block" ? `Update the selected nested ${v(n, "nestedBlockType") || "section"} block.` : e === "delete_cms_item" || e === "prepare_delete_cms_item" ? `Delete ${g !== null ? N(g, s || "CMS item") : `the selected ${s || "CMS item"}`}${r || i ? ` for "${r || i}"` : ""}.` : "Complete the requested CMS change.";
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 x(e) {
671
+ function P(e) {
646
672
  if (e.context?.skipConfirmation)
647
673
  return null;
648
- const n = Xe(e), t = fe(e.context?.latestUserMessage || ""), r = fe(n.confirmationPhrase);
649
- return t.includes(r) ? null : n;
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 Ze(e) {
652
- const n = e?.actorUserId;
653
- if (!n)
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 n;
681
+ return t;
656
682
  }
657
- function Ce() {
683
+ function Oe() {
658
684
  return globalThis.crypto?.randomUUID?.() || `id-${Date.now()}-${Math.random().toString(36).slice(2)}`;
659
685
  }
660
- function me(e) {
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 Te(e) {
689
+ function je(e) {
664
690
  return (e || "USD").trim().toUpperCase();
665
691
  }
666
- function xe(e, n) {
667
- const r = (/* @__PURE__ */ new Set(["BIF", "CLP", "DJF", "GNF", "JPY", "KMF", "KRW", "MGA", "PYG", "RWF", "UGX", "VND", "VUV", "XAF", "XOF", "XPF"])).has(Te(n)) ? 0 : 2;
668
- return e / 10 ** r;
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 an(e, n) {
671
- return typeof e == "number" && Number.isFinite(e) ? xe(e, n) : 0;
713
+ function ft(e, t) {
714
+ return Math.round(e * 10 ** Sn(t));
672
715
  }
673
- function je(e, n) {
716
+ function En(e, t) {
674
717
  return !e || typeof e != "object" || Array.isArray(e) ? {} : Object.entries(e).reduce(
675
- (t, [r, i]) => (typeof i == "number" && Number.isFinite(i) && (t[Te(r || n)] = xe(
676
- i,
677
- r || n
678
- )), t),
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 G(e, n) {
683
- if (!R(e))
684
- throw new Error(`${n} content must be a JSON object.`);
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 R(e) {
736
+ function A(e) {
691
737
  return !!(e && typeof e == "object" && !Array.isArray(e));
692
738
  }
693
- function _e(e, n) {
694
- const t = H(e);
695
- for (const [r, i] of Object.entries(n))
696
- if (i !== void 0) {
697
- if (R(i) && R(t[r])) {
698
- t[r] = _e(t[r], i);
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
- t[r] = H(i);
747
+ n[r] = H(o);
702
748
  }
703
- return t;
749
+ return n;
704
750
  }
705
- function et(e, n) {
706
- if (n.contentType === "product")
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 t = Ye(n);
709
- if ((n.contentType === "page" ? Number(e.page_id) : Number(e.post_id)) !== t)
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 ${n.contentType} being edited.`
757
+ `Block ${e.id} does not belong to the current ${t.contentType} being edited.`
712
758
  );
713
759
  }
714
- function Y(e, n) {
715
- const t = typeof e == "string" ? e : "";
716
- if (!Jt(t))
717
- throw new Error(`${n} has unsupported block type "${t || "unknown"}".`);
718
- return t;
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 tt(e, n, t) {
721
- if (e && e !== n)
766
+ function _t(e, t, n) {
767
+ if (e && e !== t)
722
768
  throw new Error(
723
- `${t} is a "${n}" block. Refusing to update it as "${e}".`
769
+ `${n} is a "${t}" block. Refusing to update it as "${e}".`
724
770
  );
725
771
  }
726
- function j(e, n, t, r) {
727
- const i = Ht(e, n, r);
728
- if (!i.isValid)
772
+ function L(e, t, n, r) {
773
+ const o = gn(e, t, r);
774
+ if (!o.isValid)
729
775
  throw new Error(
730
- `${t} content is invalid for block type "${e}": ${i.errors.join("; ")}`
776
+ `${n} content is invalid for block type "${e}": ${o.errors.join("; ")}`
731
777
  );
732
778
  }
733
- function nt(e) {
779
+ function yt(e) {
734
780
  return e === "section";
735
781
  }
736
- function sn(e) {
737
- return typeof e.html_content == "string" ? "text" : typeof e.text == "string" && typeof e.url == "string" ? "button" : typeof e.text_content == "string" ? "heading" : "media_id" in e || "object_key" in e ? "image" : typeof e.quote == "string" && typeof e.author_name == "string" ? "testimonial" : typeof e.url == "string" && ("controls" in e || "autoplay" in e || "title" in e) ? "video_embed" : Array.isArray(e.fields) || typeof e.recipient_email == "string" ? "form" : "postsPerPage" in e || "showPagination" in e ? "posts_grid" : typeof e.productId == "string" ? "featured_product" : "limit" in e && "type" in e ? "product_grid" : null;
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 Q(e) {
785
+ function oe(e) {
740
786
  return `ai-${e}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
741
787
  }
742
- function qe(e, n, t) {
743
- if (!R(e))
744
- throw new Error(`${n} must be a JSON object.`);
745
- const r = e.block_type ?? e.blockType, i = Y(r, n);
746
- if (nt(i))
747
- throw new Error(`${n} cannot be a nested ${i} block.`);
748
- const a = at(
749
- i,
750
- G(e.content, n),
751
- n,
752
- t
753
- ), s = e.temp_id ?? e.tempId, l = typeof s == "string" && s.trim() ? s : Q(i);
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: i,
801
+ block_type: o,
756
802
  content: a,
757
803
  temp_id: l
758
804
  };
759
805
  }
760
- function ln(e, n) {
761
- const t = [];
762
- if ("append_block" in e && t.push(qe(e.append_block, "Nested block to append", n)), "append_blocks" in e) {
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((i, a) => {
767
- t.push(qe(i, `Nested block to append ${a}`, n));
812
+ r.forEach((o, a) => {
813
+ n.push(ve(o, `Nested block to append ${a}`, t));
768
814
  });
769
815
  }
770
- return t;
816
+ return n;
771
817
  }
772
- function cn(e, n) {
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 t = sn(e);
776
- if (!t)
821
+ const n = $n(e);
822
+ if (!n)
777
823
  return null;
778
- const r = G(e, `Nested ${t} block`);
779
- return j(t, r, `Nested ${t} block`, n), {
780
- block_type: t,
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: Q(t)
828
+ temp_id: oe(n)
783
829
  };
784
830
  }
785
- function un(e, n) {
786
- const t = e.append_column_index ?? e.column_index;
787
- if (t === void 0)
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 t != "number" || !Number.isInteger(t) || t < 0)
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 (n > 0 && t >= n)
837
+ if (t > 0 && n >= t)
792
838
  throw new Error(
793
- `append_column_index ${t} is outside the existing ${n} column(s).`
839
+ `append_column_index ${n} is outside the existing ${t} column(s).`
794
840
  );
795
- return t;
841
+ return n;
796
842
  }
797
- function dn(e, n, t, r) {
798
- if (!nt(e))
799
- return _e(n, t);
800
- const i = { ...t }, a = ln(i, r), s = cn(i, r);
801
- s && a.push(s), delete i.append_block, delete i.append_blocks, delete i.append_column_index, delete i.column_index;
802
- const l = _e(n, i);
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 m = Array.isArray(n.column_blocks) ? H(n.column_blocks) : [], u = un(t, m.length), c = m.length > 0 ? m : [[]];
805
- for (; c.length <= u; )
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[u] = [
808
- ...c[u] || [],
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 pn(e, n) {
860
+ function Fn(e, t) {
815
861
  return {
816
862
  blockType: e.block_type,
817
- content: n ? e.content : void 0,
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 q(e) {
871
+ function R(e) {
826
872
  return typeof e == "string" ? e.trim().toLowerCase() : "";
827
873
  }
828
- function Oe(e) {
874
+ function We(e) {
829
875
  return typeof e == "string" ? e.trim().toLowerCase() : "";
830
876
  }
831
- function ot(e) {
832
- return e.reduce((n, t) => n + 1 + (t.children?.length || 0), 0);
877
+ function bt(e) {
878
+ return e.reduce((t, n) => t + 1 + (n.children?.length || 0), 0);
833
879
  }
834
- function W(e) {
880
+ function ne(e) {
835
881
  return typeof e == "string" ? e.trim().toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "") : "";
836
882
  }
837
- async function U(e, n) {
838
- const t = n.trim(), r = W(t), i = Pt[r], { data: a, error: s } = await e.from("languages").select("id, code, name, is_active");
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 "${n}": ${f(s)}`);
841
- const m = (Array.isArray(a) ? a : []).filter((c) => c.is_active !== !1), u = m.find((c) => {
842
- const d = W(c.code), g = W(c.name);
843
- return d === r || d === i || g === r;
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 (!u?.id || !u?.code) {
846
- const c = m.map((d) => d.code).filter(Boolean).join(", ");
891
+ if (!d?.id || !d?.code) {
892
+ const c = u.map((p) => p.code).filter(Boolean).join(", ");
847
893
  throw new Error(
848
- `Language "${n}" was not found.${c ? ` Available languages: ${c}.` : ""}`
894
+ `Language "${t}" was not found.${c ? ` Available languages: ${c}.` : ""}`
849
895
  );
850
896
  }
851
897
  return {
852
- code: String(u.code),
853
- id: Number(u.id)
898
+ code: String(d.code),
899
+ id: Number(d.id)
854
900
  };
855
901
  }
856
- async function $e(e, n) {
857
- if (n)
858
- return U(e, n);
859
- const { data: t, error: r } = await e.from("languages").select("id, code, name, is_active, is_default");
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: ${f(r)}`);
862
- const i = (Array.isArray(t) ? t : []).filter(
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 = i.find((s) => s.is_default) || i.find((s) => W(s.code) === "en") || i[0];
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 mn(e) {
918
+ async function Je(e) {
873
919
  try {
874
- const { data: n, error: t } = await e.from("currencies").select("code, is_default, is_active").eq("is_active", !0);
875
- if (t)
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(n) ? n : [], i = r.find((a) => a.is_default) || r[0];
878
- return Te(i?.code || "USD");
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 gn(e) {
884
- const n = e.contentType === "page" ? "pages" : e.contentType === "post" ? "posts" : "products";
885
- let t = "id", r = e.entityId;
886
- if (r === void 0 && e.slug && (t = "slug", r = e.slug), r === void 0 && e.title && (t = "title", r = e.title), r === void 0)
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: i, error: a } = await e.supabase.from(n).select("*").eq(t, r);
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}: ${f(a)}`);
891
- const s = Array.isArray(i) ? i : i ? [i] : [];
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 ${t} "${String(r)}".` : `Multiple ${e.contentType}s matched ${t} "${String(r)}"; use an exact id.`
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 ve(e, n) {
899
- const t = Ke.safeParse(n?.pageContext).success ? n?.pageContext : null, r = e.contentType || t?.contentType;
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 i = e.entityId !== void 0 || !!e.slug || !!e.title, a = e.entityId ?? (i ? void 0 : t?.entityId), s = e.slug ?? (i ? void 0 : t?.slug ?? void 0), l = e.title ?? (i ? void 0 : t?.title ?? void 0), m = await gn({
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: h(n),
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: m
957
+ item: u
912
958
  };
913
959
  }
914
- async function X(e) {
915
- const n = await _n({
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
- }), t = {
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: n?.pageId ?? null,
971
+ page_id: t?.pageId ?? null,
926
972
  parent_id: e.parentId ?? null,
927
- ...n?.navigationTranslationGroupId ? { translation_group_id: n.navigationTranslationGroupId } : {},
973
+ ...t?.navigationTranslationGroupId ? { translation_group_id: t.navigationTranslationGroupId } : {},
928
974
  url: e.item.url
929
- }, { data: r, error: i } = await e.supabase.from("navigation_items").insert(t).select("id").single();
930
- if (i)
931
- throw new Error(`Failed to insert ${e.menuKey} navigation item: ${f(i)}`);
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 fn(e) {
935
- const n = e.trim();
936
- if (!n.startsWith("/") || n.startsWith("//"))
980
+ function jn(e) {
981
+ const t = e.trim();
982
+ if (!t.startsWith("/") || t.startsWith("//"))
937
983
  return null;
938
- const t = n.split("?")[0]?.split("#")[0] || "", r = t === "/" ? "home" : t.replace(/^\/+|\/+$/g, "");
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 _n(e) {
942
- const n = fn(e.item.url);
943
- if (!n)
987
+ async function qn(e) {
988
+ const t = jn(e.item.url);
989
+ if (!t)
944
990
  return null;
945
- const { data: t, error: r } = await e.supabase.from("pages").select("id, slug, translation_group_id, language_id").eq("slug", n).eq("language_id", e.languageId);
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: ${f(r)}`);
948
- const i = Array.isArray(t) ? t[0] : t;
949
- if (!i?.id)
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 = Ce();
952
- if (i.translation_group_id) {
953
- const { data: s, error: l } = await e.supabase.from("pages").select("id").eq("translation_group_id", i.translation_group_id);
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: ${f(l)}`
1002
+ `Failed to inspect linked page translations for navigation item: ${h(l)}`
957
1003
  );
958
- const m = new Set(
1004
+ const u = new Set(
959
1005
  (Array.isArray(s) ? s : []).map((g) => String(g.id)).filter(Boolean)
960
- ), { data: u, error: c } = await e.supabase.from("navigation_items").select("id, page_id, translation_group_id, menu_key").eq("menu_key", e.menuKey);
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: ${f(c)}`
1009
+ `Failed to inspect related navigation translations: ${h(c)}`
964
1010
  );
965
- const d = (Array.isArray(u) ? u : []).find((g) => g.translation_group_id && m.has(String(g.page_id)));
966
- d?.translation_group_id && (a = d.translation_group_id);
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(i.id)
1016
+ pageId: Number(o.id)
971
1017
  };
972
1018
  }
973
- async function rt(e) {
974
- const n = await U(e.supabase, e.languageCode), { data: t, error: r } = await e.supabase.from("navigation_items").select("id, parent_id").eq("menu_key", e.menuKey).eq("language_id", n.id);
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: ${f(r)}`
1023
+ `Failed to inspect existing ${e.menuKey} navigation items: ${h(r)}`
978
1024
  );
979
- const i = Array.isArray(t) ? t : [], a = i.filter((u) => u.parent_id == null).length, s = ot(e.items);
980
- it({
981
- existingItemCount: i.length,
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: n.code,
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", n.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: ${f(l)}`);
990
- let m = 0;
991
- for (const [u, c] of e.items.entries()) {
992
- const d = await X({
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: n.id,
1040
+ languageId: t.id,
995
1041
  menuKey: e.menuKey,
996
- order: u,
1042
+ order: d,
997
1043
  supabase: e.supabase
998
1044
  });
999
- m++;
1000
- for (const [g, p] of (c.children ?? []).entries())
1001
- await X({
1002
- item: p,
1003
- languageId: n.id,
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: d,
1052
+ parentId: p,
1007
1053
  supabase: e.supabase
1008
- }), m++;
1054
+ }), u++;
1009
1055
  }
1010
1056
  return {
1011
- insertedCount: m,
1012
- languageCode: n.code,
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 it(e) {
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 bn(e) {
1025
- const n = await U(e.supabase, e.languageCode), { data: t, error: r } = await e.supabase.from("navigation_items").select("id, parent_id").eq("menu_key", e.menuKey).eq("language_id", n.id);
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: ${f(r)}`
1074
+ `Failed to inspect existing ${e.menuKey} navigation items: ${h(r)}`
1029
1075
  );
1030
- const i = Array.isArray(t) ? t : [];
1031
- it({
1032
- existingItemCount: i.length,
1033
- existingTopLevelCount: i.filter((a) => a.parent_id == null).length,
1034
- languageCode: n.code,
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: ot(e.items)
1082
+ replacementItemCount: bt(e.items)
1037
1083
  });
1038
1084
  }
1039
- async function yn(e) {
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 n = await U(e.supabase, e.languageCode), t = e.items[0], r = q(e.match?.url) || q(t.url), i = Oe(e.match?.label), { data: a, error: s } = await e.supabase.from("navigation_items").select("id, label, url, parent_id, order").eq("menu_key", e.menuKey).eq("language_id", n.id);
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: ${f(s)}`
1091
+ `Failed to load existing ${e.menuKey} navigation items: ${h(s)}`
1046
1092
  );
1047
- const m = (Array.isArray(a) ? a : []).find((c) => {
1048
- const d = q(c.url), g = Oe(c.label);
1049
- return !!(r && d === r || i && g === i);
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 (!m?.id)
1097
+ if (!u?.id)
1052
1098
  throw new Error(
1053
- `Could not find a ${e.menuKey} navigation item to update in ${n.code}. Use a matching label or url.`
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: u } = await e.supabase.from("navigation_items").update({
1056
- label: t.label,
1057
- url: t.url
1058
- }).eq("id", m.id);
1059
- if (u)
1060
- throw new Error(`Failed to update ${e.menuKey} navigation item: ${f(u)}`);
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: n.code,
1109
+ languageCode: t.code,
1064
1110
  menuKey: e.menuKey,
1065
1111
  skippedCount: 0,
1066
1112
  updatedCount: 1
1067
1113
  };
1068
1114
  }
1069
- async function hn(e) {
1070
- const n = await U(e.supabase, e.languageCode), { data: t, error: r } = await e.supabase.from("navigation_items").select("id, url, parent_id, order").eq("menu_key", e.menuKey).eq("language_id", n.id);
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: ${f(r)}`
1119
+ `Failed to load existing ${e.menuKey} navigation items: ${h(r)}`
1074
1120
  );
1075
- let i = 0, a = 0;
1076
- const s = Array.isArray(t) ? t : [], l = new Set(
1077
- s.map((c) => q(c.url)).filter(Boolean)
1078
- ), m = s.filter((c) => c.parent_id == null).map((c) => Number(c.order)).filter(Number.isFinite);
1079
- let u = m.length > 0 ? Math.max(...m) + 1 : s.length;
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 d = q(c.url);
1082
- if (d && l.has(d)) {
1127
+ const p = R(c.url);
1128
+ if (p && l.has(p)) {
1083
1129
  a++;
1084
1130
  continue;
1085
1131
  }
1086
- const g = await X({
1132
+ const g = await ie({
1087
1133
  item: c,
1088
- languageId: n.id,
1134
+ languageId: t.id,
1089
1135
  menuKey: e.menuKey,
1090
- order: u,
1136
+ order: d,
1091
1137
  supabase: e.supabase
1092
1138
  });
1093
- i++, u++, d && l.add(d);
1094
- let p = 0;
1095
- for (const _ of c.children ?? []) {
1096
- const k = q(_.url);
1097
- if (k && l.has(k)) {
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 X({
1102
- item: _,
1103
- languageId: n.id,
1147
+ await ie({
1148
+ item: f,
1149
+ languageId: t.id,
1104
1150
  menuKey: e.menuKey,
1105
- order: p,
1151
+ order: m,
1106
1152
  parentId: g,
1107
1153
  supabase: e.supabase
1108
- }), i++, p++, k && l.add(k);
1154
+ }), o++, m++, _ && l.add(_);
1109
1155
  }
1110
1156
  }
1111
1157
  return {
1112
- insertedCount: i,
1113
- languageCode: n.code,
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 b(e) {
1165
+ function x(e) {
1120
1166
  return typeof e == "string" && e.trim() ? e.trim() : "";
1121
1167
  }
1122
- function kn(e) {
1168
+ function Mn(e) {
1123
1169
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;");
1124
1170
  }
1125
- function wn(e) {
1126
- const n = b(e.field_type ?? e.fieldType ?? e.type ?? e.input_type).toLowerCase().replace(/\s+/g, "_"), t = b(e.label ?? e.name ?? e.placeholder).toLowerCase();
1127
- return ["email", "textarea", "select", "radio", "checkbox", "text"].includes(n) ? n : t.includes("email") ? "email" : t.includes("message") || t.includes("comment") || t.includes("details") ? "textarea" : "text";
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 In(e) {
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((t, r) => {
1135
- const i = R(t) ? t : {}, a = b(i.label ?? i.name) || (r === 0 ? "Name" : r === 1 ? "Email" : "Message"), s = wn({ ...i, label: a }), l = i.is_required ?? i.isRequired ?? i.required;
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(i.options) ? i.options : void 0,
1141
- placeholder: b(i.placeholder) || void 0,
1142
- temp_id: b(i.temp_id ?? i.tempId ?? i.id) || `field-${r + 1}`
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
- function at(e, n, t, r) {
1147
- const i = H(n);
1148
- if (e === "heading" && (i.text_content = b(i.text_content) || b(i.text) || b(i.title) || b(i.heading) || "Untitled", i.level = typeof i.level == "number" ? i.level : 1), e === "text") {
1149
- const a = b(i.html_content) || b(i.html) || b(i.content) || b(i.text);
1150
- a && (i.html_content = /<\/?[a-z][\s\S]*>/i.test(a) ? a : `<p>${kn(a)}</p>`);
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 e === "button" && (i.text = b(i.text) || b(i.label) || b(i.title) || "Learn More", i.url = b(i.url) || b(i.href) || b(i.link) || "#"), e === "form" && (i.fields = In(i.fields), i.submit_button_text = b(i.submit_button_text ?? i.submitButtonText ?? i.button_text) || "Send Message", i.success_message = b(i.success_message ?? i.successMessage) || "Thanks for reaching out. We will reply as soon as possible."), j(e, i, t, r), i;
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 Z(e, n, t) {
1155
- const r = at(
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
- G(e.content, `Block ${n}`),
1158
- `Block ${n}`,
1159
- t
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 ?? n
1290
+ order: e.order ?? t
1165
1291
  };
1166
1292
  }
1167
- function Cn(e, n = "Contact Us", t) {
1293
+ function tr(e, t = "Contact Us", n) {
1168
1294
  return [
1169
- Z(
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: n
1308
+ text_content: t
1183
1309
  },
1184
- temp_id: Q("heading")
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: Q("text")
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
- t
1329
+ n
1204
1330
  ),
1205
- Z(
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
- t
1364
+ n
1239
1365
  )
1240
1366
  ];
1241
1367
  }
1242
- function st(e, n, t, r) {
1243
- return (!e || e.length === 0) && n ? Cn(n, t, r) : (e || []).map((i, a) => Z(i, a, r));
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 Se(e) {
1246
- const n = e.contentType === "page" ? "pages" : e.contentType === "post" ? "posts" : "products", { data: t, error: r } = await e.supabase.from(n).select("id, title, slug, language_id").eq("slug", e.slug).eq("language_id", e.languageId);
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: ${f(r)}`);
1249
- const i = Array.isArray(t) ? t : [];
1250
- return i.length > 0 ? {
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: i[0],
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 Ee(e) {
1384
+ async function Le(e) {
1259
1385
  if (!e.suppliedTranslationGroupId)
1260
1386
  return {
1261
1387
  translationGroupId: void 0
1262
1388
  };
1263
- const n = e.contentType === "page" ? "pages" : e.contentType === "post" ? "posts" : "products", { data: t, error: r } = await e.supabase.from(n).select("id, title, slug, language_id, translation_group_id").eq("translation_group_id", e.suppliedTranslationGroupId);
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: ${f(r)}`
1392
+ `Failed to inspect ${e.contentType} translation group: ${h(r)}`
1267
1393
  );
1268
- const i = Array.isArray(t) ? t : [];
1269
- if (i.length === 0)
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 = i.find(
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 lt(e) {
1420
+ async function Tt(e) {
1295
1421
  if (e.blocks.length === 0)
1296
1422
  return [];
1297
- const n = e.blocks.map((i, a) => ({
1298
- block_type: i.block_type,
1299
- content: i.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: i.order ?? a,
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: t, error: r } = await e.supabase.from("blocks").insert(n).select("*");
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: ${f(r)}`);
1307
- return Array.isArray(t) ? t : [];
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 ct(e) {
1310
- const n = e.contentType === "page" ? "pages" : "posts";
1311
- await e.supabase.from(n).delete().eq("id", e.itemId);
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 Ae(e, n) {
1314
- return e === "page" ? `/cms/pages/${n}/edit` : e === "post" ? `/cms/posts/${n}/edit` : `/cms/products/${n}/edit`;
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 Ue(e) {
1442
+ function Xe(e) {
1317
1443
  return e === "page" ? "/cms/pages" : e === "post" ? "/cms/posts" : "/cms/products";
1318
1444
  }
1319
- async function ut(e, n) {
1320
- const t = ee.parse(e), r = h(n);
1321
- t.mode === "replace" && await bn({
1322
- items: t.items,
1323
- languageCode: t.languageCode,
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 i = x({
1453
+ const o = P({
1328
1454
  action: "UPDATE NAVIGATION",
1329
- context: n,
1330
- payload: { input: t, tool: "update_navigation_bar" },
1455
+ context: t,
1456
+ payload: { input: n, tool: "update_navigation_bar" },
1331
1457
  preview: {
1332
- itemCount: t.items.length,
1333
- languageCode: t.languageCode,
1334
- mode: t.mode,
1458
+ itemCount: n.items.length,
1459
+ languageCode: n.languageCode,
1460
+ mode: n.mode,
1335
1461
  target: "header navigation"
1336
1462
  },
1337
- subject: `${t.mode} header`
1463
+ subject: `${n.mode} header`
1338
1464
  });
1339
- if (i)
1340
- return i;
1341
- const a = t.mode === "update" ? await yn({
1342
- items: t.items,
1343
- languageCode: t.languageCode,
1344
- match: t.match,
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
- }) : t.mode === "append" ? await hn({
1348
- items: t.items,
1349
- languageCode: t.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 rt({
1353
- items: t.items,
1354
- languageCode: t.languageCode,
1478
+ }) : await kt({
1479
+ items: n.items,
1480
+ languageCode: n.languageCode,
1355
1481
  menuKey: "HEADER",
1356
1482
  supabase: r
1357
1483
  });
1358
- return Qe(n), {
1484
+ return mt(t), {
1359
1485
  ...a,
1360
1486
  mutationExecuted: !0,
1361
- mode: t.mode,
1487
+ mode: n.mode,
1362
1488
  success: !0
1363
1489
  };
1364
1490
  }
1365
- async function dt(e, n) {
1366
- const t = te.parse(e);
1367
- if (!t.links?.length && !t.copyright)
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 = h(n), i = x({
1495
+ const r = I(t), o = P({
1370
1496
  action: "UPDATE FOOTER",
1371
- context: n,
1372
- payload: { input: t, tool: "update_footer" },
1497
+ context: t,
1498
+ payload: { input: n, tool: "update_footer" },
1373
1499
  preview: {
1374
- copyrightUpdated: !!t.copyright,
1375
- linkCount: t.links?.length || 0,
1376
- languageCode: t.languageCode,
1500
+ copyrightUpdated: !!n.copyright,
1501
+ linkCount: n.links?.length || 0,
1502
+ languageCode: n.languageCode,
1377
1503
  target: "footer"
1378
1504
  },
1379
- subject: t.languageCode
1505
+ subject: n.languageCode
1380
1506
  });
1381
- if (i)
1382
- return i;
1507
+ if (o)
1508
+ return o;
1383
1509
  let a = null;
1384
- if (t.links?.length && (a = await rt({
1385
- items: t.links,
1386
- languageCode: t.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
- })), t.copyright) {
1515
+ })), n.copyright) {
1390
1516
  const { error: s } = await r.from("site_settings").upsert({
1391
1517
  key: "footer_copyright",
1392
- value: t.copyright
1518
+ value: n.copyright
1393
1519
  });
1394
1520
  if (s)
1395
- throw new Error(`Failed to update footer copyright: ${f(s)}`);
1521
+ throw new Error(`Failed to update footer copyright: ${h(s)}`);
1396
1522
  }
1397
- return Qe(n), {
1398
- copyrightUpdated: !!t.copyright,
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 pt(e) {
1530
+ function St(e) {
1405
1531
  return typeof e == "string" ? e.toLowerCase() : "";
1406
1532
  }
1407
- function Tn(e, n) {
1408
- const t = n.map(pt).join(" ");
1409
- return e.reduce((r, i) => r + (t.includes(i) ? 1 : 0), 0);
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 De(e, n) {
1537
+ function Qe(e, t) {
1412
1538
  return (e.find(
1413
- (t) => n.some((r) => pt(t).includes(r))
1414
- ) || e.find((t) => t.trim().length > 0) || "No excerpt available.").slice(0, 500);
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 xn(e, n) {
1417
- const t = ye.parse(e), r = h(n), i = t.query.toLowerCase().split(/\s+/).map((c) => c.trim()).filter(Boolean), [a, s] = await Promise.all([
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: ${f(a.error)}`);
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: ${f(s.error)}`);
1550
+ throw new Error(`Failed to search documentation pages: ${h(s.error)}`);
1425
1551
  const l = (a.data ?? []).map((c) => ({
1426
- excerpt: De(
1552
+ excerpt: Qe(
1427
1553
  [c.excerpt, c.subtitle, c.meta_description, c.slug].filter(Boolean),
1428
- i
1554
+ o
1429
1555
  ),
1430
1556
  source: "post",
1431
1557
  title: c.title,
1432
1558
  url: `/article/${c.slug}`
1433
- })), m = (s.data ?? []).map((c) => ({
1434
- excerpt: De([c.meta_description, c.slug].filter(Boolean), i),
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
- })), u = [...l, ...m].map((c) => ({
1564
+ })), d = [...l, ...u].map((c) => ({
1439
1565
  ...c,
1440
- score: Tn(i, [c.title, c.excerpt, c.url])
1441
- })).filter((c) => c.score > 0).sort((c, d) => d.score - c.score).slice(0, t.limit).map((c) => ({
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: t.query,
1449
- results: u,
1574
+ query: n.query,
1575
+ results: d,
1450
1576
  success: !0
1451
1577
  };
1452
1578
  }
1453
- async function $n(e, n, t = At) {
1454
- const r = ye.safeParse(e), i = r.success ? r.data.query : "";
1455
- return Qt(
1456
- xn(e, n),
1457
- t,
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: i,
1586
+ query: o,
1461
1587
  results: [],
1462
1588
  success: !1,
1463
1589
  timedOut: !0
1464
1590
  })
1465
1591
  );
1466
1592
  }
1467
- const vn = [
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
- ], Sn = {
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 En(e) {
1618
+ function sr(e) {
1493
1619
  return String(e ?? "unknown").trim().toLowerCase() || "unknown";
1494
1620
  }
1495
- function Me(e) {
1496
- const n = Object.fromEntries(
1497
- vn.map((t) => [t, 0])
1621
+ function Ze(e) {
1622
+ const t = Object.fromEntries(
1623
+ ir.map((n) => [n, 0])
1498
1624
  );
1499
- for (const t of e) {
1500
- const r = En(t.status);
1501
- n[r] = (n[r] ?? 0) + 1;
1625
+ for (const n of e) {
1626
+ const r = sr(n.status);
1627
+ t[r] = (t[r] ?? 0) + 1;
1502
1628
  }
1503
- return n;
1629
+ return t;
1504
1630
  }
1505
- function An(e) {
1506
- const t = e.toLowerCase().replace(/[^a-z0-9_]+/g, " ").split(/\s+/).filter(Boolean);
1507
- for (const r of t) {
1508
- const i = Sn[r];
1509
- if (i)
1510
- return i;
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 L(e) {
1515
- const n = Number(e);
1516
- return Number.isFinite(n) ? n : 0;
1640
+ function V(e) {
1641
+ const t = Number(e);
1642
+ return Number.isFinite(t) ? t : 0;
1517
1643
  }
1518
- async function Pn(e, n) {
1519
- const t = ze.parse(e), r = h(n), i = /* @__PURE__ */ new Date();
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 (t.timeRange) {
1647
+ switch (n.timeRange) {
1522
1648
  case "today":
1523
- a = new Date(i.getFullYear(), i.getMonth(), i.getDate());
1649
+ a = new Date(o.getFullYear(), o.getMonth(), o.getDate());
1524
1650
  break;
1525
1651
  case "this_month":
1526
- a = new Date(i.getFullYear(), i.getMonth(), 1);
1652
+ a = new Date(o.getFullYear(), o.getMonth(), 1);
1527
1653
  break;
1528
1654
  case "last_7_days":
1529
- a = new Date(i.getTime() - 10080 * 60 * 1e3);
1655
+ a = new Date(o.getTime() - 10080 * 60 * 1e3);
1530
1656
  break;
1531
1657
  case "last_30_days":
1532
- a = new Date(i.getTime() - 720 * 60 * 60 * 1e3);
1658
+ a = new Date(o.getTime() - 720 * 60 * 60 * 1e3);
1533
1659
  break;
1534
1660
  case "last_month":
1535
- a = new Date(i.getFullYear(), i.getMonth() - 1, 1), s = new Date(i.getFullYear(), i.getMonth(), 0, 23, 59, 59, 999);
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(i.getTime() - 2160 * 60 * 60 * 1e3);
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 = t.currency?.toUpperCase(), m = An(t.query), u = r.from("orders").select("id, status, total, currency, created_at, paid_at");
1545
- l && u.eq("currency", l), a && u.gte("created_at", a.toISOString()), s && u.lte("created_at", s.toISOString());
1546
- const d = t.reportType === "products" || t.reportType === "revenue" || t.reportType === "general" ? r.from("order_items").select(`
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
- d && (l && d.eq("orders.currency", l), a && d.gte("orders.paid_at", a.toISOString()), s && d.lte("orders.paid_at", s.toISOString()));
1562
- const p = t.timeRange !== "all_time" && (t.reportType === "orders" || m) ? r.from("orders").select("id, status, currency") : null;
1563
- p && l && p.eq("currency", l);
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: _, error: k },
1566
- { data: E, error: S },
1567
- A
1691
+ { data: f, error: _ },
1692
+ { data: k, error: w },
1693
+ E
1568
1694
  ] = await Promise.all([
1569
- u,
1570
- d ?? Promise.resolve({ data: [], error: null }),
1571
- p ?? Promise.resolve({ data: null, error: null })
1695
+ d,
1696
+ p ?? Promise.resolve({ data: [], error: null }),
1697
+ m ?? Promise.resolve({ data: null, error: null })
1572
1698
  ]);
1573
- if (k)
1574
- throw new Error(`Failed to fetch ecommerce stats: ${f(k)}`);
1575
- if (S)
1576
- throw new Error(`Failed to fetch ecommerce stats: ${f(S)}`);
1577
- if (A.error)
1578
- throw new Error(`Failed to fetch ecommerce stats: ${f(A.error)}`);
1579
- const y = Array.isArray(_) ? _ : [], I = Array.isArray(E) ? E : [], P = Me(y), $ = Array.isArray(A.data) ? A.data : null, D = $ ? Me($) : null, z = {};
1580
- for (const C of I) {
1581
- const T = Array.isArray(C.orders) ? C.orders[0] : C.orders, B = String(T?.currency || l || "unknown").toUpperCase();
1582
- z[B] = (z[B] ?? 0) + L(C.quantity) * L(C.price_at_purchase) / 100;
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 K = {
1710
+ const z = {
1585
1711
  currency: l ?? null,
1586
1712
  currencyFiltered: !!l,
1587
- orderStatusCounts: P,
1588
- paidOrderCount: P.paid ?? 0,
1589
- query: t.query,
1590
- reportType: t.reportType,
1591
- revenueByCurrency: z,
1592
- timeRange: t.timeRange,
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(z).reduce(
1595
- (C, T) => C + T,
1720
+ totalRevenue: Object.values(B).reduce(
1721
+ (b, $) => b + $,
1596
1722
  0
1597
1723
  )
1598
1724
  };
1599
- if (D && (K.allTimeOrderStatusCounts = D), m && (K.matchingOrderStatus = {
1600
- allTimeCount: D?.[m] ?? P[m] ?? 0,
1601
- count: P[m] ?? 0,
1602
- status: m,
1603
- timeRange: t.timeRange
1604
- }), t.reportType === "products" || t.reportType === "revenue" || t.reportType === "general") {
1605
- const C = {};
1606
- for (const T of I) {
1607
- const B = Array.isArray(T.products) ? T.products[0] : T.products;
1608
- if (!B?.id)
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 M = B.id;
1611
- C[M] || (C[M] = {
1612
- id: M,
1736
+ const K = O.id;
1737
+ b[K] || (b[K] = {
1738
+ id: K,
1613
1739
  quantity: 0,
1614
1740
  revenue: 0,
1615
- title: B.title,
1616
- type: B.product_type
1617
- }), C[M].quantity += L(T.quantity), C[M].revenue += L(T.quantity) * L(T.price_at_purchase) / 100;
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
- K.topProducts = Object.values(C).sort((T, B) => B.revenue - T.revenue).slice(0, 10);
1745
+ z.topProducts = Object.values(b).sort(($, O) => O.revenue - $.revenue).slice(0, 10);
1620
1746
  }
1621
1747
  return {
1622
- report: K,
1748
+ report: z,
1623
1749
  success: !0
1624
1750
  };
1625
1751
  }
1626
- async function Bn(e, n) {
1627
- const t = Ve.parse(e), r = h(n), i = pe(n), a = we(i), s = i.contentType === "page" ? "pages" : i.contentType === "post" ? "posts" : "products", { data: l, error: m } = await r.from(s).select("*").eq("id", a).single();
1628
- if (m || !l)
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 ${i.contentType}: ${f(m)}`
1756
+ `Failed to read current ${o.contentType}: ${h(u)}`
1631
1757
  );
1632
- let u = [];
1633
- if (t.includeBlocks && i.contentType !== "product") {
1634
- const c = i.contentType === "page" ? "page_id" : "post_id", { data: d, error: g } = await r.from("blocks").select("id, page_id, post_id, language_id, block_type, content, order").eq(c, a);
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 ${i.contentType} blocks: ${f(g)}`);
1637
- u = (Array.isArray(d) ? d : []).slice().sort((p, _) => Number(p.order) - Number(_.order)).map((p) => pn(p, t.includeBlockContent));
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: u,
1641
- context: i,
1766
+ blocks: d,
1767
+ context: o,
1642
1768
  item: l,
1643
1769
  success: !0
1644
1770
  };
1645
1771
  }
1646
- const mt = /* @__PURE__ */ new Set([
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
- ]), gt = /* @__PURE__ */ new Set([
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
- ]), Fn = /* @__PURE__ */ new Set([
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
- ]), Nn = /* @__PURE__ */ new Set([
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 jn(e) {
1686
- return e === "page" ? mt : e === "post" ? gt : Fn;
1811
+ function mr(e) {
1812
+ return e === "page" ? Et : e === "post" ? $t : dr;
1687
1813
  }
1688
- function ft(e, n) {
1689
- return Nn.has(e) && n === "" ? null : n;
1814
+ function At(e, t) {
1815
+ return pr.has(e) && t === "" ? null : t;
1690
1816
  }
1691
- function be(e, n) {
1692
- if (typeof n != "string")
1817
+ function Se(e, t) {
1818
+ if (typeof t != "string")
1693
1819
  return;
1694
- const t = e === "product" ? ["active", "archived", "draft"] : ["archived", "draft", "published"];
1695
- if (!t.includes(n))
1820
+ const n = e === "product" ? ["active", "archived", "draft"] : ["archived", "draft", "published"];
1821
+ if (!n.includes(t))
1696
1822
  throw new Error(
1697
- `Status "${n}" is not valid for ${e}. Allowed statuses: ${t.join(", ")}.`
1823
+ `Status "${t}" is not valid for ${e}. Allowed statuses: ${n.join(", ")}.`
1698
1824
  );
1699
1825
  }
1700
- function qn(e, n) {
1701
- const t = jn(n.contentType), r = {};
1702
- for (const [i, a] of Object.entries(e))
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 (!t.has(i))
1830
+ if (!n.has(o))
1705
1831
  throw new Error(
1706
- `Field "${i}" cannot be updated for ${n.contentType} content.`
1832
+ `Field "${o}" cannot be updated for ${t.contentType} content.`
1707
1833
  );
1708
- i === "status" && be(n.contentType, a), r[i] = ft(i, a);
1834
+ o === "status" && Se(t.contentType, a), r[o] = At(o, a);
1709
1835
  }
1710
1836
  return r;
1711
1837
  }
1712
- async function _t(e, n) {
1713
- const t = ne.parse(e), r = h(n), i = pe(n), a = we(i), s = qn(t.fields, i), l = Object.keys(s);
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 m = x({
1842
+ const u = P({
1717
1843
  action: "UPDATE CMS FIELDS",
1718
- context: n,
1844
+ context: t,
1719
1845
  payload: {
1720
- contentType: i.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: i.contentType,
1852
+ contentType: o.contentType,
1727
1853
  entityId: a,
1728
1854
  fields: l,
1729
- slug: i.slug,
1730
- title: i.title
1855
+ slug: o.slug,
1856
+ title: o.title
1731
1857
  },
1732
- subject: `${i.contentType} ${String(a)}`
1858
+ subject: `${o.contentType} ${String(a)}`
1733
1859
  });
1734
- if (m)
1735
- return m;
1736
- const u = i.contentType === "page" ? "pages" : i.contentType === "post" ? "posts" : "products", { data: c, error: d } = await r.from(u).update({
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 (d || !c)
1871
+ if (p || !c)
1741
1872
  throw new Error(
1742
- `Failed to update current ${i.contentType}: ${f(d)}`
1873
+ `Failed to update current ${o.contentType}: ${h(p)}`
1743
1874
  );
1744
- return F(n, i, c.slug), {
1745
- contentType: i.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 bt(e, n) {
1754
- const t = oe.parse(e), r = h(n), i = pe(n), { data: a, error: s } = await r.from("blocks").select("id, page_id, post_id, language_id, block_type, content, order").eq("id", t.blockId).single();
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 ${t.blockId}: ${f(s)}`);
1757
- et(a, i);
1758
- const l = Y(a.block_type, `Block ${t.blockId}`);
1759
- tt(t.blockType, l, `Block ${t.blockId}`);
1760
- const m = G(a.content, `Block ${t.blockId}`), u = dn(
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
- m,
1763
- t.content,
1764
- n
1893
+ u,
1894
+ n.content,
1895
+ t
1765
1896
  );
1766
- j(l, u, `Block ${t.blockId}`, n);
1767
- const c = x({
1897
+ L(l, d, `Block ${n.blockId}`, t);
1898
+ const c = P({
1768
1899
  action: "UPDATE CONTENT BLOCK",
1769
- context: n,
1900
+ context: t,
1770
1901
  payload: {
1771
- blockId: t.blockId,
1902
+ blockId: n.blockId,
1772
1903
  blockType: l,
1773
- content: u,
1904
+ content: d,
1774
1905
  tool: "update_content_block"
1775
1906
  },
1776
1907
  preview: {
1777
- blockId: t.blockId,
1908
+ blockId: n.blockId,
1778
1909
  blockType: l,
1779
- contentType: i.contentType,
1780
- entityId: we(i)
1910
+ contentType: o.contentType,
1911
+ entityId: be(o)
1781
1912
  },
1782
- subject: `${l} block ${t.blockId}`
1913
+ subject: `${l} block ${n.blockId}`
1783
1914
  });
1784
1915
  if (c)
1785
1916
  return c;
1786
- const { data: d, error: g } = await r.from("blocks").update({
1787
- content: u,
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", t.blockId).select("id, block_type, order").single();
1790
- if (g || !d)
1791
- throw new Error(`Failed to update block ${t.blockId}: ${f(g)}`);
1792
- return F(n, i), {
1793
- blockId: d.id,
1794
- blockType: d.block_type,
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 yt(e, n) {
1801
- const t = ae.parse(e), r = h(n), i = await ve(t, n);
1802
- if (i.contentType === "product")
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(i.item.id), s = i.contentType === "page" ? "page_id" : "post_id", l = async () => {
1805
- const { data: y, error: I } = await r.from("blocks").select("id, page_id, post_id, language_id, block_type, content, order").eq(s, a);
1806
- if (I)
1807
- throw new Error(`Failed to read ${i.contentType} blocks: ${f(I)}`);
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
- (P, $) => Number(P.order) - Number($.order)
1940
+ (v, S) => Number(v.order) - Number(S.order)
1810
1941
  );
1811
- }, m = (y) => {
1812
- if (t.position === "start")
1942
+ }, u = (y) => {
1943
+ if (n.position === "start")
1813
1944
  return 0;
1814
- if (t.position === "end") {
1815
- const $ = y.map((D) => Number(D.order)).filter(Number.isFinite);
1816
- return $.length > 0 ? Math.max(...$) + 1 : 0;
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 I = t.anchorBlockId ? y.find(($) => Number($.id) === t.anchorBlockId) : t.anchorBlockType ? y.find(($) => $.block_type === t.anchorBlockType) : null;
1819
- if (!I)
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
- t.anchorBlockType ? `Could not find a ${t.anchorBlockType} block to insert ${t.position}.` : `Could not find block ${t.anchorBlockId} to insert ${t.position}.`
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 P = Number(I.order);
1824
- return t.position === "before" ? P : P + 1;
1825
- }, u = Z(t.block, 0, n), c = await l(), d = m(c), g = {
1826
- contentType: i.contentType,
1827
- entityId: i.item.id,
1828
- languageId: i.item.language_id,
1829
- slug: i.item.slug,
1830
- title: i.item.title,
1831
- translationGroupId: i.item.translation_group_id
1832
- }, p = x({
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: n,
1965
+ context: t,
1835
1966
  payload: {
1836
- block: u,
1837
- order: d,
1967
+ block: d,
1968
+ order: p,
1838
1969
  target: {
1839
- contentType: i.contentType,
1840
- id: i.item.id,
1841
- slug: i.item.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: t.anchorBlockId,
1847
- anchorBlockType: t.anchorBlockType,
1848
- blockType: u.block_type,
1849
- contentType: i.contentType,
1850
- entityId: i.item.id,
1851
- position: t.position,
1852
- slug: i.item.slug,
1853
- summary: `Insert ${u.block_type} block ${t.position} ${t.anchorBlockType ? `the first ${t.anchorBlockType} block` : t.anchorBlockId ? `block ${t.anchorBlockId}` : "the content"} on ${i.contentType} "${i.item.title || i.item.slug}".`,
1854
- title: i.item.title
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: `${u.block_type} block on ${i.contentType} ${i.item.id}`
1987
+ subject: `${d.block_type} block on ${o.contentType} ${o.item.id}`
1857
1988
  });
1858
- if (p)
1859
- return p;
1860
- const _ = await l(), k = m(_), E = _.filter((y) => Number(y.order) >= k).sort((y, I) => Number(I.order) - Number(y.order));
1861
- for (const y of E) {
1862
- const { error: I } = await r.from("blocks").update({
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 (I)
1867
- throw new Error(`Failed to shift block ${y.id}: ${f(I)}`);
1997
+ if (C)
1998
+ throw new Error(`Failed to shift block ${y.id}: ${h(C)}`);
1868
1999
  }
1869
- const { data: S, error: A } = await r.from("blocks").insert({
1870
- block_type: u.block_type,
1871
- content: u.content,
1872
- language_id: i.item.language_id,
1873
- order: k,
1874
- page_id: i.contentType === "page" ? a : null,
1875
- post_id: i.contentType === "post" ? a : null
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 (A || !S)
1878
- throw new Error(`Failed to insert content block: ${f(A)}`);
1879
- return F(n, g), {
1880
- blockId: S.id,
1881
- blockType: S.block_type,
1882
- contentType: i.contentType,
1883
- entityId: i.item.id,
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: S.order,
2016
+ order: w.order,
1886
2017
  success: !0
1887
2018
  };
1888
2019
  }
1889
- async function ht(e, n) {
1890
- const t = re.parse(e), r = h(n), i = pe(n), { data: a, error: s } = await r.from("blocks").select("id, page_id, post_id, language_id, block_type, content, order").eq("id", t.parentBlockId).single();
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 ${t.parentBlockId}: ${f(s)}`
2024
+ `Failed to read parent block ${n.parentBlockId}: ${h(s)}`
1894
2025
  );
1895
- et(a, i);
1896
- const l = Y(
2026
+ ht(a, o);
2027
+ const l = re(
1897
2028
  a.block_type,
1898
- `Parent block ${t.parentBlockId}`
2029
+ `Parent block ${n.parentBlockId}`
1899
2030
  );
1900
2031
  if (l !== "section")
1901
2032
  throw new Error(
1902
- `Parent block ${t.parentBlockId} must be a section block, not "${l}".`
2033
+ `Parent block ${n.parentBlockId} must be a section block, not "${l}".`
1903
2034
  );
1904
- const m = G(
2035
+ const u = X(
1905
2036
  a.content,
1906
- `Parent block ${t.parentBlockId}`
2037
+ `Parent block ${n.parentBlockId}`
1907
2038
  );
1908
- j(
2039
+ L(
1909
2040
  l,
1910
- m,
1911
- `Parent block ${t.parentBlockId}`,
1912
- n
2041
+ u,
2042
+ `Parent block ${n.parentBlockId}`,
2043
+ t
1913
2044
  );
1914
- const c = m.column_blocks?.[t.columnIndex]?.[t.blockIndex];
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 ${t.columnIndex}, index ${t.blockIndex}.`
2048
+ `Nested block was not found at column ${n.columnIndex}, index ${n.blockIndex}.`
1918
2049
  );
1919
- const d = Y(
2050
+ const p = re(
1920
2051
  c.block_type,
1921
- `Nested block ${t.columnIndex}:${t.blockIndex}`
2052
+ `Nested block ${n.columnIndex}:${n.blockIndex}`
1922
2053
  );
1923
- tt(
1924
- t.blockType,
1925
- d,
1926
- `Nested block ${t.columnIndex}:${t.blockIndex}`
1927
- ), j(
1928
- d,
1929
- t.content,
1930
- `Nested block ${t.columnIndex}:${t.blockIndex}`,
1931
- n
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 = m.column_blocks.map(
1934
- (S, A) => A === t.columnIndex ? S.map(
1935
- (y, I) => I === t.blockIndex ? {
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: t.content
2068
+ content: n.content
1938
2069
  } : y
1939
- ) : S
1940
- ), p = {
1941
- ...m,
2070
+ ) : w
2071
+ ), m = {
2072
+ ...u,
1942
2073
  column_blocks: g
1943
2074
  };
1944
- j(
2075
+ L(
1945
2076
  l,
1946
- p,
1947
- `Updated parent block ${t.parentBlockId}`,
1948
- n
2077
+ m,
2078
+ `Updated parent block ${n.parentBlockId}`,
2079
+ t
1949
2080
  );
1950
- const _ = x({
2081
+ const f = P({
1951
2082
  action: "UPDATE NESTED BLOCK",
1952
- context: n,
2083
+ context: t,
1953
2084
  payload: {
1954
- blockIndex: t.blockIndex,
1955
- columnIndex: t.columnIndex,
1956
- content: t.content,
1957
- nestedBlockType: d,
1958
- parentBlockId: t.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: t.blockIndex,
1963
- columnIndex: t.columnIndex,
1964
- nestedBlockType: d,
1965
- parentBlockId: t.parentBlockId,
2093
+ blockIndex: n.blockIndex,
2094
+ columnIndex: n.columnIndex,
2095
+ nestedBlockType: p,
2096
+ parentBlockId: n.parentBlockId,
1966
2097
  parentBlockType: l
1967
2098
  },
1968
- subject: `${d} nested block ${t.columnIndex}:${t.blockIndex}`
2099
+ subject: `${p} nested block ${n.columnIndex}:${n.blockIndex}`
1969
2100
  });
1970
- if (_)
1971
- return _;
1972
- const { data: k, error: E } = await r.from("blocks").update({
1973
- content: p,
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", t.parentBlockId).select("id, block_type").single();
1976
- if (E || !k)
2106
+ }).eq("id", n.parentBlockId).select("id, block_type").single();
2107
+ if (k || !_)
1977
2108
  throw new Error(
1978
- `Failed to update parent block ${t.parentBlockId}: ${f(E)}`
2109
+ `Failed to update parent block ${n.parentBlockId}: ${h(k)}`
1979
2110
  );
1980
- return F(n, i), {
1981
- blockIndex: t.blockIndex,
1982
- columnIndex: t.columnIndex,
2111
+ return N(t, o), {
2112
+ blockIndex: n.blockIndex,
2113
+ columnIndex: n.columnIndex,
1983
2114
  mutationExecuted: !0,
1984
- nestedBlockType: d,
1985
- parentBlockId: k.id,
1986
- parentBlockType: k.block_type,
2115
+ nestedBlockType: p,
2116
+ parentBlockId: _.id,
2117
+ parentBlockType: _.block_type,
1987
2118
  success: !0
1988
2119
  };
1989
2120
  }
1990
- async function kt(e, n) {
1991
- const t = se.parse(e), r = h(n), i = Ze(n), a = await $e(r, t.languageCode), s = me(t.slug || t.title), l = st(t.blocks, t.contactEmail, t.title, n), m = await Se({
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 (m)
1998
- return m;
1999
- const u = await Ee({
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: t.translationGroupId,
2134
+ suppliedTranslationGroupId: n.translationGroupId,
2004
2135
  supabase: r
2005
2136
  });
2006
- if (u.result)
2007
- return u.result;
2137
+ if (d.result)
2138
+ return d.result;
2008
2139
  const c = {
2009
2140
  blocks: l,
2010
2141
  item: {
2011
- feature_image_id: t.feature_image_id ?? null,
2142
+ feature_image_id: n.feature_image_id ?? null,
2012
2143
  language_id: a.id,
2013
- meta_description: t.meta_description ?? null,
2014
- meta_title: t.meta_title ?? null,
2144
+ meta_description: n.meta_description ?? null,
2145
+ meta_title: n.meta_title ?? null,
2015
2146
  slug: s,
2016
- status: t.status,
2017
- title: t.title,
2018
- translation_group_id: u.translationGroupId
2147
+ status: n.status,
2148
+ title: n.title,
2149
+ translation_group_id: d.translationGroupId
2019
2150
  },
2020
2151
  tool: "create_cms_page"
2021
- }, d = x({
2152
+ }, p = P({
2022
2153
  action: "CREATE PAGE",
2023
- context: n,
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: t.status,
2030
- title: t.title,
2031
- translationGroupId: u.translationGroupId
2160
+ status: n.status,
2161
+ title: n.title,
2162
+ translationGroupId: d.translationGroupId
2032
2163
  },
2033
2164
  subject: s
2034
2165
  });
2035
- if (d)
2036
- return d;
2037
- const g = u.translationGroupId || Ce(), { data: p, error: _ } = await r.from("pages").insert({
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: i,
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 (_ || !p?.id)
2043
- throw new Error(`Failed to create page: ${f(_)}`);
2178
+ if (_ || !f?.id)
2179
+ throw new Error(`Failed to create page: ${h(_)}`);
2044
2180
  try {
2045
- await lt({
2181
+ await Tt({
2046
2182
  blocks: l,
2047
2183
  contentType: "page",
2048
- itemId: Number(p.id),
2184
+ itemId: Number(f.id),
2049
2185
  languageId: a.id,
2050
2186
  supabase: r
2051
2187
  });
2052
2188
  } catch (k) {
2053
- throw await ct({ contentType: "page", itemId: Number(p.id), supabase: r }), k;
2189
+ throw await xt({ contentType: "page", itemId: Number(f.id), supabase: r }), k;
2054
2190
  }
2055
- return F(
2056
- n,
2057
- { contentType: "page", entityId: Number(p.id), languageId: a.id, slug: s, title: t.title },
2191
+ return N(
2192
+ t,
2193
+ { contentType: "page", entityId: Number(f.id), languageId: a.id, slug: s, title: n.title },
2058
2194
  s
2059
- ), n?.revalidatePath?.("/cms/pages"), {
2195
+ ), t?.revalidatePath?.("/cms/pages"), {
2060
2196
  blockCount: l.length,
2061
2197
  contentType: "page",
2062
- editPath: Ae("page", p.id),
2063
- entityId: p.id,
2198
+ editPath: Re("page", f.id),
2199
+ entityId: f.id,
2064
2200
  mutationExecuted: !0,
2065
2201
  slug: s,
2066
2202
  success: !0,
2067
- title: t.title,
2068
- translationGroupId: p.translation_group_id
2203
+ title: n.title,
2204
+ translationGroupId: f.translation_group_id
2069
2205
  };
2070
2206
  }
2071
- async function wt(e, n) {
2072
- const t = le.parse(e), r = h(n), i = Ze(n), a = await $e(r, t.languageCode), s = me(t.slug || t.title), l = st(t.blocks, void 0, void 0, n), m = await Se({
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 (m)
2079
- return m;
2080
- const u = await Ee({
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: t.translationGroupId,
2220
+ suppliedTranslationGroupId: n.translationGroupId,
2085
2221
  supabase: r
2086
2222
  });
2087
- if (u.result)
2088
- return u.result;
2089
- const c = t.published_at && !Number.isNaN(new Date(t.published_at).getTime()) ? new Date(t.published_at).toISOString() : t.published_at ?? null, d = {
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: t.excerpt ?? null,
2093
- feature_image_id: t.feature_image_id ?? null,
2094
- label: t.label ?? null,
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: t.meta_description ?? null,
2097
- meta_title: t.meta_title ?? null,
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: t.status,
2101
- subtitle: t.subtitle ?? null,
2102
- title: t.title,
2103
- translation_group_id: u.translationGroupId
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 = x({
2242
+ }, g = P({
2107
2243
  action: "CREATE POST",
2108
- context: n,
2109
- payload: d,
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: t.status,
2115
- title: t.title,
2116
- translationGroupId: u.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 p = u.translationGroupId || Ce(), { data: _, error: k } = await r.from("posts").insert({
2123
- ...d.item,
2124
- author_id: i,
2125
- translation_group_id: p
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: ${f(k)}`);
2269
+ throw new Error(`Failed to create post: ${h(k)}`);
2129
2270
  try {
2130
- await lt({
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 (E) {
2138
- throw await ct({ contentType: "post", itemId: Number(_.id), supabase: r }), E;
2278
+ } catch (w) {
2279
+ throw await xt({ contentType: "post", itemId: Number(_.id), supabase: r }), w;
2139
2280
  }
2140
- return F(
2141
- n,
2142
- { contentType: "post", entityId: Number(_.id), languageId: a.id, slug: s, title: t.title },
2281
+ return N(
2282
+ t,
2283
+ { contentType: "post", entityId: Number(_.id), languageId: a.id, slug: s, title: n.title },
2143
2284
  s
2144
- ), n?.revalidatePath?.("/cms/posts"), n?.revalidatePath?.("/articles"), {
2285
+ ), t?.revalidatePath?.("/cms/posts"), t?.revalidatePath?.("/articles"), {
2145
2286
  blockCount: l.length,
2146
2287
  contentType: "post",
2147
- editPath: Ae("post", _.id),
2288
+ editPath: Re("post", _.id),
2148
2289
  entityId: _.id,
2149
2290
  mutationExecuted: !0,
2150
2291
  slug: s,
2151
2292
  success: !0,
2152
- title: t.title,
2293
+ title: n.title,
2153
2294
  translationGroupId: _.translation_group_id
2154
2295
  };
2155
2296
  }
2156
- function On(e, n) {
2157
- return (n || me(e) || "product").replace(/-/g, "").slice(0, 24).toUpperCase();
2297
+ function fr(e, t) {
2298
+ return (t || Y(e) || "product").replace(/-/g, "").slice(0, 24).toUpperCase();
2158
2299
  }
2159
- function It(e) {
2300
+ function Ot(e) {
2160
2301
  if (e === void 0)
2161
2302
  return;
2162
- const n = Yt().safeParse(e);
2163
- if (!n.success)
2303
+ const t = fn().safeParse(e);
2304
+ if (!t.success)
2164
2305
  throw new Error(
2165
- `Product description_json failed editor document validation: ${n.error.issues.map((t) => t.message).join("; ")}`
2306
+ `Product description_json failed editor document validation: ${t.error.issues.map((n) => n.message).join("; ")}`
2166
2307
  );
2167
- return n.data;
2308
+ return t.data;
2168
2309
  }
2169
- async function Ct(e, n) {
2170
- const t = ce.parse(e), r = h(n), i = await $e(r, t.languageCode), a = me(t.slug || t.title), s = await Se({
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: i.id,
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 Ee({
2319
+ const l = await Le({
2179
2320
  contentType: "product",
2180
- languageCode: i.code,
2181
- languageId: i.id,
2182
- suppliedTranslationGroupId: t.translationGroupId,
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: m, productSchema: u } = await Ie(), d = t.product_type === "digital" && t.payment_provider === "freemius" ? t.trial_period_days : 0, g = u.parse({
2188
- description_json: It(t.description_json),
2189
- freemius_plan_id: t.freemius_plan_id || "",
2190
- freemius_product_id: t.freemius_product_id || "",
2191
- is_taxable: t.is_taxable,
2192
- language_id: i.id,
2193
- meta_description: t.meta_description ?? "",
2194
- meta_title: t.meta_title ?? "",
2195
- payment_provider: t.payment_provider,
2196
- price: t.price,
2197
- prices: t.prices || {},
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: t.product_type,
2200
- sale_price: t.sale_price ?? null,
2201
- sale_prices: t.sale_prices || {},
2202
- short_description: t.short_description ?? "",
2203
- sku: t.sku || On(t.title, a),
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: t.status,
2206
- stock: t.stock,
2207
- title: t.title,
2208
- trial_period_days: d,
2209
- trial_requires_payment_method: d > 0 ? t.trial_requires_payment_method : !1,
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: t.upc ?? "",
2352
+ upc: n.upc ?? "",
2212
2353
  variation_attributes: [],
2213
2354
  variants: []
2214
- }), p = x({
2355
+ }), m = P({
2215
2356
  action: "CREATE PRODUCT",
2216
- context: n,
2357
+ context: t,
2217
2358
  payload: { item: g, tool: "create_cms_product" },
2218
2359
  preview: {
2219
- languageCode: i.code,
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 (p)
2231
- return p;
2232
- const _ = await m(r, g);
2233
- if (!_?.id)
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 F(
2236
- n,
2237
- { contentType: "product", entityId: _.id, languageId: i.id, slug: a, title: t.title },
2376
+ return N(
2377
+ t,
2378
+ { contentType: "product", entityId: f.id, languageId: o.id, slug: a, title: n.title },
2238
2379
  a
2239
- ), n?.revalidatePath?.("/cms/products"), {
2380
+ ), t?.revalidatePath?.("/cms/products"), {
2240
2381
  contentType: "product",
2241
- editPath: Ae("product", _.id),
2242
- entityId: _.id,
2382
+ editPath: Re("product", f.id),
2383
+ entityId: f.id,
2243
2384
  mutationExecuted: !0,
2244
2385
  slug: a,
2245
2386
  success: !0,
2246
- title: t.title,
2247
- translationGroupId: _.translation_group_id
2387
+ title: n.title,
2388
+ translationGroupId: f.translation_group_id
2248
2389
  };
2249
2390
  }
2250
- function Pe(e) {
2391
+ function Ge(e) {
2251
2392
  return e.trim().replace(/[\s-]+/g, "_").toLowerCase();
2252
2393
  }
2253
- function Un(e, n) {
2254
- const t = typeof n == "string" ? Pe(n) : n;
2255
- return e === "product" ? t === "public" || t === "publish" || t === "published" ? "active" : t : t === "public" || t === "active" || t === "publish" ? "published" : t;
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 Dn(e) {
2258
- const n = Pe(e.field);
2259
- return !!(e.startsAt || e.endsAt || n.includes("start") || n.includes("end") || n.includes("schedule") || n.includes("special_date"));
2260
- }
2261
- async function Mn(e, n, t) {
2262
- const r = await mn(n), { productSchema: i } = await Ie();
2263
- return i.parse({
2264
- description_json: t.description_json !== void 0 ? It(t.description_json) : e.description_json || void 0,
2265
- freemius_plan_id: e.freemius_plan_id || "",
2266
- freemius_product_id: e.freemius_product_id || "",
2267
- is_taxable: t.is_taxable ?? e.is_taxable ?? !0,
2268
- language_id: t.language_id ?? e.language_id,
2269
- meta_description: t.meta_description ?? e.meta_description ?? "",
2270
- meta_title: t.meta_title ?? e.meta_title ?? "",
2271
- payment_provider: t.payment_provider ?? e.payment_provider ?? "stripe",
2272
- price: t.price !== void 0 ? t.price : an(e.price, r),
2273
- prices: t.prices ?? je(e.prices, r),
2274
- product_media: void 0,
2275
- product_type: t.product_type ?? e.product_type ?? "physical",
2276
- sale_price: t.sale_price !== void 0 ? t.sale_price : e.sale_price === null || e.sale_price === void 0 ? null : xe(Number(e.sale_price), r),
2277
- sale_prices: t.sale_prices ?? je(e.sale_prices, r),
2278
- short_description: t.short_description ?? e.short_description ?? "",
2279
- sku: t.sku ?? e.sku,
2280
- slug: t.slug ?? e.slug,
2281
- status: t.status ?? e.status ?? "draft",
2282
- stock: t.stock ?? e.stock ?? 0,
2283
- title: t.title ?? e.title,
2284
- trial_period_days: t.trial_period_days ?? e.trial_period_days ?? 0,
2285
- trial_requires_payment_method: t.trial_requires_payment_method ?? e.trial_requires_payment_method ?? !1,
2286
- upc: t.upc ?? e.upc ?? "",
2287
- variation_attributes: [],
2288
- variants: []
2289
- });
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 Ln(e, n) {
2292
- const t = Pe(e.field), r = t === "status" ? Un(n.contentType, e.value) : e.value, a = {
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
- }[t] || t;
2311
- if (n.contentType !== "product") {
2312
- if (!(n.contentType === "page" ? mt : gt).has(a))
2313
- throw new Error(`Field "${e.field}" cannot be updated for ${n.contentType}.`);
2314
- return a === "status" && be(n.contentType, r), {
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]: ft(a, r)
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" && be("product", r), (a === "price" || a === "sale_price") && r !== null && (typeof r != "number" || r < 0))
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 Tt(e, n) {
2362
- const t = ue.parse(e);
2363
- if (Dn(t))
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 ve(t, n), i = Ln(t, r), a = i.field;
2371
- let s = i.payload;
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 d = await U(h(n), s.language_id);
2497
+ const p = await G(I(t), s.language_id);
2374
2498
  s = {
2375
2499
  ...s,
2376
- language_id: d.id
2500
+ language_id: p.id
2377
2501
  };
2378
2502
  }
2379
- const l = x({
2503
+ const l = P({
2380
2504
  action: "UPDATE FIELD",
2381
- context: n,
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 { updateProduct: d } = await Ie(), g = await Mn(r.item, h(n), s), p = await d(h(n), String(r.item.id), g);
2403
- return F(
2404
- n,
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(r.item.id),
2408
- languageId: p?.language_id ?? r.item.language_id,
2409
- slug: p?.slug ?? r.item.slug,
2410
- title: p?.title ?? r.item.title
2536
+ entityId: String(m.id),
2537
+ languageId: m.language_id,
2538
+ slug: m.slug,
2539
+ title: m.title
2411
2540
  },
2412
- p?.slug ?? r.item.slug
2541
+ m.slug
2413
2542
  ), {
2414
2543
  contentType: "product",
2415
- entityId: r.item.id,
2544
+ entityId: m.id,
2416
2545
  field: a,
2417
2546
  mutationExecuted: !0,
2418
- slug: p?.slug ?? r.item.slug,
2547
+ slug: m.slug,
2419
2548
  success: !0,
2420
2549
  updatedFields: [a]
2421
2550
  };
2422
2551
  }
2423
- const m = r.contentType === "page" ? "pages" : "posts", { data: u, error: c } = await h(n).from(m).update({
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 || !u)
2428
- throw new Error(`Failed to update ${r.contentType}: ${f(c)}`);
2429
- return F(
2430
- n,
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(u.id),
2434
- languageId: u.language_id,
2435
- slug: u.slug,
2436
- title: u.title
2570
+ entityId: Number(d.id),
2571
+ languageId: d.language_id,
2572
+ slug: d.slug,
2573
+ title: d.title
2437
2574
  },
2438
- u.slug
2575
+ d.slug
2439
2576
  ), {
2440
2577
  contentType: r.contentType,
2441
- entityId: u.id,
2578
+ entityId: d.id,
2442
2579
  field: a,
2443
2580
  mutationExecuted: !0,
2444
- slug: u.slug,
2581
+ slug: d.slug,
2445
2582
  success: !0,
2446
2583
  updatedFields: [a]
2447
2584
  };
2448
2585
  }
2449
- async function xt(e, n) {
2450
- const t = Je.parse(e), r = await ve(t, n);
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: Ue("product"),
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 i = r.contentType === "page" ? "pages" : "posts", { data: a, error: s } = await h(n).from(i).select("id, slug, title, translation_group_id").eq("translation_group_id", r.item.translation_group_id);
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: ${f(s)}`);
2464
- const l = Array.isArray(a) ? a : [], m = l.map(
2465
- (p) => r.contentType === "page" ? p.slug === "home" ? "/" : `/${p.slug}` : `/article/${p.slug}`
2466
- ).filter(Boolean), u = new Set(m), { data: c, error: d } = await h(n).from("navigation_items").select("id, url");
2467
- if (d)
2468
- throw new Error(`Failed to inspect related navigation links: ${f(d)}`);
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
- (p) => u.has(p.url)
2607
+ (m) => d.has(m.url)
2471
2608
  ).length;
2472
2609
  return {
2473
2610
  affectedCount: l.length,
2474
- collectionPath: Ue(r.contentType),
2611
+ collectionPath: Xe(r.contentType),
2475
2612
  contentType: r.contentType,
2476
2613
  item: r.item,
2477
2614
  navigationLinkCount: g,
2478
- publicPaths: m,
2479
- targetIds: l.map((p) => p.id)
2615
+ publicPaths: u,
2616
+ targetIds: l.map((m) => m.id)
2480
2617
  };
2481
2618
  }
2482
- function $t(e) {
2483
- const n = e.item.title || e.item.slug || "selected item", t = e.item.slug ? ` (${e.item.slug})` : "";
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 "${n}"${t}.`;
2622
+ return `Delete product "${t}"${n}.`;
2486
2623
  const r = [
2487
- `${N(e.affectedCount, "language version")}`,
2488
- e.navigationLinkCount > 0 ? `${N(e.navigationLinkCount, "navigation link")}` : null
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} "${n}"${t}, including ${r.join(" and ")}.`;
2627
+ return `Delete ${e.contentType} "${t}"${n}, including ${r.join(" and ")}.`;
2491
2628
  }
2492
- async function Rn(e, n) {
2493
- const t = await xt(e, n);
2629
+ async function kr(e, t) {
2630
+ const n = await Bt(e, t);
2494
2631
  return {
2495
- ...Xe({
2496
- action: `DELETE ${t.contentType}`,
2632
+ ...gt({
2633
+ action: `DELETE ${n.contentType}`,
2497
2634
  payload: {
2498
- affectedCount: t.affectedCount,
2499
- contentType: t.contentType,
2500
- targetIds: t.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: t.affectedCount,
2505
- collectionPath: t.collectionPath,
2506
- contentType: t.contentType,
2507
- navigationLinkCount: t.navigationLinkCount,
2508
- publicPaths: t.publicPaths,
2509
- slug: t.item.slug,
2510
- summary: $t(t),
2511
- title: t.item.title
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: `${t.item.id} ${t.item.slug || ""}`
2650
+ subject: `${n.item.id} ${n.item.slug || ""}`
2514
2651
  }),
2515
2652
  preparedDelete: !0
2516
2653
  };
2517
2654
  }
2518
- async function vt(e, n) {
2519
- const t = de.parse(e), r = await xt(t, n), i = x({
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: n,
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: $t(r),
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 (i)
2541
- return i;
2542
- const a = h(n);
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: ${f(l)}`);
2683
+ throw new Error(`Failed to delete product: ${h(l)}`);
2547
2684
  } else {
2548
- for (const u of r.publicPaths)
2549
- await a.from("navigation_items").delete().eq("url", u);
2550
- const l = r.contentType === "page" ? "pages" : "posts", { error: m } = await a.from(l).delete().eq("translation_group_id", r.item.translation_group_id);
2551
- if (m)
2552
- throw new Error(`Failed to delete ${r.contentType}: ${f(m)}`);
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 = n?.revalidatePath ?? ke();
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 Le(e, n) {
2701
+ async function et(e, t) {
2565
2702
  switch (e.tool) {
2566
2703
  case "create_cms_page":
2567
- return kt(e.input, n);
2704
+ return Me(e.input, t);
2568
2705
  case "create_cms_post":
2569
- return wt(e.input, n);
2706
+ return De(e.input, t);
2570
2707
  case "create_cms_product":
2571
- return Ct(e.input, n);
2708
+ return jt(e.input, t);
2572
2709
  case "delete_cms_item":
2573
- return vt(e.input, n);
2710
+ return Rt(e.input, t);
2574
2711
  case "update_cms_item_field":
2575
- return Tt(e.input, n);
2712
+ return qt(e.input, t);
2576
2713
  case "update_content_block":
2577
- return bt(e.input, n);
2714
+ return Nt(e.input, t);
2578
2715
  case "insert_content_block":
2579
- return yt(e.input, n);
2716
+ return Ut(e.input, t);
2580
2717
  case "update_current_cms_fields":
2581
- return _t(e.input, n);
2718
+ return Pt(e.input, t);
2582
2719
  case "update_footer":
2583
- return dt(e.input, n);
2720
+ return vt(e.input, t);
2584
2721
  case "update_navigation_bar":
2585
- return ut(e.input, n);
2722
+ return Ct(e.input, t);
2586
2723
  case "update_section_column_block":
2587
- return ht(e.input, n);
2724
+ return Ft(e.input, t);
2588
2725
  }
2589
2726
  }
2590
- function Gn(e, n) {
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 t = n[e.tool];
2594
- return t ? {
2730
+ const n = t[e.tool];
2731
+ return n ? {
2595
2732
  ...e,
2596
2733
  input: {
2597
2734
  ...e.input,
2598
- translationGroupId: t
2735
+ translationGroupId: n
2599
2736
  }
2600
2737
  } : e;
2601
2738
  }
2602
- async function zn(e, n) {
2603
- const t = He.parse(e);
2604
- if (!n?.skipConfirmation) {
2605
- const u = [];
2606
- for (const g of t.actions) {
2607
- const p = await Le(g, {
2608
- ...n,
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 (!p || typeof p != "object")
2748
+ if (!m || typeof m != "object")
2612
2749
  return {
2613
- message: `Could not prepare action ${u.length + 1}.`,
2750
+ message: `Could not prepare action ${d.length + 1}.`,
2614
2751
  mutationExecuted: !1,
2615
2752
  success: !1
2616
2753
  };
2617
- if (p.success === !1 || p.unsupported === !0)
2618
- return p;
2619
- p.requiresConfirmation === !0 && p.preview ? u.push(
2620
- rn(g.tool, p.preview)
2621
- ) : u.push(`Run ${g.tool.replace(/_/g, " ")}.`);
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 = t.summary || `Complete ${N(t.actions.length, "CMS action")}.`, d = x({
2760
+ const c = n.summary || `Complete ${F(n.actions.length, "CMS action")}.`, p = P({
2624
2761
  action: "EXECUTE CMS ACTION PLAN",
2625
- context: n,
2626
- payload: { actions: t.actions, tool: "execute_cms_action_plan" },
2762
+ context: t,
2763
+ payload: { actions: n.actions, tool: "execute_cms_action_plan" },
2627
2764
  preview: {
2628
- actionCount: t.actions.length,
2629
- actionSummaries: u,
2765
+ actionCount: n.actions.length,
2766
+ actionSummaries: d,
2630
2767
  summary: c
2631
2768
  },
2632
- subject: `${t.actions.length} actions`
2769
+ subject: `${n.actions.length} actions`
2633
2770
  });
2634
- if (d)
2635
- return d;
2771
+ if (p)
2772
+ return p;
2636
2773
  }
2637
2774
  const r = {
2638
- ...n,
2775
+ ...t,
2639
2776
  skipConfirmation: !0
2640
- }, i = [];
2777
+ }, o = [];
2641
2778
  let a = !1, s = null, l = null;
2642
- const m = {};
2643
- for (const [u, c] of t.actions.entries()) {
2644
- const d = Gn(c, m), g = await Le(d, r);
2645
- if (i.push({ output: g, tool: d.tool }), g && typeof g == "object") {
2646
- const p = g;
2647
- if (p.mutationExecuted === !0 && (a = !0), !s && typeof p.editPath == "string" && (s = p.editPath), typeof p.redirectPath == "string" && (l = p.redirectPath), (d.tool === "create_cms_page" || d.tool === "create_cms_post" || d.tool === "create_cms_product") && typeof p.translationGroupId == "string" && (m[d.tool] = p.translationGroupId), p.success === !1 || p.unsupported === !0)
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: t.actions.length,
2650
- failedActionIndex: u,
2651
- failedTool: d.tool,
2652
- message: typeof p.message == "string" ? p.message : `Action ${u + 1} failed.`,
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: i,
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: t.actions.length,
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: i,
2803
+ results: o,
2667
2804
  success: !0,
2668
- summary: t.summary ?? null
2805
+ summary: n.summary ?? null
2669
2806
  };
2670
2807
  }
2671
- function Qn(e) {
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(/&nbsp;/gi, " ").replace(/&amp;/gi, "&").replace(/&lt;/gi, "<").replace(/&gt;/gi, ">").replace(/&quot;/gi, '"').replace(/&#39;/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
- ...St(e),
2674
- ...Et(e),
2675
- fetch_ecommerce_stats: w({
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: (n) => Pn(n, e),
2678
- inputSchema: ze,
3406
+ execute: (t) => cr(t, e),
3407
+ inputSchema: at,
2679
3408
  strict: !0
2680
3409
  }),
2681
- read_current_cms_item: w({
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: (n) => Bn(n, e),
2684
- inputSchema: Ve,
3412
+ execute: (t) => ur(t, e),
3413
+ inputSchema: lt,
2685
3414
  strict: !0
2686
3415
  }),
2687
- search_documentation: w({
3416
+ search_documentation: T({
2688
3417
  description: "Search the NextBlock documentation database and return concise source snippets for factual CMS guidance.",
2689
- execute: (n) => $n(n, e),
2690
- inputSchema: ye,
3418
+ execute: (t) => or(t, e),
3419
+ inputSchema: Pe,
2691
3420
  strict: !0
2692
3421
  }),
2693
- create_cms_page: w({
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: (n) => kt(n, e),
2696
- inputSchema: se,
3454
+ execute: (t) => Me(t, e),
3455
+ inputSchema: ge,
2697
3456
  strict: !0
2698
3457
  }),
2699
- create_cms_post: w({
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: (n) => wt(n, e),
2702
- inputSchema: le,
3460
+ execute: (t) => De(t, e),
3461
+ inputSchema: fe,
2703
3462
  strict: !0
2704
3463
  }),
2705
- create_cms_product: w({
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: (n) => Ct(n, e),
2708
- inputSchema: ce,
3466
+ execute: (t) => jt(t, e),
3467
+ inputSchema: he,
2709
3468
  strict: !0
2710
3469
  }),
2711
- delete_cms_item: w({
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: (n) => vt(n, e),
2714
- inputSchema: de,
3472
+ execute: (t) => Rt(t, e),
3473
+ inputSchema: ye,
2715
3474
  strict: !0
2716
3475
  }),
2717
- prepare_delete_cms_item: w({
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: (n) => Rn(n, e),
2720
- inputSchema: Je,
3478
+ execute: (t) => kr(t, e),
3479
+ inputSchema: ct,
2721
3480
  strict: !0
2722
3481
  }),
2723
- update_footer: w({
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: (n) => dt(n, e),
2726
- inputSchema: te,
3484
+ execute: (t) => vt(t, e),
3485
+ inputSchema: le,
2727
3486
  strict: !0
2728
3487
  }),
2729
- update_content_block: w({
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: (n) => bt(n, e),
2732
- inputSchema: oe,
3490
+ execute: (t) => Nt(t, e),
3491
+ inputSchema: ue,
2733
3492
  strict: !0
2734
3493
  }),
2735
- insert_content_block: w({
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: (n) => yt(n, e),
2738
- inputSchema: ae,
3496
+ execute: (t) => Ut(t, e),
3497
+ inputSchema: me,
2739
3498
  strict: !0
2740
3499
  }),
2741
- update_current_cms_fields: w({
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: (n) => _t(n, e),
2744
- inputSchema: ne,
3502
+ execute: (t) => Pt(t, e),
3503
+ inputSchema: ce,
2745
3504
  strict: !0
2746
3505
  }),
2747
- update_cms_item_field: w({
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: (n) => Tt(n, e),
2750
- inputSchema: ue,
3508
+ execute: (t) => qt(t, e),
3509
+ inputSchema: _e,
2751
3510
  strict: !0
2752
3511
  }),
2753
- update_navigation_bar: w({
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: (n) => ut(n, e),
2756
- inputSchema: ee,
3514
+ execute: (t) => Ct(t, e),
3515
+ inputSchema: se,
2757
3516
  strict: !0
2758
3517
  }),
2759
- update_section_column_block: w({
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: (n) => ht(n, e),
2762
- inputSchema: re,
3520
+ execute: (t) => Ft(t, e),
3521
+ inputSchema: de,
2763
3522
  strict: !0
2764
3523
  }),
2765
- execute_cms_action_plan: w({
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: (n) => zn(n, e),
2768
- inputSchema: He,
3526
+ execute: (t) => Ir(t, e),
3527
+ inputSchema: dt,
2769
3528
  strict: !0
2770
3529
  })
2771
3530
  };
2772
3531
  }
2773
3532
  export {
2774
- O as availableCortexAiBlockTypes,
2775
- Yn as buildVisibleContactIntroActionPlan,
2776
- Ke as cortexAiPageContextSchema,
2777
- se as createCmsPageInputSchema,
2778
- le as createCmsPostInputSchema,
2779
- ce as createCmsProductInputSchema,
2780
- Qn as createCortexGlobalAgentTools,
2781
- de as deleteCmsItemInputSchema,
2782
- zn as executeCmsActionPlan,
2783
- He as executeCmsActionPlanInputSchema,
2784
- kt as executeCreateCmsPage,
2785
- wt as executeCreateCmsPost,
2786
- Ct as executeCreateCmsProduct,
2787
- vt as executeDeleteCmsItem,
2788
- Pn as executeFetchEcommerceStats,
2789
- yt as executeInsertContentBlock,
2790
- Rn as executePrepareDeleteCmsItem,
2791
- Bn as executeReadCurrentCmsItem,
2792
- xn as executeSearchDocumentation,
2793
- $n as executeSearchDocumentationWithTimeout,
2794
- Tt as executeUpdateCmsItemField,
2795
- bt as executeUpdateContentBlock,
2796
- _t as executeUpdateCurrentCmsFields,
2797
- dt as executeUpdateFooter,
2798
- ut as executeUpdateNavigationBar,
2799
- ht as executeUpdateSectionColumnBlock,
2800
- ze as fetchEcommerceStatsInputSchema,
2801
- ae as insertContentBlockInputSchema,
2802
- Ge as navigationItemInputSchema,
2803
- Je as prepareDeleteCmsItemInputSchema,
2804
- Ve as readCurrentCmsItemInputSchema,
2805
- ye as searchDocumentationInputSchema,
2806
- ue as updateCmsItemFieldInputSchema,
2807
- oe as updateContentBlockInputSchema,
2808
- ne as updateCurrentCmsFieldsInputSchema,
2809
- te as updateFooterInputSchema,
2810
- ee as updateNavigationBarInputSchema,
2811
- re as updateSectionColumnBlockInputSchema
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
  };