@surnie/plugin-kit 0.2.1 → 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 +102 -4
- package/package.json +1 -1
- package/schema/manifest.schema.json +177 -0
package/dist/cli.js
CHANGED
|
@@ -281,13 +281,17 @@ var networkPermission = z.strictObject({
|
|
|
281
281
|
"domains"
|
|
282
282
|
)
|
|
283
283
|
}).meta({ description: "Dominios a los que el plugin podr\xE1 llamar (por la recepci\xF3n). Solo el nombre: api.ejemplo.com." });
|
|
284
|
+
var mailPermission = z.strictObject({
|
|
285
|
+
kind: z.literal("mail"),
|
|
286
|
+
...permissionBase
|
|
287
|
+
}).meta({ description: "Mandar correos desde la direcci\xF3n del proyecto (sus clientes, avisos\u2026), con l\xEDmites." });
|
|
284
288
|
var fieldsPermission = z.strictObject({
|
|
285
289
|
kind: z.literal("fields"),
|
|
286
290
|
...permissionBase,
|
|
287
291
|
fields: z.record(z.string(), z.looseObject({ type: z.string() }))
|
|
288
292
|
}).meta({ description: "Campos que el plugin a\xF1ade a colecciones del proyecto que elija el admin; con el prefijo del plugin." });
|
|
289
|
-
var permissionSchema = z.discriminatedUnion("kind", [contentPermission, usersPermission, networkPermission, fieldsPermission], {
|
|
290
|
-
error: "kind: content, users, network o fields."
|
|
293
|
+
var permissionSchema = z.discriminatedUnion("kind", [contentPermission, usersPermission, networkPermission, mailPermission, fieldsPermission], {
|
|
294
|
+
error: "kind: content, users, network, mail o fields."
|
|
291
295
|
});
|
|
292
296
|
var KEY = /^[a-z][a-zA-Z0-9]{0,39}$/;
|
|
293
297
|
var keyOf = (what) => z.string().regex(KEY, { error: `${what}: letras y d\xEDgitos, empieza por min\xFAscula, hasta 40 (es el nombre en el c\xF3digo).` });
|
|
@@ -348,6 +352,60 @@ var panelNav = z.strictObject({
|
|
|
348
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." }),
|
|
349
353
|
permission: keyOf("permission").optional().meta({ description: "Permiso del plugin que hace falta para verlo." })
|
|
350
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
|
+
});
|
|
351
409
|
var panelScreen = z.strictObject({
|
|
352
410
|
id: keyOf("id").meta({ description: "Nombre de la pantalla en ui.js (screens.<id>)." }),
|
|
353
411
|
title: text(80, "title").meta({ description: "T\xEDtulo de la pantalla." }),
|
|
@@ -373,6 +431,7 @@ var panelAction = z.strictObject({
|
|
|
373
431
|
}).meta({ description: "Una acci\xF3n (un bot\xF3n) sobre registros: la ejecuta server.js (actions.<id>)." });
|
|
374
432
|
var panelSchema = z.strictObject({
|
|
375
433
|
permissions: z.array(panelPermission).default([]),
|
|
434
|
+
menu: panelMenu.optional(),
|
|
376
435
|
nav: z.array(panelNav).default([]),
|
|
377
436
|
screens: z.array(panelScreen).default([]),
|
|
378
437
|
widgets: z.array(panelWidget).default([]),
|
|
@@ -478,6 +537,16 @@ function crossChecks(m, ctx) {
|
|
|
478
537
|
m.panel.nav.forEach((n, i) => {
|
|
479
538
|
if (!screens.has(n.screen)) issue(["panel.nav", i, "screen"], `"${n.id}": "${n.screen}" no es una pantalla de panel.screens.`);
|
|
480
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
|
+
}
|
|
481
550
|
for (const field3 of ["name", "description"]) {
|
|
482
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).`);
|
|
483
552
|
}
|
|
@@ -555,6 +624,13 @@ function manifestTexts(m) {
|
|
|
555
624
|
for (const o of st.options ?? []) out.push(o.label);
|
|
556
625
|
}
|
|
557
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
|
+
}
|
|
558
634
|
for (const n of m.panel.nav) out.push(n.label);
|
|
559
635
|
for (const s2 of m.panel.screens) out.push(s2.title);
|
|
560
636
|
for (const w of m.panel.widgets) out.push(w.title);
|
|
@@ -908,7 +984,16 @@ var TYPES_FILE = join(".surnie", "types.d.ts");
|
|
|
908
984
|
var UI_TYPES_FILE = join(".surnie", "ui.d.ts");
|
|
909
985
|
var str = (s2) => JSON.stringify(s2);
|
|
910
986
|
var union = (values, none = "never") => values.length ? values.map(str).join(" | ") : none;
|
|
911
|
-
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). */
|
|
912
997
|
type SurnieEntry = { id: string; [field: string]: unknown };
|
|
913
998
|
|
|
914
999
|
/** Consultas con el mismo formato que la API REST (filters, sort y pagination de estilo Strapi). */
|
|
@@ -986,6 +1071,7 @@ function grantedType(p) {
|
|
|
986
1071
|
if (p.kind === "content") return `{ kind: "content"; actions: (${union(p.actions)})[]; collections: SurnieGrantedCollection[] }`;
|
|
987
1072
|
if (p.kind === "fields") return `{ kind: "fields"; collections: { collection: string; label: string }[] }`;
|
|
988
1073
|
if (p.kind === "users") return `{ kind: "users"; fields: (${union(p.fields)})[] }`;
|
|
1074
|
+
if (p.kind === "mail") return `{ kind: "mail" }`;
|
|
989
1075
|
return `{ kind: "network"; domains: (${union(p.domains)})[] }`;
|
|
990
1076
|
}
|
|
991
1077
|
function routeParams(path) {
|
|
@@ -1059,10 +1145,15 @@ function pluginTypes(m) {
|
|
|
1059
1145
|
/** Una entrada por id (en un global, sin id). null si no existe. */
|
|
1060
1146
|
get(query: { collection: string; id?: string; locale?: string; status?: "draft" | "published"; fields?: string | string[] }): Promise<SurnieEntry | null>;
|
|
1061
1147
|
create(input: { collection: string; data: Record<string, unknown>; locale?: string }): Promise<SurnieEntry>;
|
|
1062
|
-
/** 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). */
|
|
1063
1149
|
update(input: { collection: string; id?: string; data: Record<string, unknown>; locale?: string; rev?: number }): Promise<SurnieEntry>;
|
|
1064
1150
|
delete(input: { collection: string; id: string }): Promise<{ ok: true }>;
|
|
1065
1151
|
publish(input: { collection: string; id: string; locale: string; publish?: boolean }): Promise<{ ok: true }>;
|
|
1152
|
+
/**
|
|
1153
|
+
* \xBFvalue es la contrase\xF1a guardada en ese campo password? El hash nunca sale. Tiempo constante y
|
|
1154
|
+
* l\xEDmite de fallos por registro (10 en 15 minutos): limita t\xFA tambi\xE9n por IP en tu ruta de login.
|
|
1155
|
+
*/
|
|
1156
|
+
verifyPassword(input: { collection: string; id: string; field: string; value: string; locale?: string }): Promise<boolean>;
|
|
1066
1157
|
};`);
|
|
1067
1158
|
}
|
|
1068
1159
|
if (userFields.length) {
|
|
@@ -1081,6 +1172,13 @@ function pluginTypes(m) {
|
|
|
1081
1172
|
permissions: {
|
|
1082
1173
|
get(): Promise<SurniePermissions>;
|
|
1083
1174
|
};`);
|
|
1175
|
+
if (all.some((p) => p.kind === "mail")) {
|
|
1176
|
+
api.push(` /** Correo con la direcci\xF3n del proyecto (si el admin te dio el permiso). Un correo por destinatario. */
|
|
1177
|
+
mail: {
|
|
1178
|
+
/** Hasta 10 destinatarios; text, html o los dos. Como mucho 500 correos por hora. */
|
|
1179
|
+
send(input: { to: string | string[]; subject: string; text?: string; html?: string }): Promise<{ sent: number }>;
|
|
1180
|
+
};`);
|
|
1181
|
+
}
|
|
1084
1182
|
if (secrets.length) {
|
|
1085
1183
|
api.push(` /** Los secretos que rellena el admin; null si no est\xE1 puesto. Nunca salen del servidor. */
|
|
1086
1184
|
secrets: {
|
package/package.json
CHANGED
|
@@ -195,6 +195,33 @@
|
|
|
195
195
|
"additionalProperties": false,
|
|
196
196
|
"description": "Dominios a los que el plugin podrá llamar (por la recepción). Solo el nombre: api.ejemplo.com."
|
|
197
197
|
},
|
|
198
|
+
{
|
|
199
|
+
"type": "object",
|
|
200
|
+
"properties": {
|
|
201
|
+
"kind": {
|
|
202
|
+
"type": "string",
|
|
203
|
+
"const": "mail"
|
|
204
|
+
},
|
|
205
|
+
"id": {
|
|
206
|
+
"type": "string",
|
|
207
|
+
"pattern": "^[a-z][a-zA-Z0-9]{0,39}$",
|
|
208
|
+
"description": "Id estable del permiso (no cambiarlo entre versiones): así se sabe qué es nuevo al actualizar."
|
|
209
|
+
},
|
|
210
|
+
"purpose": {
|
|
211
|
+
"type": "string",
|
|
212
|
+
"minLength": 1,
|
|
213
|
+
"maxLength": 200,
|
|
214
|
+
"description": "Para qué lo quiere el plugin, en una frase: el admin lo lee antes de aceptar."
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
"required": [
|
|
218
|
+
"kind",
|
|
219
|
+
"id",
|
|
220
|
+
"purpose"
|
|
221
|
+
],
|
|
222
|
+
"additionalProperties": false,
|
|
223
|
+
"description": "Mandar correos desde la dirección del proyecto (sus clientes, avisos…), con límites."
|
|
224
|
+
},
|
|
198
225
|
{
|
|
199
226
|
"type": "object",
|
|
200
227
|
"properties": {
|
|
@@ -371,6 +398,33 @@
|
|
|
371
398
|
"additionalProperties": false,
|
|
372
399
|
"description": "Dominios a los que el plugin podrá llamar (por la recepción). Solo el nombre: api.ejemplo.com."
|
|
373
400
|
},
|
|
401
|
+
{
|
|
402
|
+
"type": "object",
|
|
403
|
+
"properties": {
|
|
404
|
+
"kind": {
|
|
405
|
+
"type": "string",
|
|
406
|
+
"const": "mail"
|
|
407
|
+
},
|
|
408
|
+
"id": {
|
|
409
|
+
"type": "string",
|
|
410
|
+
"pattern": "^[a-z][a-zA-Z0-9]{0,39}$",
|
|
411
|
+
"description": "Id estable del permiso (no cambiarlo entre versiones): así se sabe qué es nuevo al actualizar."
|
|
412
|
+
},
|
|
413
|
+
"purpose": {
|
|
414
|
+
"type": "string",
|
|
415
|
+
"minLength": 1,
|
|
416
|
+
"maxLength": 200,
|
|
417
|
+
"description": "Para qué lo quiere el plugin, en una frase: el admin lo lee antes de aceptar."
|
|
418
|
+
}
|
|
419
|
+
},
|
|
420
|
+
"required": [
|
|
421
|
+
"kind",
|
|
422
|
+
"id",
|
|
423
|
+
"purpose"
|
|
424
|
+
],
|
|
425
|
+
"additionalProperties": false,
|
|
426
|
+
"description": "Mandar correos desde la dirección del proyecto (sus clientes, avisos…), con límites."
|
|
427
|
+
},
|
|
374
428
|
{
|
|
375
429
|
"type": "object",
|
|
376
430
|
"properties": {
|
|
@@ -808,6 +862,129 @@
|
|
|
808
862
|
"description": "Un permiso del panel del plugin: sale en Ajustes → Roles; el admin lo tiene siempre."
|
|
809
863
|
}
|
|
810
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
|
+
},
|
|
811
988
|
"nav": {
|
|
812
989
|
"default": [],
|
|
813
990
|
"type": "array",
|