@aeriajs/types 0.0.29 → 0.0.31

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.
@@ -18,14 +18,13 @@ 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 Roles<TCollection extends Collection = any, TAccessControl extends AccessControl<TCollection> = any> = Record<string, Role<TCollection, TAccessControl>>;
22
- export type InternalAccessControl<TCollection extends Collection = any, TAccessControl extends AccessControl<TCollection, TAccessControl> = any> = {
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 AccessControl<TCollection extends Collection = any, TAccessControl extends AccessControl<TCollection, TAccessControl> = any> = InternalAccessControl<TCollection, TAccessControl>;
28
- export type ACProfile = {
29
- readonly roles?: string[];
30
- readonly allowed_functions?: string[];
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
  };
package/dist/api.d.ts CHANGED
@@ -1,28 +1,26 @@
1
1
  import type { ObjectId } from 'mongodb';
2
- import type { Context, Contract, Description, SecurityPolicy, AccessControl, PackReferences } from '.';
2
+ import type { Context, Contract, Description, CollectionSecurityPolicy, AccessControl, PackReferences } from '.';
3
+ export type AcceptedRole = UserRole | UserRole[] | null | unknown;
3
4
  export type Collection<TCollection extends Collection = any> = {
4
5
  description: Description;
5
6
  item?: any;
6
- security?: SecurityPolicy;
7
+ security?: CollectionSecurityPolicy<TCollection>;
7
8
  accessControl?: AccessControl<TCollection>;
8
9
  functions?: Record<string, (payload: any, context: Context, ...args: any[]) => any>;
9
10
  functionContracts?: Record<string, Contract>;
10
11
  };
11
12
  export type AssetType = keyof Collection;
12
13
  export type FunctionPath = `${string}@${string}`;
13
- export type UserACProfile = {
14
- readonly roles: string[];
15
- readonly allowed_functions?: string[];
16
- };
17
- export type AuthenticatedToken = {
14
+ export type UserRole = Collections['user']['item']['roles'][number] | 'root' | 'guest';
15
+ export type AuthenticatedToken<TAcceptedRole extends AcceptedRole = null> = {
18
16
  authenticated: true;
19
17
  sub: ObjectId;
20
- roles: string[];
18
+ roles: readonly (TAcceptedRole extends null ? string : TAcceptedRole)[];
19
+ allowed_functions?: readonly FunctionPath[];
21
20
  userinfo: PackReferences<Collections['user']['item']>;
22
- allowed_functions?: FunctionPath[];
23
21
  };
24
22
  export type UnauthenticatedToken = {
25
23
  authenticated: false;
26
24
  sub: null;
27
25
  };
28
- export type DecodedToken = AuthenticatedToken | UnauthenticatedToken;
26
+ export type Token<TAcceptedRole extends AcceptedRole = null> = (TAcceptedRole extends any[] ? TAcceptedRole[number] : TAcceptedRole) extends infer NormalizedRole ? NormalizedRole extends null | 'guest' ? AuthenticatedToken | UnauthenticatedToken : AuthenticatedToken<NormalizedRole> : never;
@@ -1,4 +1,4 @@
1
- import type { JsonSchema, PropertiesWithId } from './property';
1
+ import type { JsonSchema, PropertiesWithId } from './property.js';
2
2
  export type FinalOperator = 'equal' | 'in' | 'gt' | 'lt' | 'gte' | 'lte';
3
3
  export type FinalCondition<TSchema extends JsonSchema = any> = {
4
4
  operator: FinalOperator;
package/dist/config.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import type { RouteContext, RouteUri, RateLimitingParams } from '.';
2
2
  export type ApiConfig = {
3
3
  secret?: string;
4
- apiUrl?: string;
5
- apiBase?: RouteUri;
4
+ baseUrl?: RouteUri;
5
+ publicUrl?: string;
6
6
  port?: number;
7
7
  paginationLimit?: number;
8
8
  database?: {
package/dist/context.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { Collection as MongoCollection } from 'mongodb';
2
- import type { GenericRequest, GenericResponse } from './http';
3
- import type { Either, Description, PackReferences, SchemaWithId, FunctionPath, DecodedToken, ApiConfig, CollectionDocument, CollectionFunctions, RateLimitingParams, RateLimitingErrors } from '.';
2
+ import type { GenericRequest, GenericResponse } from './http.js';
3
+ import type { Either, Description, PackReferences, SchemaWithId, FunctionPath, Token, ApiConfig, CollectionDocument, CollectionFunctions, RateLimitingParams, RateLimitingErrors, AcceptedRole } 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?: DecodedToken;
25
+ token?: Token;
26
26
  inherited?: boolean;
27
27
  calledFunction?: string;
28
28
  };
29
- export type RouteContext = {
29
+ export type RouteContext<TAcceptedRole extends AcceptedRole = null> = {
30
30
  collections: IndepthCollections;
31
31
  functionPath: FunctionPath;
32
- token: DecodedToken;
32
+ token: Token<TAcceptedRole>;
33
33
  request: GenericRequest;
34
34
  response: GenericResponse;
35
35
  log: (message: string, details?: any) => Promise<any>;
@@ -49,6 +49,6 @@ export type Context<TDescription extends Description = any, TFunctions = any> =
49
49
  collection: TDescription['$id'] extends keyof Collections ? IndepthCollection<{
50
50
  description: TDescription;
51
51
  functions: TFunctions;
52
- }> : TDescription;
52
+ }> : IndepthCollection<any>;
53
53
  };
54
54
  export {};
@@ -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?: (Collections['user']['item']['roles'][number] | 'root' | 'guest')[];
6
+ roles?: UserRole[];
7
7
  };
8
8
  export type Contract = ContractBase & ({
9
9
  response: Property | Property[];
@@ -1,6 +1,7 @@
1
1
  import type { IconStyle, PhosphorIcon } from '@phosphor-icons/core';
2
- import type { JsonSchema, PropertiesWithId } from './property';
3
- import type { Condition } from './condition';
2
+ import type { JsonSchema, PropertiesWithId } from './property.js';
3
+ import type { Condition } from './condition.js';
4
+ import type { OwnershipMode } from './security.js';
4
5
  export type CollectionPresets = 'crud' | 'duplicate' | 'remove' | 'removeAll' | 'owned' | 'timestamped' | 'view';
5
6
  export type Icon = PhosphorIcon['name'] | `${IconStyle}:${PhosphorIcon['name']}`;
6
7
  export type CollectionAction<TDescription extends Description> = Readonly<{
@@ -71,33 +72,33 @@ export type SearchOptions<TDescription extends Description> = {
71
72
  };
72
73
  export type Description<TDescription extends Description = any> = JsonSchema<TDescription> & {
73
74
  title?: string;
74
- categories?: string[];
75
+ categories?: readonly string[];
75
76
  system?: boolean;
76
77
  inline?: boolean;
77
78
  preferred?: Record<string, Partial<TDescription | Description>>;
78
79
  icon?: Icon;
79
80
  options?: CollectionOptions<TDescription>;
80
- indexes?: ReadonlyArray<string>;
81
+ indexes?: readonly (keyof TDescription['properties'])[];
81
82
  defaults?: Record<string, any>;
82
- owned?: boolean | 'always';
83
+ owned?: OwnershipMode;
83
84
  temporary?: {
84
85
  index: keyof TDescription['properties'];
85
86
  expireAfterSeconds: number;
86
87
  };
87
88
  timestamps?: false;
88
- immutable?: boolean | ReadonlyArray<string>;
89
- route?: ReadonlyArray<string>;
90
- presets?: ReadonlyArray<CollectionPresets>;
91
- table?: ReadonlyArray<PropertiesWithId<TDescription>>;
92
- tableMeta?: ReadonlyArray<PropertiesWithId<TDescription>>;
89
+ immutable?: boolean | readonly string[];
90
+ route?: readonly string[];
91
+ presets?: readonly CollectionPresets[];
92
+ table?: readonly PropertiesWithId<TDescription>[];
93
+ tableMeta?: readonly PropertiesWithId<TDescription>[];
93
94
  filtersPresets?: Record<string, FiltersPreset<TDescription>>;
94
95
  freshItem?: Partial<Record<PropertiesWithId<TDescription>, any>>;
95
- form?: ReadonlyArray<PropertiesWithId<TDescription>> | Record<PropertiesWithId<TDescription>, string[]>;
96
- writable?: ReadonlyArray<PropertiesWithId<TDescription>>;
97
- filters?: ReadonlyArray<PropertiesWithId<TDescription> | {
96
+ form?: readonly PropertiesWithId<TDescription>[] | Record<PropertiesWithId<TDescription>, string[]>;
97
+ writable?: readonly PropertiesWithId<TDescription>[];
98
+ filters?: readonly (PropertiesWithId<TDescription> | {
98
99
  property: PropertiesWithId<TDescription>;
99
100
  default: string;
100
- }>;
101
+ })[];
101
102
  layout?: Layout<TDescription>;
102
103
  formLayout?: Partial<FormLayout<TDescription>>;
103
104
  tableLayout?: Partial<TableLayout<TDescription>>;
@@ -1,15 +1,28 @@
1
+ import type { Collection } from './api.js';
2
+ export type OwnershipMode = boolean | 'always' | 'on-write';
1
3
  export declare enum RateLimitingErrors {
2
4
  Unauthenticated = "UNAUTHENTICATED",
3
5
  LimitReached = "LIMIT_REACHED"
4
6
  }
7
+ export type DiscriminationStrategy = 'tenant' | 'ip';
8
+ export type RateLimitingWithScale = {
9
+ scale: number;
10
+ };
11
+ export type RateLimitingWithLimit = {
12
+ limit: number;
13
+ };
5
14
  export type RateLimitingParams = {
6
- strategy: 'tenant' | 'ip';
7
- limit?: number;
8
- scale?: number;
15
+ strategy: DiscriminationStrategy;
9
16
  increment?: number;
17
+ } & (RateLimitingWithLimit | RateLimitingWithScale | (RateLimitingWithLimit & RateLimitingWithScale));
18
+ export type LoggingLevel = 'debug' | 'info' | 'error' | 'critical';
19
+ export type LoggingParams = {
20
+ strategy: DiscriminationStrategy;
21
+ level: LoggingLevel;
10
22
  };
11
23
  export type SecurityPolicy = {
12
24
  allowQueryOperators?: string[];
13
- rateLimiting?: Record<string, RateLimitingParams>;
14
- accessControl?: any;
25
+ rateLimiting?: RateLimitingParams;
26
+ logging?: LoggingParams;
15
27
  };
28
+ export type CollectionSecurityPolicy<TCollection extends Collection = any> = Partial<Record<keyof TCollection['functions'], SecurityPolicy>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/types",
3
- "version": "0.0.29",
3
+ "version": "0.0.31",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",