@gzl10/nexus-sdk 0.1.8 → 0.1.10
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/index.d.ts +64 -12
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Knex } from 'knex';
|
|
2
|
+
export { Knex } from 'knex';
|
|
2
3
|
import { Request, RequestHandler, Router } from 'express';
|
|
3
4
|
export { CookieOptions, NextFunction, Request, RequestHandler, Response, Router } from 'express';
|
|
4
5
|
import { Logger } from 'pino';
|
|
@@ -11,6 +12,9 @@ import { Logger } from 'pino';
|
|
|
11
12
|
* depending on the full @gzl10/nexus-backend package.
|
|
12
13
|
*/
|
|
13
14
|
|
|
15
|
+
type KnexCreateTableBuilder = Knex.CreateTableBuilder;
|
|
16
|
+
type KnexAlterTableBuilder = Knex.AlterTableBuilder;
|
|
17
|
+
type KnexTransaction = Knex.Transaction;
|
|
14
18
|
/**
|
|
15
19
|
* Request autenticado con usuario y abilities CASL
|
|
16
20
|
* El backend especializa TUser y TAbility con tipos concretos
|
|
@@ -108,6 +112,43 @@ interface ModuleRequirements {
|
|
|
108
112
|
env?: string[];
|
|
109
113
|
modules?: string[];
|
|
110
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Interfaz genérica para ability CASL
|
|
117
|
+
* Permite verificar permisos sin depender directamente de @casl/ability
|
|
118
|
+
*/
|
|
119
|
+
interface AbilityLike {
|
|
120
|
+
can: (action: string, subject: unknown) => boolean;
|
|
121
|
+
cannot: (action: string, subject: unknown) => boolean;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Error de forbidden con método throwUnlessCan
|
|
125
|
+
*/
|
|
126
|
+
interface ForbiddenErrorInstance {
|
|
127
|
+
throwUnlessCan: (action: string, subject: unknown) => void;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Constructor de ForbiddenError con método from()
|
|
131
|
+
*/
|
|
132
|
+
interface ForbiddenErrorConstructor {
|
|
133
|
+
from: (ability: AbilityLike) => ForbiddenErrorInstance;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Abilities CASL disponibles en el contexto
|
|
137
|
+
* Permite usar CASL en plugins sin importar @casl/ability directamente
|
|
138
|
+
*/
|
|
139
|
+
interface ModuleAbilities {
|
|
140
|
+
/** Wrapper para verificar permisos contra instancias */
|
|
141
|
+
subject: (type: string, object: unknown) => unknown;
|
|
142
|
+
/** Error de CASL para throwUnlessCan */
|
|
143
|
+
ForbiddenError: ForbiddenErrorConstructor;
|
|
144
|
+
/** Otros métodos que el backend pueda añadir */
|
|
145
|
+
[key: string]: unknown;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* AuthRequest pre-tipado para uso en plugins
|
|
149
|
+
* Usa BaseUser y AbilityLike para tipado básico sin depender del backend
|
|
150
|
+
*/
|
|
151
|
+
type PluginAuthRequest = AuthRequest<BaseUser, AbilityLike>;
|
|
111
152
|
/**
|
|
112
153
|
* Resolver de usuarios para plugins
|
|
113
154
|
* Permite acceder a usuarios sin conocer la implementación interna
|
|
@@ -131,16 +172,27 @@ interface MigrationHelpers {
|
|
|
131
172
|
addAuditFieldsIfMissing: (db: Knex, tableName: string) => Promise<void>;
|
|
132
173
|
addColumnIfMissing: (db: Knex, tableName: string, columnName: string, columnBuilder: (table: Knex.AlterTableBuilder) => void) => Promise<boolean>;
|
|
133
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* Schema de validación genérico (compatible con Zod sin depender de él)
|
|
177
|
+
* Cualquier objeto con método parse() es válido
|
|
178
|
+
*/
|
|
179
|
+
interface ValidationSchema {
|
|
180
|
+
parse: (data: unknown) => unknown;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Opciones para el middleware de validación
|
|
184
|
+
*/
|
|
185
|
+
interface ValidateSchemas {
|
|
186
|
+
body?: ValidationSchema;
|
|
187
|
+
query?: ValidationSchema;
|
|
188
|
+
params?: ValidationSchema;
|
|
189
|
+
}
|
|
134
190
|
/**
|
|
135
191
|
* Middlewares disponibles en el contexto
|
|
136
192
|
*/
|
|
137
193
|
interface ModuleMiddlewares {
|
|
138
|
-
validate: (schemas:
|
|
139
|
-
|
|
140
|
-
query?: unknown;
|
|
141
|
-
params?: unknown;
|
|
142
|
-
}) => RequestHandler;
|
|
143
|
-
[key: string]: RequestHandler | ((...args: unknown[]) => RequestHandler) | undefined;
|
|
194
|
+
validate: (schemas: ValidateSchemas) => RequestHandler;
|
|
195
|
+
[key: string]: RequestHandler | ((...args: any[]) => RequestHandler) | undefined;
|
|
144
196
|
}
|
|
145
197
|
/**
|
|
146
198
|
* Contexto inyectado a los módulos
|
|
@@ -157,12 +209,12 @@ interface ModuleContext {
|
|
|
157
209
|
config: Record<string, unknown>;
|
|
158
210
|
errors: {
|
|
159
211
|
AppError: new (message: string, statusCode?: number) => Error;
|
|
160
|
-
NotFoundError: new (message
|
|
161
|
-
UnauthorizedError: new (message
|
|
162
|
-
ForbiddenError: new (message
|
|
163
|
-
ConflictError: new (message
|
|
212
|
+
NotFoundError: new (message?: string) => Error;
|
|
213
|
+
UnauthorizedError: new (message?: string) => Error;
|
|
214
|
+
ForbiddenError: new (message?: string) => Error;
|
|
215
|
+
ConflictError: new (message?: string) => Error;
|
|
164
216
|
};
|
|
165
|
-
abilities:
|
|
217
|
+
abilities: ModuleAbilities;
|
|
166
218
|
events: {
|
|
167
219
|
emit: (event: string, ...args: unknown[]) => boolean;
|
|
168
220
|
on: (event: string, listener: (...args: unknown[]) => void) => unknown;
|
|
@@ -241,4 +293,4 @@ interface PluginManifest {
|
|
|
241
293
|
modules: ModuleManifest[];
|
|
242
294
|
}
|
|
243
295
|
|
|
244
|
-
export type { AuthRequest, BaseUser, CoreServices, FieldValidation, FormField, FormFieldType, ListType, MigrationHelpers, ModuleContext, ModuleEntity, ModuleManifest, ModuleMiddlewares, ModuleRequirements, PaginatedResult, PaginationParams, PluginCategory, PluginManifest, UsersResolver };
|
|
296
|
+
export type { AbilityLike, AuthRequest, BaseUser, CoreServices, FieldValidation, ForbiddenErrorConstructor, ForbiddenErrorInstance, FormField, FormFieldType, KnexAlterTableBuilder, KnexCreateTableBuilder, KnexTransaction, ListType, MigrationHelpers, ModuleAbilities, ModuleContext, ModuleEntity, ModuleManifest, ModuleMiddlewares, ModuleRequirements, PaginatedResult, PaginationParams, PluginAuthRequest, PluginCategory, PluginManifest, UsersResolver, ValidateSchemas, ValidationSchema };
|