@blinkk/root-cms 2.4.10 → 2.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/plugin.js CHANGED
@@ -1,18 +1,18 @@
1
1
  import {
2
2
  ChatClient,
3
3
  summarizeDiff
4
- } from "./chunk-ZOEPOKGE.js";
4
+ } from "./chunk-T5UK2H24.js";
5
5
  import {
6
6
  getServerVersion
7
- } from "./chunk-Y65VGJLE.js";
7
+ } from "./chunk-KTUENARU.js";
8
8
  import {
9
9
  runCronJobs
10
- } from "./chunk-SI44FG3H.js";
10
+ } from "./chunk-RIJF2AHU.js";
11
11
  import {
12
12
  RootCMSClient,
13
13
  parseDocId,
14
14
  unmarshalData
15
- } from "./chunk-62EVNFXB.js";
15
+ } from "./chunk-NUUABQRN.js";
16
16
  import "./chunk-MLKGABMK.js";
17
17
 
18
18
  // core/plugin.ts
@@ -373,7 +373,7 @@ function api(server, options) {
373
373
  }
374
374
  try {
375
375
  const cmsClient = new RootCMSClient(req.rootConfig);
376
- const { generateImage } = await import("./ai-DRQJXU4N.js");
376
+ const { generateImage } = await import("./ai-OZY3JXDH.js");
377
377
  const imageUrl = await generateImage(cmsClient, {
378
378
  prompt,
379
379
  aspectRatio
@@ -385,6 +385,84 @@ function api(server, options) {
385
385
  }
386
386
  }
387
387
  );
388
+ server.use(
389
+ "/cms/api/ai.publish_message",
390
+ async (req, res) => {
391
+ if (req.method !== "POST" || !String(req.get("content-type")).startsWith("application/json")) {
392
+ res.status(400).json({ success: false, error: "BAD_REQUEST" });
393
+ return;
394
+ }
395
+ if (!req.user?.email) {
396
+ res.status(401).json({ success: false, error: "UNAUTHORIZED" });
397
+ return;
398
+ }
399
+ const reqBody = req.body || {};
400
+ const docId = typeof reqBody.docId === "string" ? reqBody.docId.trim() : "";
401
+ if (!docId) {
402
+ res.status(400).json({
403
+ success: false,
404
+ error: "MISSING_REQUIRED_FIELD",
405
+ field: "docId"
406
+ });
407
+ return;
408
+ }
409
+ try {
410
+ const cmsClient = new RootCMSClient(req.rootConfig);
411
+ const beforeVersion = "published";
412
+ const afterVersion = "draft";
413
+ const diffPayload = await buildDocDiffPayload(cmsClient, docId, {
414
+ beforeVersion,
415
+ afterVersion
416
+ });
417
+ if (!diffPayload.before && !diffPayload.after) {
418
+ res.status(200).json({ success: true, message: "Initial version" });
419
+ return;
420
+ }
421
+ const { generatePublishMessage } = await import("./ai-OZY3JXDH.js");
422
+ const message = await generatePublishMessage(cmsClient, {
423
+ before: diffPayload.before,
424
+ after: diffPayload.after
425
+ });
426
+ res.status(200).json({ success: true, message });
427
+ } catch (err) {
428
+ console.error(err.stack || err);
429
+ res.status(500).json({ success: false, error: "UNKNOWN" });
430
+ }
431
+ }
432
+ );
433
+ server.use("/cms/api/ai.translate", async (req, res) => {
434
+ if (req.method !== "POST" || !String(req.get("content-type")).startsWith("application/json")) {
435
+ res.status(400).json({ success: false, error: "BAD_REQUEST" });
436
+ return;
437
+ }
438
+ if (!req.user?.email) {
439
+ res.status(401).json({ success: false, error: "UNAUTHORIZED" });
440
+ return;
441
+ }
442
+ const reqBody = req.body || {};
443
+ const sourceText = reqBody.sourceText;
444
+ const targetLocales = reqBody.targetLocales;
445
+ const description = reqBody.description;
446
+ const existingTranslations = reqBody.existingTranslations || {};
447
+ if (!sourceText || !targetLocales || !Array.isArray(targetLocales)) {
448
+ res.status(400).json({ success: false, error: "MISSING_REQUIRED_FIELD" });
449
+ return;
450
+ }
451
+ try {
452
+ const cmsClient = new RootCMSClient(req.rootConfig);
453
+ const { translateString } = await import("./ai-OZY3JXDH.js");
454
+ const translations = await translateString(cmsClient, {
455
+ sourceText,
456
+ targetLocales,
457
+ description,
458
+ existingTranslations
459
+ });
460
+ res.status(200).json({ success: true, translations });
461
+ } catch (err) {
462
+ console.error(err.stack || err);
463
+ res.status(500).json({ success: false, error: err.message || "UNKNOWN" });
464
+ }
465
+ });
388
466
  }
