@andrewcaires/api 5.3.6 → 5.4.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/README.md +22 -5
- package/dist/index.cjs.js +2 -2
- package/dist/index.d.ts +90 -14
- package/dist/index.esm.js +2 -2
- package/package.json +11 -12
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @andrewcaires/api v5.
|
|
2
|
+
* @andrewcaires/api v5.4.1
|
|
3
3
|
* Simple api for small applications using express, jsonwebtoken, sequelize and websocket
|
|
4
4
|
* (c) 2026 Andrew Caires
|
|
5
5
|
* @license: MIT
|
|
6
6
|
*/
|
|
7
7
|
import { Context, Application as Application$1, ExpressOptions, ResponseError } from '@andrewcaires/express';
|
|
8
8
|
import { ModelFindOptions, ModelUpdateOptions, Model as Model$1, Sequelize } from '@andrewcaires/sequelize';
|
|
9
|
-
import {
|
|
9
|
+
import { TypeAnyObject, TypeObjectString, TypeAnyFunction, TypeAnyConstructor, EventEmitter, TypeObject, ValidationBase, ValidationShape } from '@andrewcaires/utils.js';
|
|
10
10
|
import { WebSocketServer } from 'ws';
|
|
11
11
|
import { Model, CreateOptions, Attributes, FindOptions, IncludeOptions, FindAttributeOptions, ModelStatic } from 'sequelize';
|
|
12
12
|
import { Env as Env$1 } from '@andrewcaires/node';
|
|
@@ -86,12 +86,6 @@ declare module "express-serve-static-core" {
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
declare module "express-serve-static-core" {
|
|
90
|
-
interface Request {
|
|
91
|
-
profile?: TypeObjectString;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
89
|
declare module "express-serve-static-core" {
|
|
96
90
|
interface Request {
|
|
97
91
|
tenants?: Array<{
|
|
@@ -180,6 +174,14 @@ declare enum LogLevels {
|
|
|
180
174
|
ERROR = "error"
|
|
181
175
|
}
|
|
182
176
|
|
|
177
|
+
declare enum PageTypes {
|
|
178
|
+
PAGE = "page",
|
|
179
|
+
GROUP = "group",
|
|
180
|
+
DIVIDER = "divider",
|
|
181
|
+
HIDDEN = "hidden",
|
|
182
|
+
EXTERNAL = "external"
|
|
183
|
+
}
|
|
184
|
+
|
|
183
185
|
declare enum TenantStatus {
|
|
184
186
|
ACTIVE = "active",
|
|
185
187
|
PENDING = "pending",
|
|
@@ -196,6 +198,18 @@ declare enum UserStatus {
|
|
|
196
198
|
ARCHIVED = "archived"
|
|
197
199
|
}
|
|
198
200
|
|
|
201
|
+
interface WorkerCliRequest {
|
|
202
|
+
name: string;
|
|
203
|
+
}
|
|
204
|
+
interface WorkerDeclaration {
|
|
205
|
+
name: string;
|
|
206
|
+
}
|
|
207
|
+
type WorkerHandlerResult = unknown | Promise<unknown>;
|
|
208
|
+
type WorkerHandler = () => WorkerHandlerResult;
|
|
209
|
+
interface WorkerRegistered extends WorkerDeclaration {
|
|
210
|
+
run: WorkerHandler;
|
|
211
|
+
}
|
|
212
|
+
|
|
199
213
|
declare class RegisterModel extends Model$1 {
|
|
200
214
|
readonly id: string;
|
|
201
215
|
hash: string;
|
|
@@ -221,6 +235,26 @@ declare class UserAuthModel extends Model$1 {
|
|
|
221
235
|
user: UserModel;
|
|
222
236
|
}
|
|
223
237
|
|
|
238
|
+
declare class PageModel extends Model$1 {
|
|
239
|
+
readonly id: string;
|
|
240
|
+
type: PageTypes;
|
|
241
|
+
name: string;
|
|
242
|
+
description: string;
|
|
243
|
+
icon: string;
|
|
244
|
+
path: string;
|
|
245
|
+
position: number;
|
|
246
|
+
active: boolean;
|
|
247
|
+
metadata: TypeAnyObject;
|
|
248
|
+
readonly created_at: Date;
|
|
249
|
+
readonly updated_at: Date;
|
|
250
|
+
readonly deleted_at: Date | null;
|
|
251
|
+
page_id: string;
|
|
252
|
+
page: PageModel;
|
|
253
|
+
pages: Array<PageModel>;
|
|
254
|
+
permission_id: string;
|
|
255
|
+
permission: PermissionModel;
|
|
256
|
+
}
|
|
257
|
+
|
|
224
258
|
declare class PermissionModel extends Model$1 {
|
|
225
259
|
readonly id: string;
|
|
226
260
|
name: string;
|
|
@@ -231,6 +265,7 @@ declare class PermissionModel extends Model$1 {
|
|
|
231
265
|
readonly updated_at: Date;
|
|
232
266
|
readonly deleted_at: Date | null;
|
|
233
267
|
groups_permissions: Array<GroupPermissionModel>;
|
|
268
|
+
pages: Array<PageModel>;
|
|
234
269
|
}
|
|
235
270
|
|
|
236
271
|
declare class GroupPermissionModel extends Model$1 {
|
|
@@ -501,7 +536,9 @@ declare class ModelService<M extends Model<any>> extends Service {
|
|
|
501
536
|
|
|
502
537
|
declare class UserService extends Service {
|
|
503
538
|
private hashOptions;
|
|
504
|
-
|
|
539
|
+
canAssignPassword(user_id: string, password: string): Promise<boolean>;
|
|
540
|
+
checkPassword(user_id: string, password: string): Promise<boolean>;
|
|
541
|
+
createPassword(user_id: string, value: string, ctx?: Context): Promise<boolean>;
|
|
505
542
|
getGroups(user_id: string, tenant_id?: string | null): Promise<Array<string>>;
|
|
506
543
|
getPermissions(user_id: string, tenant_id?: string | null): Promise<Array<string>>;
|
|
507
544
|
getTenants(user_id: string): Promise<Array<{
|
|
@@ -514,10 +551,17 @@ declare class Application<T extends ApplicationEvents = ApplicationEvents> exten
|
|
|
514
551
|
authService: AuthService;
|
|
515
552
|
userService: UserService;
|
|
516
553
|
private _webSocket?;
|
|
554
|
+
private _prepared;
|
|
517
555
|
constructor(controllers: Array<object | TypeAnyConstructor<object>>, options?: ExpressOptions);
|
|
518
556
|
error(error: any, source?: string): void;
|
|
519
557
|
log(message: string, source?: string): void;
|
|
520
558
|
listen(): Promise<void>;
|
|
559
|
+
prepare(): Promise<void>;
|
|
560
|
+
run(argv?: Array<string>): Promise<unknown>;
|
|
561
|
+
runWorker(name: string): Promise<unknown>;
|
|
562
|
+
workerCliRequest(argv?: Array<string>): WorkerCliRequest | undefined;
|
|
563
|
+
private getCliOption;
|
|
564
|
+
private writeWorkerResult;
|
|
521
565
|
migrations(database: Sequelize): Promise<void>;
|
|
522
566
|
websocket(): WebSocketServer | undefined;
|
|
523
567
|
}
|
|
@@ -620,6 +664,7 @@ declare class GroupsPermissionsController extends ModelController<PermissionMode
|
|
|
620
664
|
protected set(ctx: Context, group_id: string, permissions: Array<string>): Promise<void>;
|
|
621
665
|
private addPermissions;
|
|
622
666
|
private checkGroup;
|
|
667
|
+
private checkPermissions;
|
|
623
668
|
}
|
|
624
669
|
|
|
625
670
|
declare class HealthController {
|
|
@@ -646,6 +691,17 @@ declare class McpController extends BaseController {
|
|
|
646
691
|
private jsonParseErrorResponse;
|
|
647
692
|
private respond;
|
|
648
693
|
private setResponseHeaders;
|
|
694
|
+
private getAllowedOrigin;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
declare class PagesController extends CrudController<PageModel> {
|
|
698
|
+
protected readonly model: typeof PageModel;
|
|
699
|
+
private schemaCreate;
|
|
700
|
+
private schemaUpdate;
|
|
701
|
+
CrudValidateCreate(): TypeObject<ValidationBase>;
|
|
702
|
+
CrudValidateUpdate(): TypeObject<ValidationBase>;
|
|
703
|
+
protected position(ctx: Context, pages: Array<TypeAnyObject>): Promise<void>;
|
|
704
|
+
private checkPages;
|
|
649
705
|
}
|
|
650
706
|
|
|
651
707
|
declare class PermissionsController extends CrudController<PermissionModel> {
|
|
@@ -863,6 +919,7 @@ interface McpHttpHandlerOptions {
|
|
|
863
919
|
serverName?: string;
|
|
864
920
|
serverVersion?: string;
|
|
865
921
|
allowedHeaders?: Array<string>;
|
|
922
|
+
allowedOrigins?: Array<string>;
|
|
866
923
|
}
|
|
867
924
|
declare const MCP_HTTP_ALLOWED_METHODS: readonly ["POST", "DELETE", "OPTIONS"];
|
|
868
925
|
declare const MCP_HTTP_ALLOW: string;
|
|
@@ -880,11 +937,12 @@ declare class McpHttpHandler {
|
|
|
880
937
|
private readonly serverName;
|
|
881
938
|
private readonly serverVersion;
|
|
882
939
|
private readonly allowedHeaders;
|
|
940
|
+
private readonly allowedOrigins;
|
|
883
941
|
constructor(options: McpHttpHandlerOptions);
|
|
884
942
|
post(ctx: Context): Promise<McpHttpResponse>;
|
|
885
943
|
delete(ctx: Context): McpHttpResponse;
|
|
886
|
-
get(): McpHttpResponse;
|
|
887
|
-
options(): McpHttpResponse;
|
|
944
|
+
get(ctx?: Context): McpHttpResponse;
|
|
945
|
+
options(ctx?: Context): McpHttpResponse;
|
|
888
946
|
private initialize;
|
|
889
947
|
private initialized;
|
|
890
948
|
private callTool;
|
|
@@ -903,6 +961,7 @@ declare class McpHttpHandler {
|
|
|
903
961
|
private getHeaderFromRecord;
|
|
904
962
|
private normalizeHeaderValue;
|
|
905
963
|
private normalizeAllowedHeaders;
|
|
964
|
+
private getAllowedOrigin;
|
|
906
965
|
private getAuthContext;
|
|
907
966
|
}
|
|
908
967
|
|
|
@@ -924,6 +983,9 @@ declare const discoverMcpTools: (controllers: Array<object>) => Array<McpRegiste
|
|
|
924
983
|
|
|
925
984
|
declare class TestController extends BaseController {
|
|
926
985
|
protected json(ctx: Context): Promise<void>;
|
|
986
|
+
protected workerSum(): Promise<{
|
|
987
|
+
value: number;
|
|
988
|
+
}>;
|
|
927
989
|
protected sum(args: TypeAnyObject, _context: McpToolContext): Promise<{
|
|
928
990
|
value: number;
|
|
929
991
|
}>;
|
|
@@ -983,9 +1045,12 @@ declare class UsersController extends ModelController<UserModel> {
|
|
|
983
1045
|
protected readonly model: typeof UserModel;
|
|
984
1046
|
protected readonly permissions: string[];
|
|
985
1047
|
path: string;
|
|
1048
|
+
protected readonly userService: UserService;
|
|
986
1049
|
constructor();
|
|
987
1050
|
protected avatar(ctx: Context, user: UserModel): Promise<void>;
|
|
988
1051
|
protected avatar_del(ctx: Context, user: UserModel): Promise<void>;
|
|
1052
|
+
protected password(ctx: Context, oldPassword: string, newPassword: string, user: UserModel): Promise<void>;
|
|
1053
|
+
protected password_admin(ctx: Context, password: string, user_id: string): Promise<void>;
|
|
989
1054
|
protected add(ctx: Context): Promise<void>;
|
|
990
1055
|
protected all(ctx: Context): Promise<void>;
|
|
991
1056
|
protected rows(ctx: Context): Promise<void>;
|
|
@@ -1002,6 +1067,7 @@ declare class UsersGroupsController extends ModelController<GroupModel> {
|
|
|
1002
1067
|
protected del(ctx: Context, user_id: string, groups: Array<string>): Promise<void>;
|
|
1003
1068
|
protected set(ctx: Context, user_id: string, groups: Array<string>): Promise<void>;
|
|
1004
1069
|
private addGroups;
|
|
1070
|
+
private checkGroups;
|
|
1005
1071
|
private checkUser;
|
|
1006
1072
|
}
|
|
1007
1073
|
|
|
@@ -1023,6 +1089,7 @@ declare class UsersTenantsController extends ModelController<TenantModel> {
|
|
|
1023
1089
|
protected del(ctx: Context, user_id: string, tenants: Array<string>): Promise<void>;
|
|
1024
1090
|
protected set(ctx: Context, user_id: string, tenants: Array<string>): Promise<void>;
|
|
1025
1091
|
private addTenants;
|
|
1092
|
+
private checkTenants;
|
|
1026
1093
|
private checkUser;
|
|
1027
1094
|
}
|
|
1028
1095
|
|
|
@@ -1067,6 +1134,15 @@ declare const McpTool: (options: McpToolOptions) => MethodDecorator;
|
|
|
1067
1134
|
|
|
1068
1135
|
declare const Audit: (active?: boolean) => ClassDecorator;
|
|
1069
1136
|
|
|
1137
|
+
declare const WORKER_METADATA: unique symbol;
|
|
1138
|
+
interface WorkerMetadata extends WorkerDeclaration {
|
|
1139
|
+
propertyKey: string | symbol;
|
|
1140
|
+
}
|
|
1141
|
+
declare const Worker: (name: string) => MethodDecorator;
|
|
1142
|
+
declare const getWorkerMetadata: (target: object | TypeAnyConstructor<object>) => Array<WorkerMetadata>;
|
|
1143
|
+
declare const discoverWorkers: (controllers: Array<object>) => Array<WorkerRegistered>;
|
|
1144
|
+
declare const runWorker: (controllers: Array<object>, name: string) => Promise<unknown>;
|
|
1145
|
+
|
|
1070
1146
|
declare class Env extends Env$1 {
|
|
1071
1147
|
static readonly AUDIT_IGNORE: string[];
|
|
1072
1148
|
static readonly BASE_NAME: string;
|
|
@@ -1094,6 +1170,7 @@ declare class Env extends Env$1 {
|
|
|
1094
1170
|
static readonly PASSWORD_MEMORY_COST: number;
|
|
1095
1171
|
static readonly PASSWORD_PARALLELISM: number;
|
|
1096
1172
|
static readonly PASSWORD_PEPPER: string;
|
|
1173
|
+
static readonly PASSWORD_REUSE: boolean;
|
|
1097
1174
|
static readonly PASSWORD_TIME_COST: number;
|
|
1098
1175
|
static readonly SLEEP_AUTH: number;
|
|
1099
1176
|
static readonly SLEEP_FORGOT: number;
|
|
@@ -1116,9 +1193,8 @@ declare class Env extends Env$1 {
|
|
|
1116
1193
|
static readonly API_SESSION_NAME: string;
|
|
1117
1194
|
static readonly API_SESSION_LIFETIME: number;
|
|
1118
1195
|
static readonly API_SESSION_SECRET: string;
|
|
1119
|
-
static readonly API_USER_HISTORY: boolean;
|
|
1120
1196
|
static readonly API_WEBSOCKET_START: boolean;
|
|
1121
1197
|
}
|
|
1122
1198
|
|
|
1123
|
-
export { Application, Audit, AuditModel, AuditTypes, AuditsController, AuthController, AuthService, BaseController, CanCreate, CanDelete, CanRead, CanUpdate, Config, ConfigModel, CrudController, Env, FilesController, ForgotController, ForgotModel, GroupModel, GroupPermissionModel, GroupTypes, GroupsController, GroupsPermissionsController, HasGroups, HasPermissions, HasScope, HealthController, IsAuthenticated, Log, LogLevels, LogModel, Loggable, LogsController, MCP_DEFAULT_PROTOCOL_VERSION, MCP_HTTP_ALLOW, MCP_HTTP_ALLOWED_METHODS, MCP_HTTP_DEFAULT_ALLOWED_HEADERS, MCP_PROTOCOL_VERSION_HEADER, MCP_SESSION_ID_HEADER, MCP_SUPPORTED_PROTOCOL_VERSIONS, MCP_TOOL_METADATA, McpController, McpError, McpErrorCode, McpHttpHandler, McpInternalError, McpInvalidParamsError, McpInvalidRequestError, McpInvalidSessionError, McpMethodNotFoundError, McpParseError, McpServerError, McpSessionStore, McpTool, McpToolNotFoundError, McpToolRegistry, MigrationModel, ModelController, ModelService, PermissionModel, PermissionsController, RegisterController, RegisterModel, ReqAccess, ReqGroup, ReqGroups, ReqPermission, ReqPermissions, ReqTenant, ReqTenants, ReqUser, Secret, SecretModel, Service, SessionModel, SessionStore, SetupController, TenantModel, TenantStatus, TenantsController, TestController, UserAuthModel, UserGroupModel, UserKeyModel, UserModel, UserPasswordModel, UserService, UserStatus, UserTenantModel, UsersController, UsersGroupsController, UsersKeysController, UsersTenantsController, assertValidMcpToolDefinition, canFactory, discoverMcpTools, getMcpToolMetadata, isJsonParseError, isJsonRpcId, jsonParseErrorResponse, jsonRpcError, jsonRpcErrorFromCode, jsonRpcResult, parseJsonRpcRequest, sequelize };
|
|
1124
|
-
export type { ApplicationEvents, AuthEvents, AuthResult, ForgotEvents, McpCallToolResult, McpDecoratedToolHandler, McpHttpHandlerOptions, McpHttpResponse, McpJsonRpcErrorBody, McpJsonRpcErrorResult, McpJsonRpcId, McpJsonRpcRequest, McpJsonRpcResult, McpLogger, McpNormalizedValidation, McpProtocolVersion, McpRegisteredTool, McpSession, McpToolCallLog, McpToolContext, McpToolDeclaration, McpToolDefinition, McpToolHandlerResult, McpToolInput, McpToolMetadata, McpToolOptions, McpToolOutput, ModelArgumentsBase, ModelArgumentsCount, ModelArgumentsCreate, ModelArgumentsDelete, ModelArgumentsFindAll, ModelArgumentsFindOne, ModelArgumentsInclude, ModelArgumentsUpdate, ModelCallbackFindAll, ModelCallbackFindOne, ModelOptions, ModelResultFindAll, RegisterEvents };
|
|
1199
|
+
export { Application, Audit, AuditModel, AuditTypes, AuditsController, AuthController, AuthService, BaseController, CanCreate, CanDelete, CanRead, CanUpdate, Config, ConfigModel, CrudController, Env, FilesController, ForgotController, ForgotModel, GroupModel, GroupPermissionModel, GroupTypes, GroupsController, GroupsPermissionsController, HasGroups, HasPermissions, HasScope, HealthController, IsAuthenticated, Log, LogLevels, LogModel, Loggable, LogsController, MCP_DEFAULT_PROTOCOL_VERSION, MCP_HTTP_ALLOW, MCP_HTTP_ALLOWED_METHODS, MCP_HTTP_DEFAULT_ALLOWED_HEADERS, MCP_PROTOCOL_VERSION_HEADER, MCP_SESSION_ID_HEADER, MCP_SUPPORTED_PROTOCOL_VERSIONS, MCP_TOOL_METADATA, McpController, McpError, McpErrorCode, McpHttpHandler, McpInternalError, McpInvalidParamsError, McpInvalidRequestError, McpInvalidSessionError, McpMethodNotFoundError, McpParseError, McpServerError, McpSessionStore, McpTool, McpToolNotFoundError, McpToolRegistry, MigrationModel, ModelController, ModelService, PageModel, PageTypes, PagesController, PermissionModel, PermissionsController, RegisterController, RegisterModel, ReqAccess, ReqGroup, ReqGroups, ReqPermission, ReqPermissions, ReqTenant, ReqTenants, ReqUser, Secret, SecretModel, Service, SessionModel, SessionStore, SetupController, TenantModel, TenantStatus, TenantsController, TestController, UserAuthModel, UserGroupModel, UserKeyModel, UserModel, UserPasswordModel, UserService, UserStatus, UserTenantModel, UsersController, UsersGroupsController, UsersKeysController, UsersTenantsController, WORKER_METADATA, Worker, assertValidMcpToolDefinition, canFactory, discoverMcpTools, discoverWorkers, getMcpToolMetadata, getWorkerMetadata, isJsonParseError, isJsonRpcId, jsonParseErrorResponse, jsonRpcError, jsonRpcErrorFromCode, jsonRpcResult, parseJsonRpcRequest, runWorker, sequelize };
|
|
1200
|
+
export type { ApplicationEvents, AuthEvents, AuthResult, ForgotEvents, McpCallToolResult, McpDecoratedToolHandler, McpHttpHandlerOptions, McpHttpResponse, McpJsonRpcErrorBody, McpJsonRpcErrorResult, McpJsonRpcId, McpJsonRpcRequest, McpJsonRpcResult, McpLogger, McpNormalizedValidation, McpProtocolVersion, McpRegisteredTool, McpSession, McpToolCallLog, McpToolContext, McpToolDeclaration, McpToolDefinition, McpToolHandlerResult, McpToolInput, McpToolMetadata, McpToolOptions, McpToolOutput, ModelArgumentsBase, ModelArgumentsCount, ModelArgumentsCreate, ModelArgumentsDelete, ModelArgumentsFindAll, ModelArgumentsFindOne, ModelArgumentsInclude, ModelArgumentsUpdate, ModelCallbackFindAll, ModelCallbackFindOne, ModelOptions, ModelResultFindAll, RegisterEvents, WorkerCliRequest, WorkerDeclaration, WorkerHandler, WorkerHandlerResult, WorkerMetadata, WorkerRegistered };
|