@gzl10/nexus-sdk 0.1.7 → 0.1.9

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.
Files changed (2) hide show
  1. package/dist/index.d.ts +92 -6
  2. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -19,6 +19,38 @@ interface AuthRequest<TUser = unknown, TAbility = unknown> extends Request {
19
19
  user: TUser;
20
20
  ability: TAbility;
21
21
  }
22
+ /**
23
+ * Usuario base sin contraseña para uso en plugins
24
+ * Usado para tipar relaciones con usuarios (ej: author, created_by)
25
+ */
26
+ interface BaseUser {
27
+ id: string;
28
+ name: string;
29
+ email: string;
30
+ role_id: string;
31
+ created_at: Date;
32
+ updated_at: Date;
33
+ created_by: string | null;
34
+ updated_by: string | null;
35
+ }
36
+ /**
37
+ * Parámetros de paginación para queries
38
+ */
39
+ interface PaginationParams {
40
+ page: number;
41
+ limit: number;
42
+ }
43
+ /**
44
+ * Resultado paginado genérico
45
+ */
46
+ interface PaginatedResult<T> {
47
+ items: T[];
48
+ total: number;
49
+ page: number;
50
+ limit: number;
51
+ totalPages: number;
52
+ hasNext: boolean;
53
+ }
22
54
  /**
23
55
  * Tipo de campo para formularios dinámicos
24
56
  */
@@ -76,6 +108,58 @@ interface ModuleRequirements {
76
108
  env?: string[];
77
109
  modules?: string[];
78
110
  }
111
+ /**
112
+ * Interfaz genérica para ability CASL
113
+ * Permite verificar permisos sin depender directamente de @casl/ability
114
+ */
115
+ interface AbilityLike {
116
+ can: (action: string, subject: unknown) => boolean;
117
+ cannot: (action: string, subject: unknown) => boolean;
118
+ }
119
+ /**
120
+ * Error de forbidden con método throwUnlessCan
121
+ */
122
+ interface ForbiddenErrorInstance {
123
+ throwUnlessCan: (action: string, subject: unknown) => void;
124
+ }
125
+ /**
126
+ * Constructor de ForbiddenError con método from()
127
+ */
128
+ interface ForbiddenErrorConstructor {
129
+ from: (ability: AbilityLike) => ForbiddenErrorInstance;
130
+ }
131
+ /**
132
+ * Abilities CASL disponibles en el contexto
133
+ * Permite usar CASL en plugins sin importar @casl/ability directamente
134
+ */
135
+ interface ModuleAbilities {
136
+ /** Wrapper para verificar permisos contra instancias */
137
+ subject: (type: string, object: unknown) => unknown;
138
+ /** Error de CASL para throwUnlessCan */
139
+ ForbiddenError: ForbiddenErrorConstructor;
140
+ /** Otros métodos que el backend pueda añadir */
141
+ [key: string]: unknown;
142
+ }
143
+ /**
144
+ * AuthRequest pre-tipado para uso en plugins
145
+ * Usa BaseUser y AbilityLike para tipado básico sin depender del backend
146
+ */
147
+ type PluginAuthRequest = AuthRequest<BaseUser, AbilityLike>;
148
+ /**
149
+ * Resolver de usuarios para plugins
150
+ * Permite acceder a usuarios sin conocer la implementación interna
151
+ */
152
+ interface UsersResolver {
153
+ findById: (id: string) => Promise<BaseUser | null>;
154
+ findByIds: (ids: string[]) => Promise<BaseUser[]>;
155
+ }
156
+ /**
157
+ * Servicios core inyectados por el backend
158
+ * Los plugins acceden a estos servicios via ctx.services
159
+ */
160
+ interface CoreServices {
161
+ users?: UsersResolver;
162
+ }
79
163
  /**
80
164
  * Helpers para migraciones de base de datos
81
165
  */
@@ -110,12 +194,12 @@ interface ModuleContext {
110
194
  config: Record<string, unknown>;
111
195
  errors: {
112
196
  AppError: new (message: string, statusCode?: number) => Error;
113
- NotFoundError: new (message: string) => Error;
114
- UnauthorizedError: new (message: string) => Error;
115
- ForbiddenError: new (message: string) => Error;
116
- ConflictError: new (message: string) => Error;
197
+ NotFoundError: new (message?: string) => Error;
198
+ UnauthorizedError: new (message?: string) => Error;
199
+ ForbiddenError: new (message?: string) => Error;
200
+ ConflictError: new (message?: string) => Error;
117
201
  };
118
- abilities: Record<string, unknown>;
202
+ abilities: ModuleAbilities;
119
203
  events: {
120
204
  emit: (event: string, ...args: unknown[]) => boolean;
121
205
  on: (event: string, listener: (...args: unknown[]) => void) => unknown;
@@ -130,6 +214,8 @@ interface ModuleContext {
130
214
  data?: Record<string, unknown>;
131
215
  }) => Promise<void>;
132
216
  };
217
+ /** Servicios de módulos core (users, etc.) */
218
+ services: CoreServices & Record<string, unknown>;
133
219
  }
134
220
  /**
135
221
  * Manifest de un módulo Nexus
@@ -192,4 +278,4 @@ interface PluginManifest {
192
278
  modules: ModuleManifest[];
193
279
  }
194
280
 
195
- export type { AuthRequest, FieldValidation, FormField, FormFieldType, ListType, MigrationHelpers, ModuleContext, ModuleEntity, ModuleManifest, ModuleMiddlewares, ModuleRequirements, PluginCategory, PluginManifest };
281
+ export type { AbilityLike, AuthRequest, BaseUser, CoreServices, FieldValidation, ForbiddenErrorConstructor, ForbiddenErrorInstance, FormField, FormFieldType, ListType, MigrationHelpers, ModuleAbilities, ModuleContext, ModuleEntity, ModuleManifest, ModuleMiddlewares, ModuleRequirements, PaginatedResult, PaginationParams, PluginAuthRequest, PluginCategory, PluginManifest, UsersResolver };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gzl10/nexus-sdk",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "description": "SDK types for creating Nexus plugins and modules",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",