@nextblock-cms/cortex 0.20.1 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.cjs.js +1 -1
- package/client.es.js +3 -7
- package/index.cjs.js +1 -1
- package/index.es.js +24 -277
- package/lib/ai-block-generation.cjs.js +3 -4
- package/lib/ai-block-generation.es.js +143 -182
- package/lib/ai-client.cjs.js +1 -1
- package/lib/ai-client.d.ts +1 -1
- package/lib/ai-client.es.js +101 -135
- package/lib/ai-config.cjs.js +1 -1
- package/lib/ai-config.es.js +89 -108
- package/lib/ai-cortex-widget-builder.cjs.js +1 -1
- package/lib/ai-cortex-widget-builder.es.js +56 -70
- package/lib/ai-global-agent-content-ops-tools.cjs.js +1 -1
- package/lib/ai-global-agent-content-ops-tools.d.ts +1943 -68
- package/lib/ai-global-agent-content-ops-tools.es.js +185 -199
- package/lib/ai-global-agent-custom-block-tools.cjs.js +1 -1
- package/lib/ai-global-agent-custom-block-tools.d.ts +2160 -95
- package/lib/ai-global-agent-custom-block-tools.es.js +226 -223
- package/lib/ai-global-agent-db-tools.cjs.js +1 -1
- package/lib/ai-global-agent-db-tools.d.ts +2708 -98
- package/lib/ai-global-agent-db-tools.es.js +1013 -986
- package/lib/ai-global-agent-ecommerce.cjs.js +1 -1
- package/lib/ai-global-agent-ecommerce.es.js +3 -7
- package/lib/ai-global-agent-site-tools.cjs.js +2 -3
- package/lib/ai-global-agent-site-tools.d.ts +10695 -500
- package/lib/ai-global-agent-site-tools.es.js +750 -757
- package/lib/ai-global-agent-theming-tools.cjs.js +1 -3
- package/lib/ai-global-agent-theming-tools.d.ts +2905 -105
- package/lib/ai-global-agent-theming-tools.es.js +326 -396
- package/lib/ai-global-agent-tools.cjs.js +2 -2
- package/lib/ai-global-agent-tools.d.ts +4 -2230
- package/lib/ai-global-agent-tools.es.js +3899 -4328
- package/lib/ai-key-crypto.cjs.js +1 -1
- package/lib/ai-key-crypto.es.js +63 -82
- package/lib/ai-key-verification.cjs.js +1 -1
- package/lib/ai-key-verification.es.js +74 -63
- package/lib/ai-model-catalog.cjs.js +1 -1
- package/lib/ai-model-catalog.es.js +18 -22
- package/lib/ai-model-registry.cjs.js +2 -2
- package/lib/ai-model-registry.es.js +246 -309
- package/lib/ai-seo-metadata.cjs.js +2 -3
- package/lib/ai-seo-metadata.es.js +143 -185
- package/lib/ai-vision.cjs.js +2 -2
- package/lib/ai-vision.d.ts +6 -6
- package/lib/ai-vision.es.js +161 -215
- package/lib/block-content-schemas.cjs.js +1 -1
- package/lib/block-content-schemas.es.js +324 -254
- package/lib/cortex-widget-registry.cjs.js +1 -1
- package/lib/cortex-widget-registry.es.js +35 -43
- package/lib/cortex-widget-schema.cjs.js +2 -3
- package/lib/cortex-widget-schema.es.js +280 -309
- package/lib/editor-document-from-html.cjs.js +1 -1
- package/lib/editor-document-from-html.es.js +334 -278
- package/lib/fetch-host-guard.cjs.js +1 -0
- package/lib/fetch-host-guard.d.ts +2 -0
- package/lib/fetch-host-guard.es.js +30 -0
- package/lib/mcp-server.cjs.js +1 -1
- package/lib/mcp-server.es.js +155 -173
- package/lib/mcp-tokens.cjs.js +1 -1
- package/lib/mcp-tokens.es.js +95 -107
- package/lib/mcp-tool-registry.cjs.js +5 -6
- package/lib/mcp-tool-registry.es.js +533 -411
- package/lib/site-brief.cjs.js +2 -2
- package/lib/site-brief.es.js +102 -108
- package/lib/vision-image-download.cjs.js +1 -0
- package/lib/vision-image-download.d.ts +43 -0
- package/lib/vision-image-download.es.js +120 -0
- package/lib/zod-config.cjs.js +1 -1
- package/lib/zod-config.es.js +5 -6
- package/package.json +8 -8
|
@@ -1,262 +1,332 @@
|
|
|
1
|
-
import "./zod-config.es.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
],
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
1
|
+
import { z as e } from "./zod-config.es.js";
|
|
2
|
+
//#region libs/cortex/src/lib/block-content-schemas.ts
|
|
3
|
+
var t = [
|
|
4
|
+
"text",
|
|
5
|
+
"heading",
|
|
6
|
+
"image",
|
|
7
|
+
"button",
|
|
8
|
+
"posts_grid",
|
|
9
|
+
"video_embed",
|
|
10
|
+
"section",
|
|
11
|
+
"form",
|
|
12
|
+
"testimonial",
|
|
13
|
+
"product_grid",
|
|
14
|
+
"featured_product",
|
|
15
|
+
"cart",
|
|
16
|
+
"checkout",
|
|
17
|
+
"product_details"
|
|
18
|
+
], n = e.enum(t), r = e.object({
|
|
19
|
+
direction: e.string().optional(),
|
|
20
|
+
stops: e.array(e.object({
|
|
21
|
+
color: e.string(),
|
|
22
|
+
position: e.number()
|
|
23
|
+
})),
|
|
24
|
+
type: e.enum(["linear", "radial"])
|
|
25
|
+
}), i = e.object({
|
|
26
|
+
gradient: r.optional(),
|
|
27
|
+
image: e.object({
|
|
28
|
+
alt_text: e.string().optional(),
|
|
29
|
+
blur_data_url: e.string().optional(),
|
|
30
|
+
external_url: e.string().optional(),
|
|
31
|
+
height: e.number().optional(),
|
|
32
|
+
media_id: e.string().optional(),
|
|
33
|
+
object_key: e.string().optional(),
|
|
34
|
+
overlay: e.object({
|
|
35
|
+
gradient: r,
|
|
36
|
+
type: e.literal("gradient")
|
|
37
|
+
}).optional(),
|
|
38
|
+
position: e.enum([
|
|
39
|
+
"center",
|
|
40
|
+
"top",
|
|
41
|
+
"bottom",
|
|
42
|
+
"left",
|
|
43
|
+
"right"
|
|
44
|
+
]),
|
|
45
|
+
quality: e.number().nullable().optional(),
|
|
46
|
+
size: e.enum(["cover", "contain"]),
|
|
47
|
+
width: e.number().optional()
|
|
48
|
+
}).optional(),
|
|
49
|
+
min_height: e.string().optional(),
|
|
50
|
+
solid_color: e.string().optional(),
|
|
51
|
+
theme: e.enum([
|
|
52
|
+
"primary",
|
|
53
|
+
"secondary",
|
|
54
|
+
"muted",
|
|
55
|
+
"accent",
|
|
56
|
+
"destructive"
|
|
57
|
+
]).optional(),
|
|
58
|
+
type: e.enum([
|
|
59
|
+
"none",
|
|
60
|
+
"theme",
|
|
61
|
+
"solid",
|
|
62
|
+
"gradient",
|
|
63
|
+
"image"
|
|
64
|
+
])
|
|
65
|
+
}), a = e.string().regex(/^[a-z][a-z0-9-]*$/), o = e.object({
|
|
66
|
+
block_type: e.union([n, a]),
|
|
67
|
+
content: e.record(e.string(), e.any()),
|
|
68
|
+
temp_id: e.string().optional()
|
|
69
|
+
}), s = e.object({
|
|
70
|
+
background: i,
|
|
71
|
+
column_blocks: e.array(e.array(o))
|
|
72
|
+
}), c = e.object({
|
|
73
|
+
autoplay: e.boolean().optional(),
|
|
74
|
+
background: i,
|
|
75
|
+
column_blocks: e.array(e.array(o)),
|
|
76
|
+
column_gap: e.enum([
|
|
77
|
+
"none",
|
|
78
|
+
"sm",
|
|
79
|
+
"md",
|
|
80
|
+
"lg",
|
|
81
|
+
"xl"
|
|
82
|
+
]),
|
|
83
|
+
container_type: e.enum([
|
|
84
|
+
"full-width",
|
|
85
|
+
"container",
|
|
86
|
+
"container-sm",
|
|
87
|
+
"container-lg",
|
|
88
|
+
"container-xl"
|
|
89
|
+
]),
|
|
90
|
+
is_hero: e.boolean().optional(),
|
|
91
|
+
padding: e.object({
|
|
92
|
+
bottom: e.enum([
|
|
93
|
+
"none",
|
|
94
|
+
"sm",
|
|
95
|
+
"md",
|
|
96
|
+
"lg",
|
|
97
|
+
"xl"
|
|
98
|
+
]),
|
|
99
|
+
top: e.enum([
|
|
100
|
+
"none",
|
|
101
|
+
"sm",
|
|
102
|
+
"md",
|
|
103
|
+
"lg",
|
|
104
|
+
"xl"
|
|
105
|
+
])
|
|
106
|
+
}),
|
|
107
|
+
responsive_columns: e.object({
|
|
108
|
+
desktop: e.union([
|
|
109
|
+
e.literal(1),
|
|
110
|
+
e.literal(2),
|
|
111
|
+
e.literal(3),
|
|
112
|
+
e.literal(4)
|
|
113
|
+
]),
|
|
114
|
+
mobile: e.union([e.literal(1), e.literal(2)]),
|
|
115
|
+
tablet: e.union([
|
|
116
|
+
e.literal(1),
|
|
117
|
+
e.literal(2),
|
|
118
|
+
e.literal(3)
|
|
119
|
+
])
|
|
120
|
+
}),
|
|
121
|
+
slider: e.boolean().optional(),
|
|
122
|
+
slides: e.array(s).optional(),
|
|
123
|
+
timeframe: e.number().optional(),
|
|
124
|
+
vertical_alignment: e.enum([
|
|
125
|
+
"start",
|
|
126
|
+
"center",
|
|
127
|
+
"end",
|
|
128
|
+
"stretch"
|
|
129
|
+
]).optional()
|
|
130
|
+
}), l = {
|
|
131
|
+
button: e.object({
|
|
132
|
+
position: e.enum([
|
|
133
|
+
"left",
|
|
134
|
+
"center",
|
|
135
|
+
"right"
|
|
136
|
+
]).optional(),
|
|
137
|
+
size: e.enum([
|
|
138
|
+
"default",
|
|
139
|
+
"sm",
|
|
140
|
+
"lg",
|
|
141
|
+
"full"
|
|
142
|
+
]).optional(),
|
|
143
|
+
text: e.string(),
|
|
144
|
+
url: e.string(),
|
|
145
|
+
variant: e.enum([
|
|
146
|
+
"default",
|
|
147
|
+
"outline",
|
|
148
|
+
"secondary",
|
|
149
|
+
"ghost",
|
|
150
|
+
"link"
|
|
151
|
+
]).optional()
|
|
152
|
+
}),
|
|
153
|
+
cart: e.object({}),
|
|
154
|
+
checkout: e.object({}),
|
|
155
|
+
featured_product: e.object({
|
|
156
|
+
imagePosition: e.enum(["left", "right"]).default("left"),
|
|
157
|
+
productId: e.string().min(1),
|
|
158
|
+
showBackground: e.boolean().default(!1)
|
|
159
|
+
}),
|
|
160
|
+
form: e.object({
|
|
161
|
+
fields: e.array(e.object({
|
|
162
|
+
field_type: e.enum([
|
|
163
|
+
"text",
|
|
164
|
+
"email",
|
|
165
|
+
"tel",
|
|
166
|
+
"url",
|
|
167
|
+
"number",
|
|
168
|
+
"textarea",
|
|
169
|
+
"select",
|
|
170
|
+
"radio",
|
|
171
|
+
"checkbox"
|
|
172
|
+
]),
|
|
173
|
+
is_required: e.boolean(),
|
|
174
|
+
label: e.string(),
|
|
175
|
+
options: e.array(e.object({
|
|
176
|
+
label: e.string(),
|
|
177
|
+
value: e.string()
|
|
178
|
+
})).optional(),
|
|
179
|
+
placeholder: e.string().optional(),
|
|
180
|
+
temp_id: e.string()
|
|
181
|
+
})),
|
|
182
|
+
form_key: e.string().optional(),
|
|
183
|
+
recipient_email: e.string().email().optional(),
|
|
184
|
+
submit_button_text: e.string(),
|
|
185
|
+
success_message: e.string()
|
|
186
|
+
}),
|
|
187
|
+
heading: e.object({
|
|
188
|
+
level: e.union([
|
|
189
|
+
e.literal(1),
|
|
190
|
+
e.literal(2),
|
|
191
|
+
e.literal(3),
|
|
192
|
+
e.literal(4),
|
|
193
|
+
e.literal(5),
|
|
194
|
+
e.literal(6)
|
|
195
|
+
]),
|
|
196
|
+
textAlign: e.enum([
|
|
197
|
+
"left",
|
|
198
|
+
"center",
|
|
199
|
+
"right",
|
|
200
|
+
"justify"
|
|
201
|
+
]).optional(),
|
|
202
|
+
textColor: e.union([e.enum([
|
|
203
|
+
"foreground",
|
|
204
|
+
"primary",
|
|
205
|
+
"secondary",
|
|
206
|
+
"accent",
|
|
207
|
+
"muted",
|
|
208
|
+
"destructive",
|
|
209
|
+
"background"
|
|
210
|
+
]), e.string().regex(/^(#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})|rgba?\([^)]+\)|hsla?\([^)]+\))$/i, "Must be a hex, rgb(a) or hsl(a) colour")]).optional().describe("Prefer a theme token so the heading adapts to dark mode; use a CSS colour only when the brand requires an exact value"),
|
|
211
|
+
text_content: e.string()
|
|
212
|
+
}),
|
|
213
|
+
image: e.object({
|
|
214
|
+
alt_text: e.string().optional(),
|
|
215
|
+
caption: e.string().optional(),
|
|
216
|
+
external_url: e.string().nullable().optional(),
|
|
217
|
+
height: e.number().nullable().optional(),
|
|
218
|
+
media_id: e.string().nullable().optional(),
|
|
219
|
+
object_key: e.string().nullable().optional(),
|
|
220
|
+
width: e.number().nullable().optional()
|
|
221
|
+
}),
|
|
222
|
+
posts_grid: e.object({
|
|
223
|
+
columns: e.number().min(1).max(6),
|
|
224
|
+
postsPerPage: e.number().min(1).max(50),
|
|
225
|
+
showPagination: e.boolean(),
|
|
226
|
+
title: e.string().optional()
|
|
227
|
+
}),
|
|
228
|
+
product_details: e.object({}),
|
|
229
|
+
product_grid: e.object({
|
|
230
|
+
categoryId: e.string().optional(),
|
|
231
|
+
categoryIds: e.array(e.string()).max(20).optional(),
|
|
232
|
+
limit: e.number().min(0).max(48).default(6),
|
|
233
|
+
productIds: e.array(e.string()).max(24).optional(),
|
|
234
|
+
showPagination: e.boolean().default(!1),
|
|
235
|
+
title: e.string().optional(),
|
|
236
|
+
type: e.enum([
|
|
237
|
+
"latest",
|
|
238
|
+
"category",
|
|
239
|
+
"manual"
|
|
240
|
+
]).default("latest")
|
|
241
|
+
}),
|
|
242
|
+
section: c,
|
|
243
|
+
testimonial: e.object({
|
|
244
|
+
author_name: e.string().min(1),
|
|
245
|
+
author_title: e.string().optional(),
|
|
246
|
+
image_url: e.string().url().optional().or(e.literal("")),
|
|
247
|
+
quote: e.string().min(1)
|
|
248
|
+
}),
|
|
249
|
+
text: e.object({ html_content: e.string() }),
|
|
250
|
+
video_embed: e.object({
|
|
251
|
+
autoplay: e.boolean().optional(),
|
|
252
|
+
controls: e.boolean().optional(),
|
|
253
|
+
title: e.string().optional(),
|
|
254
|
+
url: e.string()
|
|
255
|
+
})
|
|
170
256
|
};
|
|
171
|
-
function
|
|
172
|
-
|
|
257
|
+
function u(e) {
|
|
258
|
+
return t.includes(e);
|
|
173
259
|
}
|
|
174
|
-
function
|
|
175
|
-
|
|
260
|
+
function d(e) {
|
|
261
|
+
return typeof e?.validateBlockContent == "function" ? e.validateBlockContent : null;
|
|
176
262
|
}
|
|
177
|
-
function
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
263
|
+
function f(e, t, n) {
|
|
264
|
+
let r = d(n);
|
|
265
|
+
if (r) return r(e, t);
|
|
266
|
+
let i = l[e].safeParse(t);
|
|
267
|
+
return i.success ? {
|
|
268
|
+
errors: [],
|
|
269
|
+
isValid: !0,
|
|
270
|
+
warnings: []
|
|
271
|
+
} : {
|
|
272
|
+
errors: i.error.issues.map((e) => {
|
|
273
|
+
let t = e.path.join(".");
|
|
274
|
+
return t ? `${t}: ${e.message}` : e.message;
|
|
275
|
+
}),
|
|
276
|
+
isValid: !1,
|
|
277
|
+
warnings: []
|
|
278
|
+
};
|
|
190
279
|
}
|
|
191
|
-
function
|
|
192
|
-
|
|
193
|
-
(n) => !!n && typeof n == "object" && typeof n.key == "string" && typeof n.type == "string"
|
|
194
|
-
) : [];
|
|
280
|
+
function p(e) {
|
|
281
|
+
return Array.isArray(e.fields) ? e.fields.filter((e) => !!e && typeof e == "object" && typeof e.key == "string" && typeof e.type == "string") : [];
|
|
195
282
|
}
|
|
196
|
-
function
|
|
197
|
-
|
|
283
|
+
function m(e) {
|
|
284
|
+
return e == null || typeof e == "string" && e.trim() === "" || Array.isArray(e) && e.length === 0;
|
|
198
285
|
}
|
|
199
|
-
function
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
239
|
-
return { errors: i, isValid: i.length === 0, warnings: s };
|
|
286
|
+
function h(e, t) {
|
|
287
|
+
if (!t || typeof t != "object" || Array.isArray(t)) return {
|
|
288
|
+
errors: ["content must be a JSON object of { field_key: value } pairs."],
|
|
289
|
+
isValid: !1,
|
|
290
|
+
warnings: []
|
|
291
|
+
};
|
|
292
|
+
let n = p(e), r = new Set(n.map((e) => e.key)), i = [], a = [];
|
|
293
|
+
for (let n of Object.keys(t)) r.has(n) || i.push(`Unknown field "${n}" for custom block "${e.slug}". Known fields: ${[...r].join(", ") || "(none)"}.`);
|
|
294
|
+
for (let e of n) {
|
|
295
|
+
let n = t[e.key];
|
|
296
|
+
if (m(n)) {
|
|
297
|
+
e.required && i.push(`Field "${e.key}" is required.`);
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
if (e.type === "text" || e.type === "rich-text") {
|
|
301
|
+
if (typeof n != "string") {
|
|
302
|
+
i.push(`Field "${e.key}" must be a string${e.type === "rich-text" ? " of HTML" : ""}.`);
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
typeof e.max_length == "number" && n.length > e.max_length && i.push(`Field "${e.key}" exceeds its ${e.max_length}-character limit.`), typeof e.min_length == "number" && n.length < e.min_length && i.push(`Field "${e.key}" is shorter than its ${e.min_length}-character minimum.`);
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
if (e.type === "image_r2") {
|
|
309
|
+
let t = n;
|
|
310
|
+
(typeof n != "object" || Array.isArray(n) || typeof t.object_key != "string" || typeof t.url != "string") && i.push(`Field "${e.key}" must be an uploaded image object with object_key and url (upload it with upload_media first) or null.`);
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
if (e.type === "db_relation") {
|
|
314
|
+
let t = (e) => typeof e == "string" || typeof e == "number";
|
|
315
|
+
e.multiple ? (!Array.isArray(n) || !n.every(t)) && i.push(`Field "${e.key}" must be an array of related record ids.`) : t(n) || i.push(`Field "${e.key}" must be a single related record id.`);
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
a.push(`Field "${e.key}" has an unrecognised type "${String(e.type)}"; it was not validated.`);
|
|
319
|
+
}
|
|
320
|
+
return {
|
|
321
|
+
errors: i,
|
|
322
|
+
isValid: i.length === 0,
|
|
323
|
+
warnings: a
|
|
324
|
+
};
|
|
240
325
|
}
|
|
241
|
-
async function
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
`Could not read the custom block definitions: ${typeof r == "object" && r && "message" in r ? String(r.message) : String(r)}`
|
|
246
|
-
);
|
|
247
|
-
return (Array.isArray(n) ? n : []).filter(
|
|
248
|
-
(l) => !!l && typeof l.slug == "string"
|
|
249
|
-
);
|
|
326
|
+
async function g(e) {
|
|
327
|
+
let { data: t, error: n } = await e.from("custom_block_definitions").select("slug, name, fields");
|
|
328
|
+
if (n) throw Error(`Could not read the custom block definitions: ${typeof n == "object" && n && "message" in n ? String(n.message) : String(n)}`);
|
|
329
|
+
return (Array.isArray(t) ? t : []).filter((e) => !!e && typeof e.slug == "string");
|
|
250
330
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
b as cortexAiBlockTypeSchema,
|
|
254
|
-
f as customBlockSlugPatternSchema,
|
|
255
|
-
_ as fallbackBlockSchemas,
|
|
256
|
-
v as isValidBlockType,
|
|
257
|
-
A as loadCustomBlockDefinitions,
|
|
258
|
-
j as readCustomBlockFields,
|
|
259
|
-
h as sectionBlockFallbackSchema,
|
|
260
|
-
B as validateCortexBlockContent,
|
|
261
|
-
S as validateCustomBlockInstanceContent
|
|
262
|
-
};
|
|
331
|
+
//#endregion
|
|
332
|
+
export { t as availableCortexAiBlockTypes, n as cortexAiBlockTypeSchema, a as customBlockSlugPatternSchema, l as fallbackBlockSchemas, u as isValidBlockType, g as loadCustomBlockDefinitions, p as readCustomBlockFields, c as sectionBlockFallbackSchema, f as validateCortexBlockContent, h as validateCustomBlockInstanceContent };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
let e=require("@nextblock-cms/utils/custom-blocks");var t=`id, slug, name, description, fields, layout_schema, is_original`,n=class extends Error{code;status;constructor(e,t){super(e),this.name=`CortexWidgetRegistryInsertError`,this.code=t?.code,this.status=t?.status??500}};function r(e){return JSON.parse(JSON.stringify(e))}function i(e){return e===`23505`?409:e===`42501`?403:500}function a(t){let n=e.customBlockDefinitionCreateSchema.parse({...t,is_original:!0});return{description:n.description,fields:r(n.fields),is_original:!0,layout_schema:r(n.layout_schema),name:n.name,slug:n.slug}}async function o(r,o){let s=a(o),{data:c,error:l}=await r.from(`custom_block_definitions`).insert(s).select(t).single();if(l||!c)throw new n(l?.message??`Failed to insert Cortex custom block definition.`,{code:l?.code,status:i(l?.code)});return e.customBlockDefinitionRowSchema.parse(c)}exports.CORTEX_WIDGET_DEFINITION_SELECT=t,exports.CortexWidgetRegistryInsertError=n,exports.buildCortexWidgetDefinitionInsertPayload=a,exports.insertCortexWidgetDefinition=o;
|