@aeriajs/types 0.0.114 → 0.0.116
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/accessControl.d.ts +14 -14
- package/dist/accessControl.js +14 -15
- package/dist/accessControl.mjs +14 -15
- package/dist/config.d.ts +6 -2
- package/dist/context.d.ts +2 -2
- package/dist/endpointError.d.ts +1 -1
- package/dist/functionSchemas.d.ts +8 -11
- package/dist/http.d.ts +14 -14
- package/dist/http.js +12 -13
- package/dist/http.mjs +12 -13
- package/dist/resultSchemas.d.ts +1 -1
- package/dist/security.d.ts +4 -4
- package/dist/security.js +4 -5
- package/dist/security.mjs +4 -5
- package/dist/token.d.ts +4 -3
- package/dist/validation.d.ts +23 -23
- package/dist/validation.js +19 -22
- package/dist/validation.mjs +19 -22
- package/package.json +1 -1
package/dist/accessControl.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { UserRole } from './token.js';
|
|
2
2
|
export type AccessCondition = undefined | boolean | readonly UserRole[] | 'unauthenticated' | 'unauthenticated-only';
|
|
3
3
|
export type RoleFromAccessCondition<TAccessCondition extends AccessCondition | undefined> = undefined extends TAccessCondition ? null : TAccessCondition extends readonly (infer Role)[] ? Role : TAccessCondition extends true ? Exclude<UserRole, 'unauthenticated'> : TAccessCondition extends false ? never : TAccessCondition extends 'unauthenticated-only' ? 'unauthenticated' : TAccessCondition extends 'unauthenticated' ? UserRole : never;
|
|
4
|
-
export declare
|
|
5
|
-
AuthenticationError
|
|
6
|
-
AuthorizationError
|
|
7
|
-
FunctionNotFound
|
|
8
|
-
FunctionNotExposed
|
|
9
|
-
TargetImmutable
|
|
10
|
-
InvalidLimit
|
|
11
|
-
OwnershipError
|
|
12
|
-
ResourceNotFound
|
|
13
|
-
InsecureOperator
|
|
14
|
-
MalformedInput
|
|
15
|
-
UniquenessViolated
|
|
16
|
-
UnknownError
|
|
17
|
-
}
|
|
4
|
+
export declare const ACError: {
|
|
5
|
+
readonly AuthenticationError: "AUTHENTICATION_ERROR";
|
|
6
|
+
readonly AuthorizationError: "AUTHORIZATION_ERROR";
|
|
7
|
+
readonly FunctionNotFound: "FUNCTION_NOT_FOUND";
|
|
8
|
+
readonly FunctionNotExposed: "FUNCTION_NOT_EXPOSED";
|
|
9
|
+
readonly TargetImmutable: "TARGET_IMMUTABLE";
|
|
10
|
+
readonly InvalidLimit: "INVALID_LIMIT";
|
|
11
|
+
readonly OwnershipError: "OWNERSHIP_ERROR";
|
|
12
|
+
readonly ResourceNotFound: "RESOURCE_NOT_FOUND";
|
|
13
|
+
readonly InsecureOperator: "INSECURE_OPERATOR";
|
|
14
|
+
readonly MalformedInput: "MALFORMED_INPUT";
|
|
15
|
+
readonly UniquenessViolated: "UNIQUENESS_VIOLATED";
|
|
16
|
+
readonly UnknownError: "UNKNOWN_ERROR";
|
|
17
|
+
};
|
package/dist/accessControl.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ACError = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
})(ACError || (exports.ACError = ACError = {}));
|
|
4
|
+
exports.ACError = {
|
|
5
|
+
AuthenticationError: 'AUTHENTICATION_ERROR',
|
|
6
|
+
AuthorizationError: 'AUTHORIZATION_ERROR',
|
|
7
|
+
FunctionNotFound: 'FUNCTION_NOT_FOUND',
|
|
8
|
+
FunctionNotExposed: 'FUNCTION_NOT_EXPOSED',
|
|
9
|
+
TargetImmutable: 'TARGET_IMMUTABLE',
|
|
10
|
+
InvalidLimit: 'INVALID_LIMIT',
|
|
11
|
+
OwnershipError: 'OWNERSHIP_ERROR',
|
|
12
|
+
ResourceNotFound: 'RESOURCE_NOT_FOUND',
|
|
13
|
+
InsecureOperator: 'INSECURE_OPERATOR',
|
|
14
|
+
MalformedInput: 'MALFORMED_INPUT',
|
|
15
|
+
UniquenessViolated: 'UNIQUENESS_VIOLATED',
|
|
16
|
+
UnknownError: 'UNKNOWN_ERROR',
|
|
17
|
+
};
|
package/dist/accessControl.mjs
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
})(ACError || {});
|
|
2
|
+
export const ACError = {
|
|
3
|
+
AuthenticationError: "AUTHENTICATION_ERROR",
|
|
4
|
+
AuthorizationError: "AUTHORIZATION_ERROR",
|
|
5
|
+
FunctionNotFound: "FUNCTION_NOT_FOUND",
|
|
6
|
+
FunctionNotExposed: "FUNCTION_NOT_EXPOSED",
|
|
7
|
+
TargetImmutable: "TARGET_IMMUTABLE",
|
|
8
|
+
InvalidLimit: "INVALID_LIMIT",
|
|
9
|
+
OwnershipError: "OWNERSHIP_ERROR",
|
|
10
|
+
ResourceNotFound: "RESOURCE_NOT_FOUND",
|
|
11
|
+
InsecureOperator: "INSECURE_OPERATOR",
|
|
12
|
+
MalformedInput: "MALFORMED_INPUT",
|
|
13
|
+
UniquenessViolated: "UNIQUENESS_VIOLATED",
|
|
14
|
+
UnknownError: "UNKNOWN_ERROR"
|
|
15
|
+
};
|
package/dist/config.d.ts
CHANGED
|
@@ -4,16 +4,20 @@ import type { RateLimitingParams } from './security.js';
|
|
|
4
4
|
import type { CollectionItem } from './collection.js';
|
|
5
5
|
import type { UserRole } from './token.js';
|
|
6
6
|
export type RolesHierarchy = Record<UserRole, readonly UserRole[] | boolean>;
|
|
7
|
+
export type ServerOptions = {
|
|
8
|
+
host?: string;
|
|
9
|
+
port?: number;
|
|
10
|
+
enableLogging?: boolean;
|
|
11
|
+
};
|
|
7
12
|
export type ApiConfig = {
|
|
8
13
|
name?: string;
|
|
9
14
|
secret?: string;
|
|
10
15
|
baseUrl?: RouteUri;
|
|
11
16
|
publicUrl?: string;
|
|
12
17
|
webPublicUrl?: string;
|
|
13
|
-
host?: string;
|
|
14
|
-
port?: number;
|
|
15
18
|
defaultPaginationLimit?: number;
|
|
16
19
|
noWarmup?: boolean;
|
|
20
|
+
server?: ServerOptions;
|
|
17
21
|
database?: {
|
|
18
22
|
mongodbUrl?: string;
|
|
19
23
|
noDatabase?: boolean;
|
package/dist/context.d.ts
CHANGED
|
@@ -44,10 +44,10 @@ export type RouteContext<TAccessCondition extends AccessCondition = false> = {
|
|
|
44
44
|
request: GenericRequest;
|
|
45
45
|
response: GenericResponse;
|
|
46
46
|
log: (message: string, details?: unknown) => Promise<unknown>;
|
|
47
|
-
error: <const THTTPStatus extends HTTPStatus, const TEndpointError extends Omit<EndpointError, 'httpStatus'>>(httpStatus: THTTPStatus, error: TEndpointError) => Result.Error<TEndpointError & {
|
|
47
|
+
error: <const THTTPStatus extends typeof HTTPStatus[keyof typeof HTTPStatus], const TEndpointError extends Omit<EndpointError, 'httpStatus'>>(httpStatus: THTTPStatus, error: TEndpointError) => Result.Error<TEndpointError & {
|
|
48
48
|
httpStatus: THTTPStatus;
|
|
49
49
|
}>;
|
|
50
|
-
limitRate: (params: RateLimitingParams) => Promise<Result.Either<EndpointError<RateLimitingError, HTTPStatus.TooManyRequests>, {
|
|
50
|
+
limitRate: (params: RateLimitingParams) => Promise<Result.Either<EndpointError<typeof RateLimitingError[keyof typeof RateLimitingError], typeof HTTPStatus.TooManyRequests>, {
|
|
51
51
|
hits: number;
|
|
52
52
|
points: number;
|
|
53
53
|
last_reach: Date;
|
package/dist/endpointError.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { HTTPStatus } from './http.js';
|
|
2
2
|
export declare const ERROR_SYMBOL_DESCRIPTION = "#__ERROR_SYMBOL__";
|
|
3
3
|
export declare const ERROR_SYMBOL: unique symbol;
|
|
4
|
-
export type EndpointError<TCode extends string = string, TDetails = unknown, THTTPStatus extends HTTPStatus | undefined = HTTPStatus, TMessage extends string | undefined = string> = {
|
|
4
|
+
export type EndpointError<TCode extends string = string, TDetails = unknown, THTTPStatus extends typeof HTTPStatus[keyof typeof HTTPStatus] | undefined = typeof HTTPStatus[keyof typeof HTTPStatus], TMessage extends string | undefined = string> = {
|
|
5
5
|
code: TCode;
|
|
6
6
|
details?: TDetails;
|
|
7
7
|
httpStatus: THTTPStatus;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { ACError } from './accessControl.js';
|
|
2
|
-
import { HTTPStatus } from './http.js';
|
|
3
|
-
import { ValidationErrorCode, TraverseError } from './validation.js';
|
|
4
1
|
export declare const insertError: () => {
|
|
5
2
|
readonly type: "object";
|
|
6
3
|
readonly properties: {
|
|
@@ -15,10 +12,10 @@ export declare const insertError: () => {
|
|
|
15
12
|
readonly required: readonly ["httpStatus", "code"];
|
|
16
13
|
readonly properties: {
|
|
17
14
|
readonly httpStatus: {
|
|
18
|
-
readonly enum: [
|
|
15
|
+
readonly enum: [403, 404, 422, 400, 500];
|
|
19
16
|
};
|
|
20
17
|
readonly code: {
|
|
21
|
-
readonly enum: [
|
|
18
|
+
readonly enum: ["INSECURE_OPERATOR", "OWNERSHIP_ERROR", "RESOURCE_NOT_FOUND", "TARGET_IMMUTABLE", "MALFORMED_INPUT", "UNIQUENESS_VIOLATED", "EMPTY_TARGET", "INVALID_PROPERTIES", "MISSING_PROPERTIES", "INVALID_DOCUMENT_ID", "INVALID_TEMPFILE"];
|
|
22
19
|
};
|
|
23
20
|
readonly message: {
|
|
24
21
|
readonly type: "string";
|
|
@@ -45,10 +42,10 @@ export declare const getError: () => {
|
|
|
45
42
|
readonly required: readonly ["httpStatus", "code"];
|
|
46
43
|
readonly properties: {
|
|
47
44
|
readonly httpStatus: {
|
|
48
|
-
readonly enum: [
|
|
45
|
+
readonly enum: [403, 404, 400];
|
|
49
46
|
};
|
|
50
47
|
readonly code: {
|
|
51
|
-
readonly enum: [
|
|
48
|
+
readonly enum: ["RESOURCE_NOT_FOUND", "OWNERSHIP_ERROR", "INSECURE_OPERATOR", "MALFORMED_INPUT"];
|
|
52
49
|
};
|
|
53
50
|
readonly message: {
|
|
54
51
|
readonly type: "string";
|
|
@@ -75,10 +72,10 @@ export declare const getAllError: () => {
|
|
|
75
72
|
readonly required: readonly ["httpStatus", "code"];
|
|
76
73
|
readonly properties: {
|
|
77
74
|
readonly httpStatus: {
|
|
78
|
-
readonly enum: [
|
|
75
|
+
readonly enum: [403];
|
|
79
76
|
};
|
|
80
77
|
readonly code: {
|
|
81
|
-
readonly enum: [
|
|
78
|
+
readonly enum: ["OWNERSHIP_ERROR", "INSECURE_OPERATOR", "INVALID_LIMIT"];
|
|
82
79
|
};
|
|
83
80
|
readonly message: {
|
|
84
81
|
readonly type: "string";
|
|
@@ -105,10 +102,10 @@ export declare const countError: () => {
|
|
|
105
102
|
readonly required: readonly ["httpStatus", "code"];
|
|
106
103
|
readonly properties: {
|
|
107
104
|
readonly httpStatus: {
|
|
108
|
-
readonly enum: [
|
|
105
|
+
readonly enum: [403];
|
|
109
106
|
};
|
|
110
107
|
readonly code: {
|
|
111
|
-
readonly enum: [
|
|
108
|
+
readonly enum: ["OWNERSHIP_ERROR", "INVALID_LIMIT"];
|
|
112
109
|
};
|
|
113
110
|
readonly message: {
|
|
114
111
|
readonly type: "string";
|
package/dist/http.d.ts
CHANGED
|
@@ -4,18 +4,18 @@ import type { EndpointError } from './endpointError.js';
|
|
|
4
4
|
import type { ACError } from './accessControl.js';
|
|
5
5
|
import type { RateLimitingError } from './security.js';
|
|
6
6
|
export declare const REQUEST_METHODS: readonly ["GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS", "PATCH", "TRACE", "SEARCH"];
|
|
7
|
-
export declare
|
|
8
|
-
Ok
|
|
9
|
-
NoContent
|
|
10
|
-
BadRequest
|
|
11
|
-
Unauthorized
|
|
12
|
-
Forbidden
|
|
13
|
-
NotFound
|
|
14
|
-
RangeNotSatisfiable
|
|
15
|
-
UnprocessableContent
|
|
16
|
-
TooManyRequests
|
|
17
|
-
InternalServerError
|
|
18
|
-
}
|
|
7
|
+
export declare const HTTPStatus: {
|
|
8
|
+
readonly Ok: 200;
|
|
9
|
+
readonly NoContent: 204;
|
|
10
|
+
readonly BadRequest: 400;
|
|
11
|
+
readonly Unauthorized: 401;
|
|
12
|
+
readonly Forbidden: 403;
|
|
13
|
+
readonly NotFound: 404;
|
|
14
|
+
readonly RangeNotSatisfiable: 416;
|
|
15
|
+
readonly UnprocessableContent: 422;
|
|
16
|
+
readonly TooManyRequests: 429;
|
|
17
|
+
readonly InternalServerError: 500;
|
|
18
|
+
};
|
|
19
19
|
export type RouteUri = `/${string}`;
|
|
20
20
|
export type RequestMethod = string;
|
|
21
21
|
export type GenericRequest = Omit<IncomingMessage, 'url' | 'method'> & {
|
|
@@ -32,8 +32,8 @@ export type GenericResponse = ServerResponse & {
|
|
|
32
32
|
};
|
|
33
33
|
type ExtractCode<TRouteResponse> = TRouteResponse extends EndpointError<infer PCode> ? PCode : never;
|
|
34
34
|
type ExtractHTTPStatus<TRouteResponse> = TRouteResponse extends EndpointError<string, unknown, infer PHTTPStatus> ? PHTTPStatus : never;
|
|
35
|
-
export type NativeError = ACError.AuthenticationError | ACError.AuthorizationError | RateLimitingError.LimitReached | RateLimitingError.Unauthenticated;
|
|
36
|
-
export type NativeHTTPErrorStatus = HTTPStatus.Unauthorized | HTTPStatus.TooManyRequests;
|
|
35
|
+
export type NativeError = typeof ACError.AuthenticationError | typeof ACError.AuthorizationError | typeof RateLimitingError.LimitReached | typeof RateLimitingError.Unauthenticated;
|
|
36
|
+
export type NativeHTTPErrorStatus = typeof HTTPStatus.Unauthorized | typeof HTTPStatus.TooManyRequests;
|
|
37
37
|
export type WithACErrors<TRouteResponse> = TRouteResponse extends Result.Either<infer InferredError, unknown> ? Result.Either<ExtractError<TRouteResponse> | EndpointError<ExtractCode<InferredError> | NativeError, unknown, ExtractHTTPStatus<InferredError> | NativeHTTPErrorStatus>, ExtractResult<TRouteResponse>> : TRouteResponse | Result.Error<EndpointError<NativeError, unknown, NativeHTTPErrorStatus>>;
|
|
38
38
|
export type EndpointFunction<TRouteMethod extends RequestMethod, TRouteResponse, TRoutePayload> = (TRoutePayload extends null ? <T = TRouteResponse>(payload?: unknown) => Promise<WithACErrors<T>> : TRoutePayload extends undefined ? <T = TRouteResponse>() => Promise<WithACErrors<T>> : <T = TRouteResponse>(payload: TRoutePayload) => Promise<WithACErrors<T>>) extends infer Function ? Record<TRouteMethod, Function> : never;
|
|
39
39
|
export type MakeEndpoint<TRoute extends string, TRouteMethod extends RequestMethod, TRouteResponse = unknown, TRoutePayload = null> = TRoute extends `/${infer RouteTail}` ? MakeEndpoint<RouteTail, TRouteMethod, TRouteResponse, TRoutePayload> : TRoute extends `${infer Route}/${infer RouteTail}` ? Record<Route, MakeEndpoint<RouteTail, TRouteMethod, TRouteResponse, TRoutePayload>> : TRoute extends `(${string}` ? Record<string, EndpointFunction<TRouteMethod, TRouteResponse, TRoutePayload>> : Record<TRoute, EndpointFunction<TRouteMethod, TRouteResponse, TRoutePayload>>;
|
package/dist/http.js
CHANGED
|
@@ -12,17 +12,16 @@ exports.REQUEST_METHODS = [
|
|
|
12
12
|
'TRACE',
|
|
13
13
|
'SEARCH',
|
|
14
14
|
];
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
})(HTTPStatus || (exports.HTTPStatus = HTTPStatus = {}));
|
|
15
|
+
exports.HTTPStatus = {
|
|
16
|
+
Ok: 200,
|
|
17
|
+
NoContent: 204,
|
|
18
|
+
BadRequest: 400,
|
|
19
|
+
Unauthorized: 401,
|
|
20
|
+
Forbidden: 403,
|
|
21
|
+
NotFound: 404,
|
|
22
|
+
RangeNotSatisfiable: 416,
|
|
23
|
+
UnprocessableContent: 422,
|
|
24
|
+
TooManyRequests: 429,
|
|
25
|
+
InternalServerError: 500,
|
|
26
|
+
};
|
|
28
27
|
exports.STREAMED_RESPONSE = Symbol('StreamedResponse');
|
package/dist/http.mjs
CHANGED
|
@@ -10,17 +10,16 @@ export const REQUEST_METHODS = [
|
|
|
10
10
|
"TRACE",
|
|
11
11
|
"SEARCH"
|
|
12
12
|
];
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
})(HTTPStatus || {});
|
|
13
|
+
export const HTTPStatus = {
|
|
14
|
+
Ok: 200,
|
|
15
|
+
NoContent: 204,
|
|
16
|
+
BadRequest: 400,
|
|
17
|
+
Unauthorized: 401,
|
|
18
|
+
Forbidden: 403,
|
|
19
|
+
NotFound: 404,
|
|
20
|
+
RangeNotSatisfiable: 416,
|
|
21
|
+
UnprocessableContent: 422,
|
|
22
|
+
TooManyRequests: 429,
|
|
23
|
+
InternalServerError: 500
|
|
24
|
+
};
|
|
26
25
|
export const STREAMED_RESPONSE = Symbol("StreamedResponse");
|
package/dist/resultSchemas.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export declare const resultSchema: <const TResult extends Property>(result: TRes
|
|
|
24
24
|
readonly result: Property;
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
|
-
export declare const endpointErrorSchema: <const THTTPStatus extends HTTPStatus[], const TCode extends string[]>(error: {
|
|
27
|
+
export declare const endpointErrorSchema: <const THTTPStatus extends (typeof HTTPStatus)[keyof typeof HTTPStatus][], const TCode extends string[]>(error: {
|
|
28
28
|
httpStatus: THTTPStatus;
|
|
29
29
|
code: TCode;
|
|
30
30
|
}) => {
|
package/dist/security.d.ts
CHANGED
|
@@ -3,10 +3,10 @@ import type { What } from './functions.js';
|
|
|
3
3
|
import type { Result } from './result.js';
|
|
4
4
|
import type { QuerySort } from './functions.js';
|
|
5
5
|
export type OwnershipMode = boolean | 'always' | 'on-write';
|
|
6
|
-
export declare
|
|
7
|
-
Unauthenticated
|
|
8
|
-
LimitReached
|
|
9
|
-
}
|
|
6
|
+
export declare const RateLimitingError: {
|
|
7
|
+
readonly Unauthenticated: "UNAUTHENTICATED";
|
|
8
|
+
readonly LimitReached: "LIMIT_REACHED";
|
|
9
|
+
};
|
|
10
10
|
export type DiscriminationStrategy = 'tenant' | 'ip';
|
|
11
11
|
export type RateLimitingWithScale = {
|
|
12
12
|
scale: number;
|
package/dist/security.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RateLimitingError = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
})(RateLimitingError || (exports.RateLimitingError = RateLimitingError = {}));
|
|
4
|
+
exports.RateLimitingError = {
|
|
5
|
+
Unauthenticated: 'UNAUTHENTICATED',
|
|
6
|
+
LimitReached: 'LIMIT_REACHED',
|
|
7
|
+
};
|
package/dist/security.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
})(RateLimitingError || {});
|
|
2
|
+
export const RateLimitingError = {
|
|
3
|
+
Unauthenticated: "UNAUTHENTICATED",
|
|
4
|
+
LimitReached: "LIMIT_REACHED"
|
|
5
|
+
};
|
package/dist/token.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import type { ObjectId } from 'mongodb';
|
|
2
2
|
import type { PackReferences } from './schema.js';
|
|
3
3
|
import type { AccessCondition } from './accessControl.js';
|
|
4
|
+
export type UserInfo = Omit<Collections['user']['item'], '_id' | 'roles'>;
|
|
4
5
|
export type UserRole = (Collections['user']['item'] extends {
|
|
5
6
|
roles: infer Roles;
|
|
6
7
|
} ? Roles extends unknown[] ? Roles[number] extends infer UserDefinedRole ? UserDefinedRole extends string ? `${UserDefinedRole}${UserDefinedRole}` extends UserDefinedRole ? 'root' : UserDefinedRole : never : never : never : never) | 'root' | 'unauthenticated';
|
|
7
|
-
export type AuthenticatedToken<TAccessCondition extends AccessCondition = true, TUserRole = UserRole
|
|
8
|
+
export type AuthenticatedToken<TAccessCondition extends AccessCondition = true, TUserRole = UserRole> = {
|
|
8
9
|
authenticated: true;
|
|
9
10
|
sub: ObjectId | null;
|
|
10
11
|
roles: TAccessCondition extends readonly unknown[] ? TAccessCondition : TAccessCondition extends true ? readonly TUserRole[] : TAccessCondition extends 'unauthenticated' ? readonly UserRole[] : readonly [];
|
|
11
12
|
picture?: string;
|
|
12
|
-
userinfo: Partial<
|
|
13
|
+
userinfo: Partial<UserInfo | PackReferences<UserInfo>>;
|
|
13
14
|
};
|
|
14
15
|
export type UnauthenticatedToken = {
|
|
15
16
|
authenticated: false;
|
|
@@ -19,4 +20,4 @@ export type TokenRecipient = {
|
|
|
19
20
|
type: 'bearer';
|
|
20
21
|
content: string;
|
|
21
22
|
};
|
|
22
|
-
export type Token<TAccessCondition extends AccessCondition = false, TUserRole = UserRole
|
|
23
|
+
export type Token<TAccessCondition extends AccessCondition = false, TUserRole = UserRole> = (false extends TAccessCondition ? false : TAccessCondition extends 'unauthenticated' | 'unauthenticated-only' ? false : true) extends true ? AuthenticatedToken<TAccessCondition> : 'unauthenticated-only' extends TAccessCondition ? UnauthenticatedToken : AuthenticatedToken<true, TUserRole> | UnauthenticatedToken;
|
package/dist/validation.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
InvalidProperties
|
|
3
|
-
MissingProperties
|
|
4
|
-
EmptyTarget
|
|
5
|
-
}
|
|
6
|
-
export declare
|
|
7
|
-
Missing
|
|
8
|
-
Extraneous
|
|
9
|
-
Unmatching
|
|
10
|
-
ExtraneousElement
|
|
11
|
-
MoreItemsExpected
|
|
12
|
-
LessItemsExpected
|
|
13
|
-
NumericConstraint
|
|
14
|
-
StringConstraint
|
|
15
|
-
}
|
|
16
|
-
export declare
|
|
17
|
-
InvalidDocumentId
|
|
18
|
-
InvalidTempfile
|
|
19
|
-
}
|
|
1
|
+
export declare const ValidationErrorCode: {
|
|
2
|
+
readonly InvalidProperties: "INVALID_PROPERTIES";
|
|
3
|
+
readonly MissingProperties: "MISSING_PROPERTIES";
|
|
4
|
+
readonly EmptyTarget: "EMPTY_TARGET";
|
|
5
|
+
};
|
|
6
|
+
export declare const PropertyValidationErrorCode: {
|
|
7
|
+
readonly Missing: "MISSING_PROPERTY";
|
|
8
|
+
readonly Extraneous: "EXTRANEOUS_PROPERTY";
|
|
9
|
+
readonly Unmatching: "UNMATCHING_PROPERTIES";
|
|
10
|
+
readonly ExtraneousElement: "EXTRANEOUS_ELEMENT";
|
|
11
|
+
readonly MoreItemsExpected: "MORE_ITEMS_EXPECTED";
|
|
12
|
+
readonly LessItemsExpected: "LESS_ITEMS_EXPECTED";
|
|
13
|
+
readonly NumericConstraint: "NUMERIC_CONSTRAINT";
|
|
14
|
+
readonly StringConstraint: "STRING_CONSTRAINT";
|
|
15
|
+
};
|
|
16
|
+
export declare const TraverseError: {
|
|
17
|
+
readonly InvalidDocumentId: "INVALID_DOCUMENT_ID";
|
|
18
|
+
readonly InvalidTempfile: "INVALID_TEMPFILE";
|
|
19
|
+
};
|
|
20
20
|
export type PropertyValidationError = {
|
|
21
|
-
type: PropertyValidationErrorCode;
|
|
21
|
+
type: typeof PropertyValidationErrorCode[keyof typeof PropertyValidationErrorCode];
|
|
22
22
|
index?: number;
|
|
23
23
|
details?: {
|
|
24
24
|
expected: unknown;
|
|
@@ -26,17 +26,17 @@ export type PropertyValidationError = {
|
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
28
|
export type ValidationErrorInvalidProperties = {
|
|
29
|
-
code: ValidationErrorCode.InvalidProperties;
|
|
29
|
+
code: typeof ValidationErrorCode.InvalidProperties;
|
|
30
30
|
details: Record<string, PropertyValidationError | ValidationError>;
|
|
31
31
|
};
|
|
32
32
|
export type ValidationErrorMissingProperties = {
|
|
33
|
-
code: ValidationErrorCode.MissingProperties;
|
|
33
|
+
code: typeof ValidationErrorCode.MissingProperties;
|
|
34
34
|
details: Record<string, {
|
|
35
35
|
type: 'missing';
|
|
36
36
|
}>;
|
|
37
37
|
};
|
|
38
38
|
export type ValidationErrorEmptyTarget = {
|
|
39
|
-
code: ValidationErrorCode.EmptyTarget;
|
|
39
|
+
code: typeof ValidationErrorCode.EmptyTarget;
|
|
40
40
|
details: {};
|
|
41
41
|
};
|
|
42
42
|
export type ValidationError = ValidationErrorInvalidProperties | ValidationErrorMissingProperties | ValidationErrorEmptyTarget;
|
package/dist/validation.js
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TraverseError = exports.PropertyValidationErrorCode = exports.ValidationErrorCode = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
TraverseError["InvalidDocumentId"] = "INVALID_DOCUMENT_ID";
|
|
24
|
-
TraverseError["InvalidTempfile"] = "INVALID_TEMPFILE";
|
|
25
|
-
})(TraverseError || (exports.TraverseError = TraverseError = {}));
|
|
4
|
+
exports.ValidationErrorCode = {
|
|
5
|
+
InvalidProperties: 'INVALID_PROPERTIES',
|
|
6
|
+
MissingProperties: 'MISSING_PROPERTIES',
|
|
7
|
+
EmptyTarget: 'EMPTY_TARGET',
|
|
8
|
+
};
|
|
9
|
+
exports.PropertyValidationErrorCode = {
|
|
10
|
+
Missing: 'MISSING_PROPERTY',
|
|
11
|
+
Extraneous: 'EXTRANEOUS_PROPERTY',
|
|
12
|
+
Unmatching: 'UNMATCHING_PROPERTIES',
|
|
13
|
+
ExtraneousElement: 'EXTRANEOUS_ELEMENT',
|
|
14
|
+
MoreItemsExpected: 'MORE_ITEMS_EXPECTED',
|
|
15
|
+
LessItemsExpected: 'LESS_ITEMS_EXPECTED',
|
|
16
|
+
NumericConstraint: 'NUMERIC_CONSTRAINT',
|
|
17
|
+
StringConstraint: 'STRING_CONSTRAINT',
|
|
18
|
+
};
|
|
19
|
+
exports.TraverseError = {
|
|
20
|
+
InvalidDocumentId: 'INVALID_DOCUMENT_ID',
|
|
21
|
+
InvalidTempfile: 'INVALID_TEMPFILE',
|
|
22
|
+
};
|
package/dist/validation.mjs
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
TraverseError2["InvalidTempfile"] = "INVALID_TEMPFILE";
|
|
22
|
-
return TraverseError2;
|
|
23
|
-
})(TraverseError || {});
|
|
2
|
+
export const ValidationErrorCode = {
|
|
3
|
+
InvalidProperties: "INVALID_PROPERTIES",
|
|
4
|
+
MissingProperties: "MISSING_PROPERTIES",
|
|
5
|
+
EmptyTarget: "EMPTY_TARGET"
|
|
6
|
+
};
|
|
7
|
+
export const PropertyValidationErrorCode = {
|
|
8
|
+
Missing: "MISSING_PROPERTY",
|
|
9
|
+
Extraneous: "EXTRANEOUS_PROPERTY",
|
|
10
|
+
Unmatching: "UNMATCHING_PROPERTIES",
|
|
11
|
+
ExtraneousElement: "EXTRANEOUS_ELEMENT",
|
|
12
|
+
MoreItemsExpected: "MORE_ITEMS_EXPECTED",
|
|
13
|
+
LessItemsExpected: "LESS_ITEMS_EXPECTED",
|
|
14
|
+
NumericConstraint: "NUMERIC_CONSTRAINT",
|
|
15
|
+
StringConstraint: "STRING_CONSTRAINT"
|
|
16
|
+
};
|
|
17
|
+
export const TraverseError = {
|
|
18
|
+
InvalidDocumentId: "INVALID_DOCUMENT_ID",
|
|
19
|
+
InvalidTempfile: "INVALID_TEMPFILE"
|
|
20
|
+
};
|