@surnie/plugin-kit 0.2.2 → 0.2.3
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/cli.js +83 -2
- package/package.json +1 -1
- package/schema/manifest.schema.json +123 -0
package/dist/cli.js
CHANGED
|
@@ -352,6 +352,60 @@ var panelNav = z.strictObject({
|
|
|
352
352
|
area: z.enum(["content", "settings"]).default("content").meta({ description: "D\xF3nde: content, en el apartado del plugin del panel de Contenido; settings, en Ajustes." }),
|
|
353
353
|
permission: keyOf("permission").optional().meta({ description: "Permiso del plugin que hace falta para verlo." })
|
|
354
354
|
}).meta({ description: "Una entrada de la barra lateral." });
|
|
355
|
+
var MENU_ICONS = [
|
|
356
|
+
"puzzle",
|
|
357
|
+
"cart",
|
|
358
|
+
"store",
|
|
359
|
+
"package",
|
|
360
|
+
"receipt",
|
|
361
|
+
"credit-card",
|
|
362
|
+
"wallet",
|
|
363
|
+
"truck",
|
|
364
|
+
"tag",
|
|
365
|
+
"percent",
|
|
366
|
+
"chart",
|
|
367
|
+
"users",
|
|
368
|
+
"calendar",
|
|
369
|
+
"mail",
|
|
370
|
+
"megaphone",
|
|
371
|
+
"message",
|
|
372
|
+
"bell",
|
|
373
|
+
"star",
|
|
374
|
+
"heart",
|
|
375
|
+
"book",
|
|
376
|
+
"file",
|
|
377
|
+
"folder",
|
|
378
|
+
"clipboard",
|
|
379
|
+
"globe",
|
|
380
|
+
"map",
|
|
381
|
+
"camera",
|
|
382
|
+
"music",
|
|
383
|
+
"video",
|
|
384
|
+
"graduation",
|
|
385
|
+
"briefcase"
|
|
386
|
+
];
|
|
387
|
+
var menuItem = z.union([
|
|
388
|
+
z.strictObject({
|
|
389
|
+
screen: keyOf("screen").meta({ description: "Una pantalla del plugin (panel.screens)." }),
|
|
390
|
+
label: text(60, "label").optional().meta({ description: "Texto del enlace; sin \xE9l, el t\xEDtulo de la pantalla." })
|
|
391
|
+
}),
|
|
392
|
+
z.strictObject({
|
|
393
|
+
collection: z.string().min(1).meta({ description: "Una colecci\xF3n o un global del modelo del plugin." }),
|
|
394
|
+
label: text(60, "label").optional().meta({ description: "Texto del enlace; sin \xE9l, el nombre de la colecci\xF3n." })
|
|
395
|
+
})
|
|
396
|
+
]).meta({ description: "Una entrada del apartado: una pantalla o una colecci\xF3n (o global) del plugin." });
|
|
397
|
+
var panelMenu = z.strictObject({
|
|
398
|
+
label: text(40, "label").meta({ description: "Nombre del apartado (el del icono)." }),
|
|
399
|
+
icon: z.enum(MENU_ICONS).default("puzzle").meta({ description: "Su icono, de la lista de Surnie." }),
|
|
400
|
+
groups: z.array(
|
|
401
|
+
z.strictObject({
|
|
402
|
+
label: text(60, "label").optional().meta({ description: "T\xEDtulo del grupo." }),
|
|
403
|
+
items: z.array(menuItem).min(1)
|
|
404
|
+
})
|
|
405
|
+
).min(1).meta({ description: "Los grupos de enlaces de su panel, en orden." })
|
|
406
|
+
}).meta({
|
|
407
|
+
description: "Un apartado propio en la barra de la izquierda (como un men\xFA de WordPress), con sus pantallas y colecciones. Las colecciones del plugin que no est\xE9n aqu\xED no salen en la navegaci\xF3n; sin `menu`, van en Contenido."
|
|
408
|
+
});
|
|
355
409
|
var panelScreen = z.strictObject({
|
|
356
410
|
id: keyOf("id").meta({ description: "Nombre de la pantalla en ui.js (screens.<id>)." }),
|
|
357
411
|
title: text(80, "title").meta({ description: "T\xEDtulo de la pantalla." }),
|
|
@@ -377,6 +431,7 @@ var panelAction = z.strictObject({
|
|
|
377
431
|
}).meta({ description: "Una acci\xF3n (un bot\xF3n) sobre registros: la ejecuta server.js (actions.<id>)." });
|
|
378
432
|
var panelSchema = z.strictObject({
|
|
379
433
|
permissions: z.array(panelPermission).default([]),
|
|
434
|
+
menu: panelMenu.optional(),
|
|
380
435
|
nav: z.array(panelNav).default([]),
|
|
381
436
|
screens: z.array(panelScreen).default([]),
|
|
382
437
|
widgets: z.array(panelWidget).default([]),
|
|
@@ -482,6 +537,16 @@ function crossChecks(m, ctx) {
|
|
|
482
537
|
m.panel.nav.forEach((n, i) => {
|
|
483
538
|
if (!screens.has(n.screen)) issue(["panel.nav", i, "screen"], `"${n.id}": "${n.screen}" no es una pantalla de panel.screens.`);
|
|
484
539
|
});
|
|
540
|
+
if (m.panel.menu) {
|
|
541
|
+
const own = new Set([...m.model.collections, ...m.model.singleTypes].map((t) => t.apiId));
|
|
542
|
+
m.panel.menu.groups.forEach(
|
|
543
|
+
(g, gi) => g.items.forEach((item, ii) => {
|
|
544
|
+
const at = ["panel.menu", "groups", gi, "items", ii];
|
|
545
|
+
if ("screen" in item && !screens.has(item.screen)) issue([...at, "screen"], `"${item.screen}" no es una pantalla de panel.screens.`);
|
|
546
|
+
if ("collection" in item && !own.has(item.collection)) issue([...at, "collection"], `"${item.collection}" no es una colecci\xF3n ni un global del modelo del plugin.`);
|
|
547
|
+
})
|
|
548
|
+
);
|
|
549
|
+
}
|
|
485
550
|
for (const field3 of ["name", "description"]) {
|
|
486
551
|
if (TEXT_KEY.test(m[field3])) issue([field3], `${field3}: va en literal (sale en el cat\xE1logo y en la plataforma, donde no hay traducciones).`);
|
|
487
552
|
}
|
|
@@ -559,6 +624,13 @@ function manifestTexts(m) {
|
|
|
559
624
|
for (const o of st.options ?? []) out.push(o.label);
|
|
560
625
|
}
|
|
561
626
|
for (const p of m.panel.permissions) out.push(p.label, ...p.description ? [p.description] : []);
|
|
627
|
+
if (m.panel.menu) {
|
|
628
|
+
out.push(m.panel.menu.label);
|
|
629
|
+
for (const g of m.panel.menu.groups) {
|
|
630
|
+
if (g.label) out.push(g.label);
|
|
631
|
+
for (const item of g.items) if (item.label) out.push(item.label);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
562
634
|
for (const n of m.panel.nav) out.push(n.label);
|
|
563
635
|
for (const s2 of m.panel.screens) out.push(s2.title);
|
|
564
636
|
for (const w of m.panel.widgets) out.push(w.title);
|
|
@@ -912,7 +984,16 @@ var TYPES_FILE = join(".surnie", "types.d.ts");
|
|
|
912
984
|
var UI_TYPES_FILE = join(".surnie", "ui.d.ts");
|
|
913
985
|
var str = (s2) => JSON.stringify(s2);
|
|
914
986
|
var union = (values, none = "never") => values.length ? values.map(str).join(" | ") : none;
|
|
915
|
-
var COMMON = `/**
|
|
987
|
+
var COMMON = `/**
|
|
988
|
+
* El \`code\` del Error con el que falla una llamada a \`surnie.*\`, para decidir sin leer el mensaje:
|
|
989
|
+
* invalid (datos o consulta que no valen), not_found, forbidden (no concedido), conflict (el \`rev\` ya
|
|
990
|
+
* no es el de ahora: vuelve a leer y reintenta), unique (otro registro tiene ese valor), rate_limited
|
|
991
|
+
* e internal.
|
|
992
|
+
*/
|
|
993
|
+
type SurnieErrorCode = "invalid" | "not_found" | "forbidden" | "conflict" | "unique" | "rate_limited" | "internal";
|
|
994
|
+
type SurnieError = Error & { code?: SurnieErrorCode };
|
|
995
|
+
|
|
996
|
+
/** Una entrada tal como la ve el plugin: solo los campos concedidos (el resto llega como null). */
|
|
916
997
|
type SurnieEntry = { id: string; [field: string]: unknown };
|
|
917
998
|
|
|
918
999
|
/** Consultas con el mismo formato que la API REST (filters, sort y pagination de estilo Strapi). */
|
|
@@ -1064,7 +1145,7 @@ function pluginTypes(m) {
|
|
|
1064
1145
|
/** Una entrada por id (en un global, sin id). null si no existe. */
|
|
1065
1146
|
get(query: { collection: string; id?: string; locale?: string; status?: "draft" | "published"; fields?: string | string[] }): Promise<SurnieEntry | null>;
|
|
1066
1147
|
create(input: { collection: string; data: Record<string, unknown>; locale?: string }): Promise<SurnieEntry>;
|
|
1067
|
-
/** rev: el _rev le\xEDdo; si el documento cambi\xF3 entretanto, falla (concurrencia optimista). */
|
|
1148
|
+
/** rev: el _rev le\xEDdo; si el documento cambi\xF3 entretanto, falla con \`code: "conflict"\` (concurrencia optimista). */
|
|
1068
1149
|
update(input: { collection: string; id?: string; data: Record<string, unknown>; locale?: string; rev?: number }): Promise<SurnieEntry>;
|
|
1069
1150
|
delete(input: { collection: string; id: string }): Promise<{ ok: true }>;
|
|
1070
1151
|
publish(input: { collection: string; id: string; locale: string; publish?: boolean }): Promise<{ ok: true }>;
|
package/package.json
CHANGED
|
@@ -862,6 +862,129 @@
|
|
|
862
862
|
"description": "Un permiso del panel del plugin: sale en Ajustes → Roles; el admin lo tiene siempre."
|
|
863
863
|
}
|
|
864
864
|
},
|
|
865
|
+
"menu": {
|
|
866
|
+
"type": "object",
|
|
867
|
+
"properties": {
|
|
868
|
+
"label": {
|
|
869
|
+
"type": "string",
|
|
870
|
+
"minLength": 1,
|
|
871
|
+
"maxLength": 40,
|
|
872
|
+
"description": "Nombre del apartado (el del icono)."
|
|
873
|
+
},
|
|
874
|
+
"icon": {
|
|
875
|
+
"default": "puzzle",
|
|
876
|
+
"description": "Su icono, de la lista de Surnie.",
|
|
877
|
+
"type": "string",
|
|
878
|
+
"enum": [
|
|
879
|
+
"puzzle",
|
|
880
|
+
"cart",
|
|
881
|
+
"store",
|
|
882
|
+
"package",
|
|
883
|
+
"receipt",
|
|
884
|
+
"credit-card",
|
|
885
|
+
"wallet",
|
|
886
|
+
"truck",
|
|
887
|
+
"tag",
|
|
888
|
+
"percent",
|
|
889
|
+
"chart",
|
|
890
|
+
"users",
|
|
891
|
+
"calendar",
|
|
892
|
+
"mail",
|
|
893
|
+
"megaphone",
|
|
894
|
+
"message",
|
|
895
|
+
"bell",
|
|
896
|
+
"star",
|
|
897
|
+
"heart",
|
|
898
|
+
"book",
|
|
899
|
+
"file",
|
|
900
|
+
"folder",
|
|
901
|
+
"clipboard",
|
|
902
|
+
"globe",
|
|
903
|
+
"map",
|
|
904
|
+
"camera",
|
|
905
|
+
"music",
|
|
906
|
+
"video",
|
|
907
|
+
"graduation",
|
|
908
|
+
"briefcase"
|
|
909
|
+
]
|
|
910
|
+
},
|
|
911
|
+
"groups": {
|
|
912
|
+
"minItems": 1,
|
|
913
|
+
"type": "array",
|
|
914
|
+
"items": {
|
|
915
|
+
"type": "object",
|
|
916
|
+
"properties": {
|
|
917
|
+
"label": {
|
|
918
|
+
"description": "Título del grupo.",
|
|
919
|
+
"type": "string",
|
|
920
|
+
"minLength": 1,
|
|
921
|
+
"maxLength": 60
|
|
922
|
+
},
|
|
923
|
+
"items": {
|
|
924
|
+
"minItems": 1,
|
|
925
|
+
"type": "array",
|
|
926
|
+
"items": {
|
|
927
|
+
"anyOf": [
|
|
928
|
+
{
|
|
929
|
+
"type": "object",
|
|
930
|
+
"properties": {
|
|
931
|
+
"screen": {
|
|
932
|
+
"type": "string",
|
|
933
|
+
"pattern": "^[a-z][a-zA-Z0-9]{0,39}$",
|
|
934
|
+
"description": "Una pantalla del plugin (panel.screens)."
|
|
935
|
+
},
|
|
936
|
+
"label": {
|
|
937
|
+
"description": "Texto del enlace; sin él, el título de la pantalla.",
|
|
938
|
+
"type": "string",
|
|
939
|
+
"minLength": 1,
|
|
940
|
+
"maxLength": 60
|
|
941
|
+
}
|
|
942
|
+
},
|
|
943
|
+
"required": [
|
|
944
|
+
"screen"
|
|
945
|
+
],
|
|
946
|
+
"additionalProperties": false
|
|
947
|
+
},
|
|
948
|
+
{
|
|
949
|
+
"type": "object",
|
|
950
|
+
"properties": {
|
|
951
|
+
"collection": {
|
|
952
|
+
"type": "string",
|
|
953
|
+
"minLength": 1,
|
|
954
|
+
"description": "Una colección o un global del modelo del plugin."
|
|
955
|
+
},
|
|
956
|
+
"label": {
|
|
957
|
+
"description": "Texto del enlace; sin él, el nombre de la colección.",
|
|
958
|
+
"type": "string",
|
|
959
|
+
"minLength": 1,
|
|
960
|
+
"maxLength": 60
|
|
961
|
+
}
|
|
962
|
+
},
|
|
963
|
+
"required": [
|
|
964
|
+
"collection"
|
|
965
|
+
],
|
|
966
|
+
"additionalProperties": false
|
|
967
|
+
}
|
|
968
|
+
],
|
|
969
|
+
"description": "Una entrada del apartado: una pantalla o una colección (o global) del plugin."
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
},
|
|
973
|
+
"required": [
|
|
974
|
+
"items"
|
|
975
|
+
],
|
|
976
|
+
"additionalProperties": false
|
|
977
|
+
},
|
|
978
|
+
"description": "Los grupos de enlaces de su panel, en orden."
|
|
979
|
+
}
|
|
980
|
+
},
|
|
981
|
+
"required": [
|
|
982
|
+
"label",
|
|
983
|
+
"groups"
|
|
984
|
+
],
|
|
985
|
+
"additionalProperties": false,
|
|
986
|
+
"description": "Un apartado propio en la barra de la izquierda (como un menú de WordPress), con sus pantallas y colecciones. Las colecciones del plugin que no estén aquí no salen en la navegación; sin `menu`, van en Contenido."
|
|
987
|
+
},
|
|
865
988
|
"nav": {
|
|
866
989
|
"default": [],
|
|
867
990
|
"type": "array",
|