389
467
 
390
468
  // core/sse.ts
package/dist/project.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { S as Schema, C as Collection } from './schema-Bux4PrV2.js';
1
+ import { S as Schema, C as Collection } from './schema-BKfPP_s9.js';
2
2
 
3
3
  /**
4
4
  * Loads various files or configurations from the project.
package/dist/project.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  SCHEMA_MODULES,
3
3
  getCollectionSchema,
4
4
  getProjectSchemas
5
- } from "./chunk-377TGNX2.js";
5
+ } from "./chunk-RNDSZKAW.js";
6
6
  import "./chunk-MLKGABMK.js";
7
7
  export {
8
8
  SCHEMA_MODULES,
@@ -146,9 +146,31 @@ type ArrayField = CommonFieldProps & {
146
146
  buttonLabel?: string;
147
147
  };
148
148
  declare function array(field: Omit<ArrayField, 'type'>): ArrayField;
149
+ /**
150
+ * A schema pattern that is resolved at project load time. This allows schemas
151
+ * to reference other schemas by glob pattern without causing circular import
152
+ * issues, since resolution is deferred until all schemas are loaded.
153
+ */
154
+ interface SchemaPattern {
155
+ /** Marker to identify this as a schema pattern. */
156
+ _schemaPattern: true;
157
+ /** Glob pattern to match schema files. */
158
+ pattern: string;
159
+ /** Schema names to exclude from the matched results. */
160
+ exclude?: string[];
161
+ /** Field IDs to omit from the matched schemas. */
162
+ omitFields?: string[];
163
+ }
149
164
  type OneOfField = CommonFieldProps & {
150
165
  type: 'oneof';
151
- types: Schema[] | string[];
166
+ /**
167
+ * Schema types to include in the oneOf field. Can be:
168
+ * - An array of Schema objects
169
+ * - An array of string names (resolved at runtime)
170
+ * - A mixed array of Schema objects and strings
171
+ * - A SchemaPattern from `schema.glob()` (resolved at project load)
172
+ */
173
+ types: Schema[] | string[] | Array<Schema | string> | SchemaPattern;
152
174
  };
153
175
  declare function oneOf(field: Omit<OneOfField, 'type'>): OneOfField;
