@aeriajs/types 0.0.29 → 0.0.30
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 +10 -8
- package/dist/api.d.ts +7 -10
- package/dist/config.d.ts +2 -2
- package/dist/context.d.ts +4 -4
- package/dist/contract.d.ts +2 -2
- package/dist/security.d.ts +17 -5
- package/package.json +1 -1
package/dist/accessControl.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Collection } from '.';
|
|
1
|
+
import type { AuthenticatedToken, Collection, Token, UserRole } from '.';
|
|
2
2
|
export declare enum ACErrors {
|
|
3
3
|
AssetNotFound = "ASSET_NOT_FOUND",
|
|
4
4
|
AuthenticationError = "AUTHENTICATION_ERROR",
|
|
@@ -18,14 +18,16 @@ export type Role<TCollection extends Collection = any, TAccessControl extends Ac
|
|
|
18
18
|
grant?: readonly (keyof TCollection['functions'])[];
|
|
19
19
|
forbid?: readonly (keyof TCollection['functions'])[];
|
|
20
20
|
};
|
|
21
|
-
export type
|
|
22
|
-
|
|
23
|
-
roles?: Roles<TCollection, TAccessControl>;
|
|
21
|
+
export type AccessControl<TCollection extends Collection = any, TAccessControl extends AccessControl<TCollection, TAccessControl> = any> = {
|
|
22
|
+
roles?: Partial<Record<string, Role<TCollection, TAccessControl>>>;
|
|
24
23
|
availableRoles?: keyof TAccessControl['roles'];
|
|
25
24
|
parent?: TAccessControl['roles'];
|
|
26
25
|
};
|
|
27
|
-
export type
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
export type NonCircularAccessControl<TCollection extends Collection = any, TAccessControl extends AccessControl<TCollection, TAccessControl> = any> = {
|
|
27
|
+
roles?: Record<string, Role<TCollection, TAccessControl>>;
|
|
28
|
+
availableRoles?: keyof TAccessControl['roles'];
|
|
29
|
+
parent?: TAccessControl['roles'];
|
|
31
30
|
};
|
|
31
|
+
export type ExpectToken<TToken extends Token, TRole extends UserRole | UserRole[]> = (TRole extends any[] ? TRole[number] : TRole) extends infer NormalizedRole ? TToken extends AuthenticatedToken ? NormalizedRole extends TToken['roles'][number] ? TToken : Omit<TToken, 'roles'> & {
|
|
32
|
+
roles: readonly NormalizedRole[];
|
|
33
|
+
} : TToken : never;
|
package/dist/api.d.ts
CHANGED
|
@@ -1,28 +1,25 @@
|
|
|
1
1
|
import type { ObjectId } from 'mongodb';
|
|
2
|
-
import type { Context, Contract, Description,
|
|
2
|
+
import type { Context, Contract, Description, CollectionSecurityPolicy, AccessControl, PackReferences } from '.';
|
|
3
3
|
export type Collection<TCollection extends Collection = any> = {
|
|
4
4
|
description: Description;
|
|
5
5
|
item?: any;
|
|
6
|
-
security?:
|
|
6
|
+
security?: CollectionSecurityPolicy<TCollection>;
|
|
7
7
|
accessControl?: AccessControl<TCollection>;
|
|
8
8
|
functions?: Record<string, (payload: any, context: Context, ...args: any[]) => any>;
|
|
9
9
|
functionContracts?: Record<string, Contract>;
|
|
10
10
|
};
|
|
11
11
|
export type AssetType = keyof Collection;
|
|
12
12
|
export type FunctionPath = `${string}@${string}`;
|
|
13
|
-
export type
|
|
14
|
-
|
|
15
|
-
readonly allowed_functions?: string[];
|
|
16
|
-
};
|
|
17
|
-
export type AuthenticatedToken = {
|
|
13
|
+
export type UserRole = Collections['user']['item']['roles'][number];
|
|
14
|
+
export type AuthenticatedToken<TAcceptedRole = string> = {
|
|
18
15
|
authenticated: true;
|
|
19
16
|
sub: ObjectId;
|
|
20
|
-
roles:
|
|
17
|
+
roles: readonly TAcceptedRole[];
|
|
18
|
+
allowed_functions?: readonly FunctionPath[];
|
|
21
19
|
userinfo: PackReferences<Collections['user']['item']>;
|
|
22
|
-
allowed_functions?: FunctionPath[];
|
|
23
20
|
};
|
|
24
21
|
export type UnauthenticatedToken = {
|
|
25
22
|
authenticated: false;
|
|
26
23
|
sub: null;
|
|
27
24
|
};
|
|
28
|
-
export type
|
|
25
|
+
export type Token<TAcceptedRole = string> = AuthenticatedToken<TAcceptedRole> | UnauthenticatedToken;
|
package/dist/config.d.ts
CHANGED
package/dist/context.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Collection as MongoCollection } from 'mongodb';
|
|
2
2
|
import type { GenericRequest, GenericResponse } from './http';
|
|
3
|
-
import type { Either, Description, PackReferences, SchemaWithId, FunctionPath,
|
|
3
|
+
import type { Either, Description, PackReferences, SchemaWithId, FunctionPath, Token, ApiConfig, CollectionDocument, CollectionFunctions, RateLimitingParams, RateLimitingErrors } from '.';
|
|
4
4
|
export type CollectionModel<TDescription extends Description> = MongoCollection<Omit<PackReferences<SchemaWithId<TDescription>>, '_id'>>;
|
|
5
5
|
type OmitContextParameter<TFunction> = TFunction extends () => any ? TFunction : TFunction extends (payload: undefined, ...args: any[]) => infer Return ? () => Return : TFunction extends (payload: infer Payload, context: Context, ...args: infer Rest) => infer Return ? (payload: Payload, ...args: Rest) => Return : never;
|
|
6
6
|
type RestParameters<TFunction> = TFunction extends (payload: any, context: Context, ...args: infer Rest) => any ? Rest : never;
|
|
@@ -22,14 +22,14 @@ export type ContextOptions = {
|
|
|
22
22
|
config?: ApiConfig;
|
|
23
23
|
parentContext?: RouteContext | Context;
|
|
24
24
|
collectionName?: string;
|
|
25
|
-
token?:
|
|
25
|
+
token?: Token;
|
|
26
26
|
inherited?: boolean;
|
|
27
27
|
calledFunction?: string;
|
|
28
28
|
};
|
|
29
|
-
export type RouteContext = {
|
|
29
|
+
export type RouteContext<TAcceptedRole = string> = {
|
|
30
30
|
collections: IndepthCollections;
|
|
31
31
|
functionPath: FunctionPath;
|
|
32
|
-
token:
|
|
32
|
+
token: Token<TAcceptedRole>;
|
|
33
33
|
request: GenericRequest;
|
|
34
34
|
response: GenericResponse;
|
|
35
35
|
log: (message: string, details?: any) => Promise<any>;
|
package/dist/contract.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { Property, InferProperty, InferResponse, Context } from '.';
|
|
1
|
+
import type { Property, InferProperty, InferResponse, Context, UserRole } from '.';
|
|
2
2
|
export type ContractBase = {
|
|
3
3
|
builtin?: boolean;
|
|
4
4
|
};
|
|
5
5
|
export type ContractRoles = {
|
|
6
|
-
roles?: (
|
|
6
|
+
roles?: (UserRole | 'root' | 'guest')[];
|
|
7
7
|
};
|
|
8
8
|
export type Contract = ContractBase & ({
|
|
9
9
|
response: Property | Property[];
|
package/dist/security.d.ts
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
|
+
import type { Collection } from './api.js';
|
|
1
2
|
export declare enum RateLimitingErrors {
|
|
2
3
|
Unauthenticated = "UNAUTHENTICATED",
|
|
3
4
|
LimitReached = "LIMIT_REACHED"
|
|
4
5
|
}
|
|
6
|
+
export type DiscriminationStrategy = 'tenant' | 'ip';
|
|
7
|
+
export type RateLimitingWithScale = {
|
|
8
|
+
scale: number;
|
|
9
|
+
};
|
|
10
|
+
export type RateLimitingWithLimit = {
|
|
11
|
+
limit: number;
|
|
12
|
+
};
|
|
5
13
|
export type RateLimitingParams = {
|
|
6
|
-
strategy:
|
|
7
|
-
limit?: number;
|
|
8
|
-
scale?: number;
|
|
14
|
+
strategy: DiscriminationStrategy;
|
|
9
15
|
increment?: number;
|
|
16
|
+
} & (RateLimitingWithLimit | RateLimitingWithScale | (RateLimitingWithLimit & RateLimitingWithScale));
|
|
17
|
+
export type LoggingLevel = 'debug' | 'info' | 'error' | 'critical';
|
|
18
|
+
export type LoggingParams = {
|
|
19
|
+
strategy: DiscriminationStrategy;
|
|
20
|
+
level: LoggingLevel;
|
|
10
21
|
};
|
|
11
22
|
export type SecurityPolicy = {
|
|
12
23
|
allowQueryOperators?: string[];
|
|
13
|
-
rateLimiting?:
|
|
14
|
-
|
|
24
|
+
rateLimiting?: RateLimitingParams;
|
|
25
|
+
logging?: LoggingParams;
|
|
15
26
|
};
|
|
27
|
+
export type CollectionSecurityPolicy<TCollection extends Collection = any> = Partial<Record<keyof TCollection['functions'], SecurityPolicy>>;
|