@design-edito/publisher-core 0.0.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 +265 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5105 -0
- package/dist/index.js.map +7 -0
- package/dist/public/empty.txt +0 -0
- package/dist/types/api/admin/temp/flush/index.d.ts +6 -0
- package/dist/types/api/admin/users/create/index.d.ts +23 -0
- package/dist/types/api/admin/users/delete/index.d.ts +12 -0
- package/dist/types/api/admin/users/get/index.d.ts +18 -0
- package/dist/types/api/admin/users/get-upload-quota/index.d.ts +12 -0
- package/dist/types/api/admin/users/list/index.d.ts +24 -0
- package/dist/types/api/admin/users/reset-upload-quota/index.d.ts +15 -0
- package/dist/types/api/admin/users/revoke-auth-tokens/index.d.ts +10 -0
- package/dist/types/api/admin/users/revoke-email-validation-tokens/index.d.ts +10 -0
- package/dist/types/api/admin/users/revoke-pasword-renewal-tokens/index.d.ts +10 -0
- package/dist/types/api/admin/users/update/index.d.ts +23 -0
- package/dist/types/api/auth/login/index.d.ts +15 -0
- package/dist/types/api/auth/logout/index.d.ts +5 -0
- package/dist/types/api/auth/logout-everywhere/index.d.ts +5 -0
- package/dist/types/api/auth/refresh-token/index.d.ts +5 -0
- package/dist/types/api/auth/request-email-verification-token/index.d.ts +9 -0
- package/dist/types/api/auth/request-new-password/index.d.ts +9 -0
- package/dist/types/api/auth/signup/index.d.ts +13 -0
- package/dist/types/api/auth/submit-new-password/index.d.ts +11 -0
- package/dist/types/api/auth/verify-email/index.d.ts +12 -0
- package/dist/types/api/auth/whoami/index.d.ts +8 -0
- package/dist/types/api/csrf/get-token/index.d.ts +8 -0
- package/dist/types/api/image/format/index.d.ts +28 -0
- package/dist/types/api/image/transform/index.d.ts +11 -0
- package/dist/types/api/index.d.ts +102 -0
- package/dist/types/api/internals.d.ts +270 -0
- package/dist/types/api/system/kill/index.d.ts +3 -0
- package/dist/types/api/system/ping/index.d.ts +6 -0
- package/dist/types/api/system/send-mail/index.d.ts +11 -0
- package/dist/types/api/system/status-check/index.d.ts +22 -0
- package/dist/types/auth/index.d.ts +11 -0
- package/dist/types/csrf/index.d.ts +5 -0
- package/dist/types/database/index.d.ts +69 -0
- package/dist/types/dto/index.d.ts +25 -0
- package/dist/types/email/index.d.ts +6 -0
- package/dist/types/env/index.d.ts +83 -0
- package/dist/types/errors/index.d.ts +295 -0
- package/dist/types/fs/index.d.ts +110 -0
- package/dist/types/index.d.ts +21 -0
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +7 -0
- package/dist/types/init/index.d.ts +1 -0
- package/dist/types/jwt/index.d.ts +7 -0
- package/dist/types/logs/index.d.ts +46 -0
- package/dist/types/plugins/index.d.ts +3 -0
- package/dist/types/plugins/internals.d.ts +177 -0
- package/dist/types/schema/index.d.ts +156 -0
- package/dist/types/temp/index.d.ts +7 -0
- package/dist/types/transformers/index.d.ts +3 -0
- package/dist/types/transformers/user/index.d.ts +5 -0
- package/dist/types/transformers/user-upload-quota/index.d.ts +3 -0
- package/dist/types/uploads/index.d.ts +73 -0
- package/dist/types/validation/index.d.ts +4 -0
- package/package.json +280 -0
@@ -0,0 +1,270 @@
|
|
1
|
+
import type { Request, Response as ExpressResponse } from 'express';
|
2
|
+
import type { ParamsDictionary } from 'express-serve-static-core';
|
3
|
+
import type multer from 'multer';
|
4
|
+
import type { Readable } from 'stream';
|
5
|
+
import type { MessageOf, DetailsOf, Codes, ErrorData, DetailsMaker } from '../errors/index.js';
|
6
|
+
import type { AccessTokenSigned, AccessTokenPayload } from '../jwt/index.js';
|
7
|
+
import type { IUser } from '../schema/index.js';
|
8
|
+
import type { UploadedFile } from '../uploads/index.js';
|
9
|
+
export type WorkerErrorResponse<C extends Codes> = {
|
10
|
+
type: 'error';
|
11
|
+
httpStatus: number;
|
12
|
+
code: C;
|
13
|
+
message: MessageOf<C>;
|
14
|
+
details: DetailsOf<C>;
|
15
|
+
};
|
16
|
+
export type WorkerErrorResponseMaker = <C extends Codes>(httpStatus: number, code: C, ...details: Parameters<DetailsMaker<C>>) => WorkerErrorResponse<C>;
|
17
|
+
export type WorkerVoidResponse = {
|
18
|
+
type: 'void';
|
19
|
+
};
|
20
|
+
export type WorkerVoidResponseMaker = () => WorkerVoidResponse;
|
21
|
+
export type WorkerJsonResponse<P extends object> = {
|
22
|
+
type: 'json';
|
23
|
+
httpStatus: number;
|
24
|
+
payload: P;
|
25
|
+
};
|
26
|
+
export type WorkerJsonResponseMaker = <P extends object>(httpStatus: number, payload: P) => WorkerJsonResponse<P>;
|
27
|
+
export type WorkerListResponse<P extends object> = {
|
28
|
+
type: 'list';
|
29
|
+
httpStatus: number;
|
30
|
+
payload: P[];
|
31
|
+
page: number;
|
32
|
+
total: number;
|
33
|
+
prev: string | null;
|
34
|
+
next: string | null;
|
35
|
+
};
|
36
|
+
export type WorkerListResponseMaker = <P extends object>(httpStatus: number, payload: P[], page: number, total: number, prev: string | null, next: string | null) => WorkerListResponse<P>;
|
37
|
+
export type WorkerFileResponse = {
|
38
|
+
type: 'file';
|
39
|
+
httpStatus: number;
|
40
|
+
filename: string;
|
41
|
+
payload: Readable | Buffer;
|
42
|
+
contentType: string;
|
43
|
+
cacheControl: string;
|
44
|
+
contentLengthBytes: number;
|
45
|
+
};
|
46
|
+
export type WorkerFileResponseMaker = (httpStatus: number, filename: string, payload: Readable | Buffer, contentType: string, cacheControl: string, contentLengthBytes: number) => WorkerFileResponse;
|
47
|
+
export type WorkerHooks<TBody extends unknown = unknown, TQuery extends Request['query'] = Request['query'], TParams extends ParamsDictionary = ParamsDictionary, TFileFields extends string | null = null, TUser extends IUser | null = IUser | null, TAccessTokenSigned extends AccessTokenSigned | undefined = AccessTokenSigned | undefined, TAccessTokenPayload extends AccessTokenPayload | undefined = AccessTokenPayload | undefined> = {
|
48
|
+
body: TBody;
|
49
|
+
query: TQuery;
|
50
|
+
params: TParams;
|
51
|
+
files: TFileFields extends string ? Record<string, UploadedFile[]> : {};
|
52
|
+
headers: Request['headers'];
|
53
|
+
cookies: Request['cookies'];
|
54
|
+
originalUrl: Request['originalUrl'];
|
55
|
+
ip: string | null;
|
56
|
+
accessTokenSigned: TAccessTokenSigned;
|
57
|
+
accessTokenPayload: TAccessTokenPayload;
|
58
|
+
user: TUser;
|
59
|
+
setCookie: ExpressResponse['cookie'];
|
60
|
+
setHeader: ExpressResponse['setHeader'];
|
61
|
+
_unsafeReq: Request;
|
62
|
+
_unsafeRes: ExpressResponse;
|
63
|
+
};
|
64
|
+
export type VoidWorker<TBody extends unknown = unknown, TQuery extends Request['query'] = Request['query'], TParams extends ParamsDictionary = ParamsDictionary, TFileFields extends string | null = null, TUser extends IUser | null = IUser | null, TAccessTokenSigned extends AccessTokenSigned | undefined = AccessTokenSigned | undefined, TAccessTokenPayload extends AccessTokenPayload | undefined = AccessTokenPayload | undefined, TErrCodes extends Codes = Codes> = (hooks: WorkerHooks<TBody, TQuery, TParams, TFileFields, TUser, TAccessTokenSigned, TAccessTokenPayload>) => Promise<WorkerVoidResponse | WorkerErrorResponse<TErrCodes>>;
|
65
|
+
export type JsonWorker<TBody extends unknown = unknown, TQuery extends Request['query'] = Request['query'], TParams extends ParamsDictionary = ParamsDictionary, TFileFields extends string | null = null, TUser extends IUser | null = IUser | null, TAccessTokenSigned extends AccessTokenSigned | undefined = AccessTokenSigned | undefined, TAccessTokenPayload extends AccessTokenPayload | undefined = AccessTokenPayload | undefined, TErrCodes extends Codes = Codes, TSuccessPayload extends object = object> = (hooks: WorkerHooks<TBody, TQuery, TParams, TFileFields, TUser, TAccessTokenSigned, TAccessTokenPayload>) => Promise<WorkerJsonResponse<TSuccessPayload> | WorkerErrorResponse<TErrCodes>>;
|
66
|
+
export type ListWorker<TBody extends unknown = unknown, TQuery extends Request['query'] = Request['query'], TParams extends ParamsDictionary = ParamsDictionary, TFileFields extends string | null = null, TUser extends IUser | null = IUser | null, TAccessTokenSigned extends AccessTokenSigned | undefined = AccessTokenSigned | undefined, TAccessTokenPayload extends AccessTokenPayload | undefined = AccessTokenPayload | undefined, TErrCodes extends Codes = Codes, TSuccessPayload extends object = object> = (hooks: WorkerHooks<TBody, TQuery, TParams, TFileFields, TUser, TAccessTokenSigned, TAccessTokenPayload>) => Promise<WorkerListResponse<TSuccessPayload> | WorkerErrorResponse<TErrCodes>>;
|
67
|
+
export type FileWorker<TBody extends unknown = unknown, TQuery extends Request['query'] = Request['query'], TParams extends ParamsDictionary = ParamsDictionary, TFileFields extends string | null = null, TUser extends IUser | null = IUser | null, TAccessTokenSigned extends AccessTokenSigned | undefined = AccessTokenSigned | undefined, TAccessTokenPayload extends AccessTokenPayload | undefined = AccessTokenPayload | undefined, TErrCodes extends Codes = Codes> = (hooks: WorkerHooks<TBody, TQuery, TParams, TFileFields, TUser, TAccessTokenSigned, TAccessTokenPayload>) => Promise<WorkerFileResponse | WorkerErrorResponse<TErrCodes>>;
|
68
|
+
export type AuthenticatorAllowedErrorCodes = Codes.USER_DOES_NOT_EXIST | Codes.USER_NOT_AUTHENTICATED | Codes.USER_NOT_AUTHORIZED;
|
69
|
+
export type WeakAuthenticatorPayload = {
|
70
|
+
accessTokenSigned: AccessTokenSigned;
|
71
|
+
accessTokenPayload: AccessTokenPayload;
|
72
|
+
};
|
73
|
+
export type StrongAuthenticatorPayload = {
|
74
|
+
user: IUser;
|
75
|
+
accessTokenSigned: AccessTokenSigned;
|
76
|
+
accessTokenPayload: AccessTokenPayload;
|
77
|
+
};
|
78
|
+
export type WeakAuthenticator<TErrCodes extends AuthenticatorAllowedErrorCodes = AuthenticatorAllowedErrorCodes> = JsonWorker<unknown, Request['query'], ParamsDictionary, null, null, AccessTokenSigned, AccessTokenPayload, TErrCodes, WeakAuthenticatorPayload>;
|
79
|
+
export type StrongAuthenticator<TErrCodes extends AuthenticatorAllowedErrorCodes = AuthenticatorAllowedErrorCodes> = JsonWorker<unknown, Request['query'], ParamsDictionary, null, IUser, AccessTokenSigned, AccessTokenPayload, TErrCodes, StrongAuthenticatorPayload>;
|
80
|
+
export type ValidatorAllowedErrorCodes = Codes.INVALID_REQUEST_BODY | Codes.INVALID_REQUEST_QUERY | Codes.INVALID_REQUEST_FILES;
|
81
|
+
export type ValidatorSuccessPayload<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary> = {
|
82
|
+
body: TExpectedBody;
|
83
|
+
query: TExpectedQuery;
|
84
|
+
params: TExpectedParams;
|
85
|
+
};
|
86
|
+
export type NoAuthValidator<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TErrCodes extends ValidatorAllowedErrorCodes = ValidatorAllowedErrorCodes> = JsonWorker<unknown, Request['query'], ParamsDictionary, TExpectedFileFields, null, undefined, undefined, TErrCodes, ValidatorSuccessPayload<TExpectedBody, TExpectedQuery, TExpectedParams>>;
|
87
|
+
export type WeakAuthValidator<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TErrCodes extends ValidatorAllowedErrorCodes = ValidatorAllowedErrorCodes> = JsonWorker<unknown, Request['query'], ParamsDictionary, TExpectedFileFields, null, AccessTokenSigned, AccessTokenPayload, TErrCodes, ValidatorSuccessPayload<TExpectedBody, TExpectedQuery, TExpectedParams>>;
|
88
|
+
export type StrongAuthValidator<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TErrCodes extends ValidatorAllowedErrorCodes = ValidatorAllowedErrorCodes> = JsonWorker<unknown, Request['query'], ParamsDictionary, TExpectedFileFields, IUser, AccessTokenSigned, AccessTokenPayload, TErrCodes, ValidatorSuccessPayload<TExpectedBody, TExpectedQuery, TExpectedParams>>;
|
89
|
+
export type NoAuthVoidOperator<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TErrCodes extends Codes = Codes> = VoidWorker<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, null, undefined, undefined, TErrCodes>;
|
90
|
+
export type WeakAuthVoidOperator<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TErrCodes extends Codes = Codes> = VoidWorker<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, null, AccessTokenSigned, AccessTokenPayload, TErrCodes>;
|
91
|
+
export type StrongAuthVoidOperator<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TErrCodes extends Codes = Codes> = VoidWorker<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, IUser, AccessTokenSigned, AccessTokenPayload, TErrCodes>;
|
92
|
+
export type NoAuthJsonOperator<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TErrCodes extends Codes = Codes, TSuccessPayload extends object = object> = JsonWorker<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, null, undefined, undefined, TErrCodes, TSuccessPayload>;
|
93
|
+
export type WeakAuthJsonOperator<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TErrCodes extends Codes = Codes, TSuccessPayload extends object = object> = JsonWorker<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, null, AccessTokenSigned, AccessTokenPayload, TErrCodes, TSuccessPayload>;
|
94
|
+
export type StrongAuthJsonOperator<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TErrCodes extends Codes = Codes, TSuccessPayload extends object = object> = JsonWorker<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, IUser, AccessTokenSigned, AccessTokenPayload, TErrCodes, TSuccessPayload>;
|
95
|
+
export type NoAuthListOperator<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TErrCodes extends Codes = Codes, TSuccessPayload extends object = object> = ListWorker<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, null, undefined, undefined, TErrCodes, TSuccessPayload>;
|
96
|
+
export type WeakAuthListOperator<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TErrCodes extends Codes = Codes, TSuccessPayload extends object = object> = ListWorker<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, null, AccessTokenSigned, AccessTokenPayload, TErrCodes, TSuccessPayload>;
|
97
|
+
export type StrongAuthListOperator<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TErrCodes extends Codes = Codes, TSuccessPayload extends object = object> = ListWorker<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, IUser, AccessTokenSigned, AccessTokenPayload, TErrCodes, TSuccessPayload>;
|
98
|
+
export type NoAuthFileOperator<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TErrCodes extends Codes = Codes> = FileWorker<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, null, undefined, undefined, TErrCodes>;
|
99
|
+
export type WeakAuthFileOperator<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TErrCodes extends Codes = Codes> = FileWorker<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, null, AccessTokenSigned, AccessTokenPayload, TErrCodes>;
|
100
|
+
export type StrongAuthFileOperator<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TErrCodes extends Codes = Codes> = FileWorker<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, IUser, AccessTokenSigned, AccessTokenPayload, TErrCodes>;
|
101
|
+
export type UploadsDescriptor<TExpectedFileFields extends string = string> = {
|
102
|
+
fields: Array<{
|
103
|
+
name: TExpectedFileFields;
|
104
|
+
maxCount?: number;
|
105
|
+
}>;
|
106
|
+
limits?: multer.Options['limits'];
|
107
|
+
filter?: multer.Options['fileFilter'];
|
108
|
+
incrementQuotas?: boolean;
|
109
|
+
};
|
110
|
+
export type UploadsProcessorErrCodes = Codes.FILE_TOO_LARGE | Codes.INVALID_REQUEST_FILES | Codes.USER_NOT_AUTHENTICATED | Codes.USER_UPLOAD_QUOTA_EXCEEDED | Codes.FILE_INFECTED | Codes.FILE_HASH_FAILED | Codes.FILE_SCANNER_NOT_REACHABLE;
|
111
|
+
export type NoAuthVoidProcessContract<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TValidationErrCodes extends ValidatorAllowedErrorCodes = ValidatorAllowedErrorCodes, TOperationErrCodes extends Codes = Codes> = {
|
112
|
+
_authType: 'none';
|
113
|
+
_opType: 'void';
|
114
|
+
uploads?: TExpectedFileFields extends string ? UploadsDescriptor<TExpectedFileFields> : undefined;
|
115
|
+
skipCsrfProtection?: boolean;
|
116
|
+
validation: NoAuthValidator<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TValidationErrCodes>;
|
117
|
+
operation: NoAuthVoidOperator<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TOperationErrCodes>;
|
118
|
+
};
|
119
|
+
export type WeakAuthVoidProcessContract<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TAuthErrCodes extends AuthenticatorAllowedErrorCodes = AuthenticatorAllowedErrorCodes, TValidationErrCodes extends ValidatorAllowedErrorCodes = ValidatorAllowedErrorCodes, TOperationErrCodes extends Codes = Codes> = {
|
120
|
+
_authType: 'weak';
|
121
|
+
_opType: 'void';
|
122
|
+
uploads?: TExpectedFileFields extends string ? UploadsDescriptor<TExpectedFileFields> : undefined;
|
123
|
+
skipCsrfProtection?: boolean;
|
124
|
+
authentication: WeakAuthenticator<TAuthErrCodes>;
|
125
|
+
validation: WeakAuthValidator<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TValidationErrCodes>;
|
126
|
+
operation: WeakAuthVoidOperator<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TOperationErrCodes>;
|
127
|
+
};
|
128
|
+
export type StrongAuthVoidProcessContract<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TAuthErrCodes extends AuthenticatorAllowedErrorCodes = AuthenticatorAllowedErrorCodes, TValidationErrCodes extends ValidatorAllowedErrorCodes = ValidatorAllowedErrorCodes, TOperationErrCodes extends Codes = Codes> = {
|
129
|
+
_authType: 'strong';
|
130
|
+
_opType: 'void';
|
131
|
+
uploads?: TExpectedFileFields extends string ? UploadsDescriptor<TExpectedFileFields> : undefined;
|
132
|
+
skipCsrfProtection?: boolean;
|
133
|
+
authentication: StrongAuthenticator<TAuthErrCodes>;
|
134
|
+
validation: StrongAuthValidator<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TValidationErrCodes>;
|
135
|
+
operation: StrongAuthVoidOperator<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TOperationErrCodes>;
|
136
|
+
};
|
137
|
+
export type NoAuthJsonProcessContract<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TValidationErrCodes extends ValidatorAllowedErrorCodes = ValidatorAllowedErrorCodes, TOperationErrCodes extends Codes = Codes, TOperationPayload extends object = object> = {
|
138
|
+
_authType: 'none';
|
139
|
+
_opType: 'json';
|
140
|
+
uploads?: TExpectedFileFields extends string ? UploadsDescriptor<TExpectedFileFields> : undefined;
|
141
|
+
skipCsrfProtection?: boolean;
|
142
|
+
validation: NoAuthValidator<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TValidationErrCodes>;
|
143
|
+
operation: NoAuthJsonOperator<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TOperationErrCodes, TOperationPayload>;
|
144
|
+
};
|
145
|
+
export type WeakAuthJsonProcessContract<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TAuthErrCodes extends AuthenticatorAllowedErrorCodes = AuthenticatorAllowedErrorCodes, TValidationErrCodes extends ValidatorAllowedErrorCodes = ValidatorAllowedErrorCodes, TOperationErrCodes extends Codes = Codes, TOperationPayload extends object = object> = {
|
146
|
+
_authType: 'weak';
|
147
|
+
_opType: 'json';
|
148
|
+
uploads?: TExpectedFileFields extends string ? UploadsDescriptor<TExpectedFileFields> : undefined;
|
149
|
+
skipCsrfProtection?: boolean;
|
150
|
+
authentication: WeakAuthenticator<TAuthErrCodes>;
|
151
|
+
validation: WeakAuthValidator<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TValidationErrCodes>;
|
152
|
+
operation: WeakAuthJsonOperator<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TOperationErrCodes, TOperationPayload>;
|
153
|
+
};
|
154
|
+
export type StrongAuthJsonProcessContract<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TAuthErrCodes extends AuthenticatorAllowedErrorCodes = AuthenticatorAllowedErrorCodes, TValidationErrCodes extends ValidatorAllowedErrorCodes = ValidatorAllowedErrorCodes, TOperationErrCodes extends Codes = Codes, TOperationPayload extends object = object> = {
|
155
|
+
_authType: 'strong';
|
156
|
+
_opType: 'json';
|
157
|
+
uploads?: TExpectedFileFields extends string ? UploadsDescriptor<TExpectedFileFields> : undefined;
|
158
|
+
skipCsrfProtection?: boolean;
|
159
|
+
authentication: StrongAuthenticator<TAuthErrCodes>;
|
160
|
+
validation: StrongAuthValidator<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TValidationErrCodes>;
|
161
|
+
operation: StrongAuthJsonOperator<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TOperationErrCodes, TOperationPayload>;
|
162
|
+
};
|
163
|
+
export type NoAuthListProcessContract<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TValidationErrCodes extends ValidatorAllowedErrorCodes = ValidatorAllowedErrorCodes, TOperationErrCodes extends Codes = Codes, TOperationPayload extends object = object> = {
|
164
|
+
_authType: 'none';
|
165
|
+
_opType: 'list';
|
166
|
+
uploads?: TExpectedFileFields extends string ? UploadsDescriptor<TExpectedFileFields> : undefined;
|
167
|
+
skipCsrfProtection?: boolean;
|
168
|
+
validation: NoAuthValidator<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TValidationErrCodes>;
|
169
|
+
operation: NoAuthListOperator<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TOperationErrCodes, TOperationPayload>;
|
170
|
+
};
|
171
|
+
export type WeakAuthListProcessContract<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TAuthErrCodes extends AuthenticatorAllowedErrorCodes = AuthenticatorAllowedErrorCodes, TValidationErrCodes extends ValidatorAllowedErrorCodes = ValidatorAllowedErrorCodes, TOperationErrCodes extends Codes = Codes, TOperationPayload extends object = object> = {
|
172
|
+
_authType: 'weak';
|
173
|
+
_opType: 'list';
|
174
|
+
uploads?: TExpectedFileFields extends string ? UploadsDescriptor<TExpectedFileFields> : undefined;
|
175
|
+
skipCsrfProtection?: boolean;
|
176
|
+
authentication: WeakAuthenticator<TAuthErrCodes>;
|
177
|
+
validation: WeakAuthValidator<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TValidationErrCodes>;
|
178
|
+
operation: WeakAuthListOperator<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TOperationErrCodes, TOperationPayload>;
|
179
|
+
};
|
180
|
+
export type StrongAuthListProcessContract<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TAuthErrCodes extends AuthenticatorAllowedErrorCodes = AuthenticatorAllowedErrorCodes, TValidationErrCodes extends ValidatorAllowedErrorCodes = ValidatorAllowedErrorCodes, TOperationErrCodes extends Codes = Codes, TOperationPayload extends object = object> = {
|
181
|
+
_authType: 'strong';
|
182
|
+
_opType: 'list';
|
183
|
+
uploads?: TExpectedFileFields extends string ? UploadsDescriptor<TExpectedFileFields> : undefined;
|
184
|
+
skipCsrfProtection?: boolean;
|
185
|
+
authentication: StrongAuthenticator<TAuthErrCodes>;
|
186
|
+
validation: StrongAuthValidator<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TValidationErrCodes>;
|
187
|
+
operation: StrongAuthListOperator<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TOperationErrCodes, TOperationPayload>;
|
188
|
+
};
|
189
|
+
export type NoAuthFileProcessContract<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TValidationErrCodes extends ValidatorAllowedErrorCodes = ValidatorAllowedErrorCodes, TOperationErrCodes extends Codes = Codes> = {
|
190
|
+
_authType: 'none';
|
191
|
+
_opType: 'file';
|
192
|
+
uploads?: TExpectedFileFields extends string ? UploadsDescriptor<TExpectedFileFields> : undefined;
|
193
|
+
skipCsrfProtection?: boolean;
|
194
|
+
validation: NoAuthValidator<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TValidationErrCodes>;
|
195
|
+
operation: NoAuthFileOperator<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TOperationErrCodes>;
|
196
|
+
};
|
197
|
+
export type WeakAuthFileProcessContract<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TAuthErrCodes extends AuthenticatorAllowedErrorCodes = AuthenticatorAllowedErrorCodes, TValidationErrCodes extends ValidatorAllowedErrorCodes = ValidatorAllowedErrorCodes, TOperationErrCodes extends Codes = Codes> = {
|
198
|
+
_authType: 'weak';
|
199
|
+
_opType: 'file';
|
200
|
+
uploads?: TExpectedFileFields extends string ? UploadsDescriptor<TExpectedFileFields> : undefined;
|
201
|
+
skipCsrfProtection?: boolean;
|
202
|
+
authentication: WeakAuthenticator<TAuthErrCodes>;
|
203
|
+
validation: WeakAuthValidator<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TValidationErrCodes>;
|
204
|
+
operation: WeakAuthFileOperator<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TOperationErrCodes>;
|
205
|
+
};
|
206
|
+
export type StrongAuthFileProcessContract<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TAuthErrCodes extends AuthenticatorAllowedErrorCodes = AuthenticatorAllowedErrorCodes, TValidationErrCodes extends ValidatorAllowedErrorCodes = ValidatorAllowedErrorCodes, TOperationErrCodes extends Codes = Codes> = {
|
207
|
+
_authType: 'strong';
|
208
|
+
_opType: 'file';
|
209
|
+
uploads?: TExpectedFileFields extends string ? UploadsDescriptor<TExpectedFileFields> : undefined;
|
210
|
+
skipCsrfProtection?: boolean;
|
211
|
+
authentication: StrongAuthenticator<TAuthErrCodes>;
|
212
|
+
validation: StrongAuthValidator<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TValidationErrCodes>;
|
213
|
+
operation: StrongAuthFileOperator<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TOperationErrCodes>;
|
214
|
+
};
|
215
|
+
export type NoAuthProcessContract<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TValidationErrCodes extends ValidatorAllowedErrorCodes = ValidatorAllowedErrorCodes, TOperationErrCodes extends Codes = Codes, TOperationPayload extends object = object> = NoAuthVoidProcessContract<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TValidationErrCodes, TOperationErrCodes> | NoAuthJsonProcessContract<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TValidationErrCodes, TOperationErrCodes, TOperationPayload> | NoAuthListProcessContract<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TValidationErrCodes, TOperationErrCodes, TOperationPayload> | NoAuthFileProcessContract<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TValidationErrCodes, TOperationErrCodes>;
|
216
|
+
export type WeakAuthProcessContract<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TAuthErrCodes extends AuthenticatorAllowedErrorCodes = AuthenticatorAllowedErrorCodes, TValidationErrCodes extends ValidatorAllowedErrorCodes = ValidatorAllowedErrorCodes, TOperationErrCodes extends Codes = Codes, TOperationPayload extends object = object> = WeakAuthVoidProcessContract<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TAuthErrCodes, TValidationErrCodes, TOperationErrCodes> | WeakAuthJsonProcessContract<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TAuthErrCodes, TValidationErrCodes, TOperationErrCodes, TOperationPayload> | WeakAuthListProcessContract<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TAuthErrCodes, TValidationErrCodes, TOperationErrCodes, TOperationPayload> | WeakAuthFileProcessContract<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TAuthErrCodes, TValidationErrCodes, TOperationErrCodes>;
|
217
|
+
export type StrongAuthProcessContract<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TAuthErrCodes extends AuthenticatorAllowedErrorCodes = AuthenticatorAllowedErrorCodes, TValidationErrCodes extends ValidatorAllowedErrorCodes = ValidatorAllowedErrorCodes, TOperationErrCodes extends Codes = Codes, TOperationPayload extends object = object> = StrongAuthVoidProcessContract<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TAuthErrCodes, TValidationErrCodes, TOperationErrCodes> | StrongAuthJsonProcessContract<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TAuthErrCodes, TValidationErrCodes, TOperationErrCodes, TOperationPayload> | StrongAuthListProcessContract<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TAuthErrCodes, TValidationErrCodes, TOperationErrCodes, TOperationPayload> | StrongAuthFileProcessContract<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TAuthErrCodes, TValidationErrCodes, TOperationErrCodes>;
|
218
|
+
export type ProcessContract<TExpectedBody extends unknown = unknown, TExpectedQuery extends Request['query'] = Request['query'], TExpectedParams extends ParamsDictionary = ParamsDictionary, TExpectedFileFields extends string | null = null, TAuthErrCodes extends AuthenticatorAllowedErrorCodes = AuthenticatorAllowedErrorCodes, TValidationErrCodes extends ValidatorAllowedErrorCodes = ValidatorAllowedErrorCodes, TOperationErrCodes extends Codes = Codes, TOperationPayload extends object = object> = NoAuthProcessContract<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TValidationErrCodes, TOperationErrCodes, TOperationPayload> | WeakAuthProcessContract<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TAuthErrCodes, TValidationErrCodes, TOperationErrCodes, TOperationPayload> | StrongAuthProcessContract<TExpectedBody, TExpectedQuery, TExpectedParams, TExpectedFileFields, TAuthErrCodes, TValidationErrCodes, TOperationErrCodes, TOperationPayload>;
|
219
|
+
export type InitServerResponseMeta = {
|
220
|
+
ip: string | null;
|
221
|
+
userId: string | null;
|
222
|
+
requestId: string;
|
223
|
+
startHrTimeNs: bigint;
|
224
|
+
timestampMs: number;
|
225
|
+
};
|
226
|
+
export type ServerResponseMeta = Omit<InitServerResponseMeta, 'startHrTimeNs'> & {
|
227
|
+
elapsedMs: number;
|
228
|
+
};
|
229
|
+
export type ServerErrorResponse<C extends Codes> = {
|
230
|
+
success: false;
|
231
|
+
httpStatus: number;
|
232
|
+
type: 'error';
|
233
|
+
error: ErrorData<C>;
|
234
|
+
meta: ServerResponseMeta;
|
235
|
+
};
|
236
|
+
export type ServerJsonResponse<P extends object> = {
|
237
|
+
success: true;
|
238
|
+
httpStatus: number;
|
239
|
+
type: 'json';
|
240
|
+
payload: P;
|
241
|
+
meta: ServerResponseMeta;
|
242
|
+
};
|
243
|
+
export type ServerListResponse<P extends object> = {
|
244
|
+
success: true;
|
245
|
+
httpStatus: number;
|
246
|
+
type: 'list';
|
247
|
+
payload: P[];
|
248
|
+
page: number;
|
249
|
+
total: number;
|
250
|
+
prev: string | null;
|
251
|
+
next: string | null;
|
252
|
+
meta: ServerResponseMeta;
|
253
|
+
};
|
254
|
+
export type WeakAuthenticatorPayloadGetterErrCodes = Codes.USER_NOT_AUTHENTICATED;
|
255
|
+
export type StrongAuthenticatorPayloadGetterErrCodes = Codes.USER_NOT_AUTHENTICATED | Codes.USER_DOES_NOT_EXIST;
|
256
|
+
export type WeakAuthenticatorPayloadGetterResponse = WorkerErrorResponse<WeakAuthenticatorPayloadGetterErrCodes> | WorkerJsonResponse<WeakAuthenticatorPayload>;
|
257
|
+
export type StrongAuthenticatorPayloadGetterResponse = WorkerErrorResponse<StrongAuthenticatorPayloadGetterErrCodes> | WorkerJsonResponse<StrongAuthenticatorPayload>;
|
258
|
+
export type ExtractExpectedBody<P extends ProcessContract<any, any, any, any, any, any, any, any>> = P extends ProcessContract<infer B, any, any, any, any, any, any, any> ? B : never;
|
259
|
+
export type ExtractExpectedQuery<P extends ProcessContract<any, any, any, any, any, any, any, any>> = P extends ProcessContract<any, infer Q, any, any, any, any, any, any> ? Q : never;
|
260
|
+
export type ExtractExpectedParams<P extends ProcessContract<any, any, any, any, any, any, any, any>> = P extends ProcessContract<any, any, infer PA, any, any, any, any, any> ? PA : never;
|
261
|
+
export type ExtractExpectedFileFields<P extends ProcessContract<any, any, any, any, any, any, any, any>> = P extends ProcessContract<any, any, any, infer F, any, any, any, any> ? F : null;
|
262
|
+
export type ExtractUploadsErrCodes<P extends ProcessContract<any, any, any, any, any, any, any, any>> = P['uploads'] extends undefined ? never : UploadsProcessorErrCodes;
|
263
|
+
export type ExtractCsrfErrCodes<P extends ProcessContract<any, any, any, any, any, any, any, any>> = P['skipCsrfProtection'] extends true ? never : Codes.INVALID_CSRF_TOKEN;
|
264
|
+
export type ExtractAuthErrCodes<P extends ProcessContract<any, any, any, any, any, any, any, any>> = P extends WeakAuthProcessContract<any, any, any, any, infer C, any, any, any> ? C | WeakAuthenticatorPayloadGetterErrCodes : P extends StrongAuthProcessContract<any, any, any, any, infer C, any, any, any> ? C | StrongAuthenticatorPayloadGetterErrCodes : never;
|
265
|
+
export type ExtractValidationErrCodes<P extends ProcessContract<any, any, any, any, any, any, any, any>> = P extends ProcessContract<any, any, any, any, any, infer C, any, any> ? C : never;
|
266
|
+
export type ExtractOperationErrCodes<P extends ProcessContract<any, any, any, any, any, any, any, any>> = P extends ProcessContract<any, any, any, any, any, any, infer C, any> ? C : never;
|
267
|
+
export type ExtractOperationPayload<P extends ProcessContract<any, any, any, any, any, any, any, any>> = P extends ProcessContract<any, any, any, any, any, any, any, infer OP> ? OP : never;
|
268
|
+
export type InferServerErrorResponse<P extends ProcessContract<any, any, any, any, any, any, any, any>> = P extends ProcessContract<any, any, any, any, any, any, any, any> ? ServerErrorResponse<ExtractCsrfErrCodes<P> | ExtractUploadsErrCodes<P> | ExtractAuthErrCodes<P> | ExtractValidationErrCodes<P> | ExtractOperationErrCodes<P>> : never;
|
269
|
+
export type InferServerSuccessResponse<P extends ProcessContract<any, any, any, any, any, any, any, any>> = P extends NoAuthJsonProcessContract<any, any, any, any, any, any, infer Payload> | WeakAuthJsonProcessContract<any, any, any, any, any, any, any, infer Payload> | StrongAuthJsonProcessContract<any, any, any, any, any, any, any, infer Payload> ? ServerJsonResponse<Payload> : P extends NoAuthListProcessContract<any, any, any, any, any, any, infer Payload> | WeakAuthListProcessContract<any, any, any, any, any, any, any, infer Payload> | StrongAuthListProcessContract<any, any, any, any, any, any, any, infer Payload> ? ServerListResponse<Payload> : never;
|
270
|
+
export type InferServerResponse<P extends ProcessContract<any, any, any, any, any, any, any, any>> = InferServerErrorResponse<P> | InferServerSuccessResponse<P>;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { AllowerErrCodes } from '../../../auth/index.js';
|
2
|
+
import { Codes } from '../../../errors/index.js';
|
3
|
+
import type { StrongAuthVoidProcessContract } from '../../internals.js';
|
4
|
+
type ExpectedQuery = {
|
5
|
+
to: string;
|
6
|
+
subject: string;
|
7
|
+
text: string;
|
8
|
+
};
|
9
|
+
type ValidationErrCodes = Codes.INVALID_REQUEST_QUERY;
|
10
|
+
export type SystemSendMailProcessContract = StrongAuthVoidProcessContract<{}, ExpectedQuery, {}, null, AllowerErrCodes, ValidationErrCodes, never>;
|
11
|
+
export {};
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import type { NoAuthJsonProcessContract } from '../../internals.js';
|
2
|
+
type SuccessPayload = {
|
3
|
+
isHealthy: boolean;
|
4
|
+
builtOn: string;
|
5
|
+
aliveSince: string;
|
6
|
+
uptimeSeconds: number;
|
7
|
+
database: {
|
8
|
+
connected: boolean;
|
9
|
+
pingMs: number | null;
|
10
|
+
};
|
11
|
+
fs: {
|
12
|
+
type: 'gcs' | 'aws' | 'ftps' | 'sftp';
|
13
|
+
connected: boolean;
|
14
|
+
pingMs: number | null;
|
15
|
+
};
|
16
|
+
clamav: {
|
17
|
+
connected: boolean;
|
18
|
+
pingMs: number | null;
|
19
|
+
};
|
20
|
+
};
|
21
|
+
export type SystemStatusCheckProcessContract = NoAuthJsonProcessContract<{}, {}, {}, null, never, never, SuccessPayload>;
|
22
|
+
export {};
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import type { UserRole, UserStatus, UserBadge } from '../schema/index.js';
|
2
|
+
import type { Codes } from '../errors/index.js';
|
3
|
+
import { StrongAuthenticator } from '../api/internals.js';
|
4
|
+
export type AllowerOptions = {
|
5
|
+
roles?: UserRole[];
|
6
|
+
statuses?: UserStatus[];
|
7
|
+
badges?: UserBadge[];
|
8
|
+
verified?: boolean;
|
9
|
+
};
|
10
|
+
export type AllowerErrCodes = Codes.USER_DOES_NOT_EXIST | Codes.USER_NOT_AUTHENTICATED | Codes.USER_NOT_AUTHORIZED;
|
11
|
+
export type Allower = (options: AllowerOptions) => StrongAuthenticator<AllowerErrCodes>;
|
@@ -0,0 +1,69 @@
|
|
1
|
+
import type { Query as MongooseQuery, Types as MongooseTypes, Document as MongooseDocument, Model as MongooseModel, FilterQuery as MongooseFilterQuery, SortOrder as MongooseSortOrder, RootFilterQuery as MongooseRootFilterQuery, UpdateQuery as MongooseUpdateQuery } from 'mongoose';
|
2
|
+
import type { Outcome } from '@design-edito/tools/agnostic/misc/outcome/index.js';
|
3
|
+
import type { WithId } from '../schema/index.js';
|
4
|
+
import type { ErrorData, Codes } from '../errors/index.js';
|
5
|
+
export type OperationContext = {
|
6
|
+
initiatorId: string | null;
|
7
|
+
};
|
8
|
+
export interface DocumentWithLocals<T> extends MongooseDocument<MongooseTypes.ObjectId, any, T> {
|
9
|
+
$locals: {
|
10
|
+
context?: OperationContext;
|
11
|
+
};
|
12
|
+
}
|
13
|
+
export interface QueryWithLocals<T, R = T | null> extends MongooseQuery<T, R> {
|
14
|
+
getOptions(): {
|
15
|
+
$locals?: {
|
16
|
+
context?: OperationContext;
|
17
|
+
};
|
18
|
+
};
|
19
|
+
}
|
20
|
+
export type POJOInput<T> = {
|
21
|
+
[K in keyof T]: T[K] extends MongooseTypes.DocumentArray<infer U> ? U[] : T[K];
|
22
|
+
};
|
23
|
+
export type PartialPOJOInput<T> = Partial<{
|
24
|
+
[K in keyof T]: T[K] extends MongooseTypes.DocumentArray<infer U> ? U[] : T[K];
|
25
|
+
}>;
|
26
|
+
export interface InsertOne {
|
27
|
+
<T extends WithId<{}>>(model: MongooseModel<T>, data: PartialPOJOInput<T>, context: OperationContext): Promise<Outcome.Either<T, ErrorData<Codes.DB_ERROR>>>;
|
28
|
+
}
|
29
|
+
export interface InsertMany {
|
30
|
+
<T extends WithId<{}>>(model: MongooseModel<T>, data: PartialPOJOInput<T>[], context: OperationContext): Promise<Outcome.Either<{
|
31
|
+
inserted: T[];
|
32
|
+
insertedCount: number;
|
33
|
+
}, ErrorData<Codes.DB_ERROR>>>;
|
34
|
+
}
|
35
|
+
export interface FindOne {
|
36
|
+
<T extends WithId<{}>>(model: MongooseModel<T>, filter: MongooseFilterQuery<T>, context: OperationContext): Promise<Outcome.Either<T, ErrorData<Codes.DB_NO_DOCUMENT_MATCHES_FILTER> | ErrorData<Codes.DB_ERROR>>>;
|
37
|
+
}
|
38
|
+
export type FindManyOptions<T> = {
|
39
|
+
limit?: number;
|
40
|
+
skip?: number;
|
41
|
+
sort?: Partial<Record<keyof T, MongooseSortOrder>>;
|
42
|
+
};
|
43
|
+
export type FindManyFailure = ErrorData<Codes.DB_NO_DOCUMENT_MATCHES_FILTER> | ErrorData<Codes.DB_ERROR>;
|
44
|
+
export type FindManySuccess<T> = {
|
45
|
+
found: T[];
|
46
|
+
foundCount: number;
|
47
|
+
totalCount: number;
|
48
|
+
next: null | (() => Promise<Outcome.Either<FindManySuccess<T>, FindManyFailure>>);
|
49
|
+
prev: null | (() => Promise<Outcome.Either<FindManySuccess<T>, FindManyFailure>>);
|
50
|
+
};
|
51
|
+
export interface FindMany {
|
52
|
+
<T extends WithId<{}>>(model: MongooseModel<T>, filter: MongooseFilterQuery<T>, context: OperationContext, options?: FindManyOptions<T>): Promise<Outcome.Either<FindManySuccess<T>, FindManyFailure>>;
|
53
|
+
}
|
54
|
+
export interface UpdateOne {
|
55
|
+
<T extends WithId<{}>>(model: MongooseModel<T>, filter: MongooseRootFilterQuery<T>, update: MongooseUpdateQuery<T>, context: OperationContext): Promise<Outcome.Either<T, ErrorData<Codes.DB_NO_DOCUMENT_MATCHES_FILTER> | ErrorData<Codes.DB_ERROR>>>;
|
56
|
+
}
|
57
|
+
export interface UpdateMany {
|
58
|
+
<T extends WithId<{}>>(model: MongooseModel<T>, filter: MongooseRootFilterQuery<T>, update: MongooseUpdateQuery<T>, context: OperationContext): Promise<Outcome.Either<{
|
59
|
+
updatedCount: number;
|
60
|
+
}, ErrorData<Codes.DB_NO_DOCUMENT_MATCHES_FILTER> | ErrorData<Codes.DB_ERROR>>>;
|
61
|
+
}
|
62
|
+
export interface DeleteOne {
|
63
|
+
<T extends WithId<{}>>(model: MongooseModel<T>, filter: MongooseRootFilterQuery<T>, context: OperationContext): Promise<Outcome.Either<T, ErrorData<Codes.DB_NO_DOCUMENT_MATCHES_FILTER> | ErrorData<Codes.DB_ERROR>>>;
|
64
|
+
}
|
65
|
+
export interface DeleteMany {
|
66
|
+
<T extends WithId<{}>>(model: MongooseModel<T>, filter: MongooseRootFilterQuery<T>, context: OperationContext): Promise<Outcome.Either<{
|
67
|
+
deletedCount: number;
|
68
|
+
}, ErrorData<Codes.DB_NO_DOCUMENT_MATCHES_FILTER> | ErrorData<Codes.DB_ERROR>>>;
|
69
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import type { UserRole, UserStatus, UserBadge } from '../schema/index.js';
|
2
|
+
type WithIdDTO<T> = T & {
|
3
|
+
_id: string;
|
4
|
+
};
|
5
|
+
export type UserUploadQuotaDTO = {
|
6
|
+
userId: string;
|
7
|
+
dailyUploadsByteSize: number;
|
8
|
+
monthlyUploadsByteSize: number;
|
9
|
+
totalUploadsByteSize: number;
|
10
|
+
};
|
11
|
+
export type BaseUserDTO = WithIdDTO<{
|
12
|
+
username: string;
|
13
|
+
role: UserRole;
|
14
|
+
status: UserStatus;
|
15
|
+
badges: UserBadge[];
|
16
|
+
}>;
|
17
|
+
export type LocalUserDTO = BaseUserDTO & {
|
18
|
+
email: string;
|
19
|
+
verified: boolean;
|
20
|
+
};
|
21
|
+
export type GoogleUserDTO = BaseUserDTO & {
|
22
|
+
googleId: string;
|
23
|
+
verified: true;
|
24
|
+
};
|
25
|
+
export {};
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import type { Outcome } from '@design-edito/tools/agnostic/misc/outcome/index.js';
|
2
|
+
import type { APIResponse } from 'mailersend/lib/services/request.service.js';
|
3
|
+
import type { SentMessageInfo } from 'nodemailer';
|
4
|
+
export interface Send {
|
5
|
+
(from: string, fromName: string, to: string, toName: string, subject: string, htmlBody: string): Promise<Outcome.Either<APIResponse | SentMessageInfo, string>>;
|
6
|
+
}
|
@@ -0,0 +1,83 @@
|
|
1
|
+
export type Env = {
|
2
|
+
APP_LABEL?: string;
|
3
|
+
ALLOW_MAIN_ADMIN_USER_EMAIL_NOTIFICATIONS: 'true' | 'false';
|
4
|
+
ALLOW_HTTP: 'true' | 'false';
|
5
|
+
PORT: string;
|
6
|
+
CORS_WHITELIST: string[];
|
7
|
+
DB_PROTOCOL: 'mongodb' | 'mongodb+srv';
|
8
|
+
DB_HOST: string;
|
9
|
+
DB_PORT?: string;
|
10
|
+
DB_NAME?: string;
|
11
|
+
DB_USR: string;
|
12
|
+
DB_PWD: string;
|
13
|
+
DB_OPT: string;
|
14
|
+
DB_RESERVED_AGENDA_JOBS_COLLECTION_NAME: string;
|
15
|
+
ROOT_USER_ID: string;
|
16
|
+
ROOT_USER_NAME: string;
|
17
|
+
ROOT_USER_EMAIL: string;
|
18
|
+
ROOT_USER_PWD: string;
|
19
|
+
MAIN_ADMIN_USER_ID: string;
|
20
|
+
MAIN_ADMIN_USER_NAME: string;
|
21
|
+
MAIN_ADMIN_USER_EMAIL: string;
|
22
|
+
MAIN_ADMIN_USER_PWD: string;
|
23
|
+
USER_EMAIL_VALIDATION_TOKEN_LIFETIME_MINUTES: number;
|
24
|
+
USER_PASSWORD_RENEWAL_TOKEN_LIFETIME_MINUTES: number;
|
25
|
+
JWT_SECRET: string;
|
26
|
+
ACCESS_TOKEN_EXPIRATION_SECONDS: number;
|
27
|
+
ACCESS_TOKEN_RENEWAL_THRESHOLD_SECONDS: number;
|
28
|
+
REFRESH_TOKEN_EXPIRATION_SECONDS: number;
|
29
|
+
ACCESS_TOKEN_MAX_REFRESH_COUNT: number;
|
30
|
+
REFRESH_TOKEN_MAX_REFRESH_COUNT: number;
|
31
|
+
ACCESS_TOKEN_EXPIRATION_SECONDS_ADMIN: number;
|
32
|
+
ACCESS_TOKEN_RENEWAL_THRESHOLD_SECONDS_ADMIN: number;
|
33
|
+
REFRESH_TOKEN_EXPIRATION_SECONDS_ADMIN: number;
|
34
|
+
ACCESS_TOKEN_MAX_REFRESH_COUNT_ADMIN: number;
|
35
|
+
REFRESH_TOKEN_MAX_REFRESH_COUNT_ADMIN: number;
|
36
|
+
TEMP_DIR_PREFIX: string;
|
37
|
+
TEMP_DIR_MAX_MEBIBYTES_SIZE: number;
|
38
|
+
CSRF_COOKIE_NAME: string;
|
39
|
+
CSRF_TOKEN_HEADER: string;
|
40
|
+
USER_UPLOAD_DAILY_LIMIT_MEBIBYTES: number;
|
41
|
+
USER_UPLOAD_MONTHLY_LIMIT_MEBIBYTES: number;
|
42
|
+
USER_UPLOAD_TOTAL_LIMIT_MEBIBYTES: number;
|
43
|
+
USER_UPLOAD_ALLOWED_EXTENSIONS: string[];
|
44
|
+
CLAMAV_PROTOCOL: 'http' | 'https';
|
45
|
+
CLAMAV_HOST: string;
|
46
|
+
CLAMAV_PORT?: number;
|
47
|
+
CLAMAV_AUTH_MODE: 'none' | 'gcp';
|
48
|
+
ESBUILD_BUILT_ON: string;
|
49
|
+
} & ({
|
50
|
+
FS_STORAGE_TYPE: 'gcs';
|
51
|
+
FS_STORAGE_GCS_BUCKET_NAME: string;
|
52
|
+
FS_STORAGE_GCS_PROJECT_ID: string;
|
53
|
+
FS_STORAGE_GCS_CLIENT_EMAIL: string;
|
54
|
+
FS_STORAGE_GCS_PRIVATE_KEY: string;
|
55
|
+
} | {
|
56
|
+
FS_STORAGE_TYPE: 'aws';
|
57
|
+
FS_STORAGE_AWS_REGION: string;
|
58
|
+
FS_STORAGE_AWS_ACCESS_KEY_ID: string;
|
59
|
+
FS_STORAGE_AWS_SECRET_ACCESS_KEY: string;
|
60
|
+
FS_STORAGE_AWS_BUCKET_NAME: string;
|
61
|
+
} | {
|
62
|
+
FS_STORAGE_TYPE: 'ftps';
|
63
|
+
FS_STORAGE_FTP_HOST: string;
|
64
|
+
FS_STORAGE_FTP_PORT: string;
|
65
|
+
FS_STORAGE_FTP_USER: string;
|
66
|
+
FS_STORAGE_FTP_PASSWORD: string;
|
67
|
+
} | {
|
68
|
+
FS_STORAGE_TYPE: 'sftp';
|
69
|
+
FS_STORAGE_FTP_HOST: string;
|
70
|
+
FS_STORAGE_FTP_PORT: string;
|
71
|
+
FS_STORAGE_FTP_USER: string;
|
72
|
+
FS_STORAGE_FTP_PASSWORD: string;
|
73
|
+
}) & ({
|
74
|
+
EMAILER_TYPE: 'mailersend';
|
75
|
+
EMAILER_MAILERSEND_API_KEY: string;
|
76
|
+
EMAILER_MAILERSEND_EMAILER_EMAIL: string;
|
77
|
+
EMAILER_MAILERSEND_EMAILER_NAME: string;
|
78
|
+
} | {
|
79
|
+
EMAILER_TYPE: 'gmail';
|
80
|
+
EMAILER_GMAIL_EMAIL: string;
|
81
|
+
EMAILER_GMAIL_NAME: string;
|
82
|
+
EMAILER_GMAIL_PASSWORD: string;
|
83
|
+
});
|