154
176
  type RichTextField = CommonFieldProps & {
@@ -304,6 +326,57 @@ type Collection = SchemaWithTypes & {
304
326
  };
305
327
  declare function defineCollection(collection: Omit<Collection, 'id'>): Omit<Collection, 'id'>;
306
328
  declare const collection: typeof defineCollection;
329
+ /**
330
+ * Options for `schema.glob()`.
331
+ */
332
+ interface GlobOptions {
333
+ /** Schema names to exclude from the matched results. */
334
+ exclude?: string[];
335
+ /** Field IDs to omit from the matched schemas. */
336
+ omitFields?: string[];
337
+ }
338
+ /**
339
+ * Creates a schema pattern that is resolved at project load time.
340
+ *
341
+ * This is the recommended way to reference multiple schemas in a `oneOf` field,
342
+ * especially for self-referencing schemas like containers. The pattern is
343
+ * resolved after all schemas are loaded, completely avoiding circular import
344
+ * issues.
345
+ *
346
+ * @param pattern - Glob pattern to match schema files (e.g., '/templates/*\/*.schema.ts')
347
+ * @param options - Optional configuration for exclusions and field omissions
348
+ *
349
+ * @example
350
+ * ```ts
351
+ * // Simple usage - include all templates:
352
+ * export default schema.define({
353
+ * name: 'Container',
354
+ * fields: [
355
+ * schema.array({
356
+ * id: 'children',
357
+ * of: schema.oneOf({
358
+ * types: schema.glob('/templates/*\/*.schema.ts'),
359
+ * }),
360
+ * }),
361
+ * ],
362
+ * });
363
+ *
364
+ * // With exclusions:
365
+ * schema.oneOf({
366
+ * types: schema.glob('/templates/*\/*.schema.ts', {
367
+ * exclude: ['DeprecatedTemplate'],
368
+ * }),
369
+ * });
370
+ *
371
+ * // With field omissions (useful for nested contexts):
372
+ * schema.oneOf({
373
+ * types: schema.glob('/blocks/*\/*.schema.ts', {
374
+ * omitFields: ['id'],
375
+ * }),
376
+ * });
377
+ * ```
378
+ */
379
+ declare function glob(pattern: string, options?: GlobOptions): SchemaPattern;
307
380
 
308
381
  type schema_ArrayField = ArrayField;
309
382
  type schema_BooleanField = BooleanField;
@@ -314,6 +387,7 @@ type schema_DateTimeField = DateTimeField;
314
387
  type schema_Field = Field;
315
388
  type schema_FieldWithId = FieldWithId;
316
389
  type schema_FileField = FileField;
390
+ type schema_GlobOptions = GlobOptions;
317
391
  type schema_ImageField = ImageField;
318
392
  type schema_MultiSelectField = MultiSelectField;
319
393
  type schema_NumberField = NumberField;
@@ -324,6 +398,7 @@ type schema_ReferenceField = ReferenceField;
324
398
  type schema_ReferencesField = ReferencesField;
325
399
  type schema_RichTextField = RichTextField;
326
400
  type schema_Schema = Schema;
401
+ type schema_SchemaPattern = SchemaPattern;
327
402
  type schema_SchemaWithTypes = SchemaWithTypes;
328
403
  type schema_SelectField = SelectField;
329
404
  type schema_StringField = StringField;
@@ -336,6 +411,7 @@ declare const schema_define: typeof define;
336
411
  declare const schema_defineCollection: typeof defineCollection;
337
412
  declare const schema_defineSchema: typeof defineSchema;
338
413
  declare const schema_file: typeof file;
414
+ declare const schema_glob: typeof glob;
339
415
  declare const schema_image: typeof image;
340
416
  declare const schema_multiselect: typeof multiselect;
341
417
  declare const schema_number: typeof number;
@@ -347,7 +423,7 @@ declare const schema_richtext: typeof richtext;
347
423
  declare const schema_select: typeof select;
348
424
  declare const schema_string: typeof string;
349
425
  declare namespace schema {
350
- export { type schema_ArrayField as ArrayField, type schema_BooleanField as BooleanField, type schema_Collection as Collection, type schema_CommonFieldProps as CommonFieldProps, type schema_DateField as DateField, type schema_DateTimeField as DateTimeField, type schema_Field as Field, type schema_FieldWithId as FieldWithId, type schema_FileField as FileField, type schema_ImageField as ImageField, type schema_MultiSelectField as MultiSelectField, type schema_NumberField as NumberField, type schema_ObjectField as ObjectField, type schema_ObjectLikeField as ObjectLikeField, type schema_OneOfField as OneOfField, type schema_ReferenceField as ReferenceField, type schema_ReferencesField as ReferencesField, type schema_RichTextField as RichTextField, type schema_Schema as Schema, type schema_SchemaWithTypes as SchemaWithTypes, type schema_SelectField as SelectField, type schema_StringField as StringField, schema_array as array, schema_boolean as boolean, schema_collection as collection, schema_date as date, schema_datetime as datetime, schema_define as define, schema_defineCollection as defineCollection, schema_defineSchema as defineSchema, schema_file as file, schema_image as image, schema_multiselect as multiselect, schema_number as number, schema_object as object, schema_oneOf as oneOf, schema_reference as reference, schema_references as references, schema_richtext as richtext, schema_select as select, schema_string as string };
426
+ export { type schema_ArrayField as ArrayField, type schema_BooleanField as BooleanField, type schema_Collection as Collection, type schema_CommonFieldProps as CommonFieldProps, type schema_DateField as DateField, type schema_DateTimeField as DateTimeField, type schema_Field as Field, type schema_FieldWithId as FieldWithId, type schema_FileField as FileField, type schema_GlobOptions as GlobOptions, type schema_ImageField as ImageField, type schema_MultiSelectField as MultiSelectField, type schema_NumberField as NumberField, type schema_ObjectField as ObjectField, type schema_ObjectLikeField as ObjectLikeField, type schema_OneOfField as OneOfField, type schema_ReferenceField as ReferenceField, type schema_ReferencesField as ReferencesField, type schema_RichTextField as RichTextField, type schema_Schema as Schema, type schema_SchemaPattern as SchemaPattern, type schema_SchemaWithTypes as SchemaWithTypes, type schema_SelectField as SelectField, type schema_StringField as StringField, schema_array as array, schema_boolean as boolean, schema_collection as collection, schema_date as date, schema_datetime as datetime, schema_define as define, schema_defineCollection as defineCollection, schema_defineSchema as defineSchema, schema_file as file, schema_glob as glob, schema_image as image, schema_multiselect as multiselect, schema_number as number, schema_object as object, schema_oneOf as oneOf, schema_reference as reference, schema_references as references, schema_richtext as richtext, schema_select as select, schema_string as string };
351
427
  }
352
428
 
353
429
  export { type Collection as C, type Schema as S, schema as s };