@aeriajs/types 0.0.27 → 0.0.29

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/api.d.ts CHANGED
@@ -14,13 +14,15 @@ export type UserACProfile = {
14
14
  readonly roles: string[];
15
15
  readonly allowed_functions?: string[];
16
16
  };
17
- export type DecodedToken = {
17
+ export type AuthenticatedToken = {
18
18
  authenticated: true;
19
19
  sub: ObjectId;
20
20
  roles: string[];
21
21
  userinfo: PackReferences<Collections['user']['item']>;
22
22
  allowed_functions?: FunctionPath[];
23
- } | {
23
+ };
24
+ export type UnauthenticatedToken = {
24
25
  authenticated: false;
25
26
  sub: null;
26
27
  };
28
+ export type DecodedToken = AuthenticatedToken | UnauthenticatedToken;
package/dist/config.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { RouteContext, RouteUri } from '.';
1
+ import type { RouteContext, RouteUri, RateLimitingParams } from '.';
2
2
  export type ApiConfig = {
3
3
  secret?: string;
4
4
  apiUrl?: string;
@@ -23,7 +23,10 @@ export type ApiConfig = {
23
23
  roles: string[];
24
24
  active: boolean;
25
25
  }>;
26
- logSuccessfulAuthentications?: boolean;
26
+ security?: {
27
+ logSuccessfulAuthentications?: boolean;
28
+ authenticationRateLimiting?: RateLimitingParams | null;
29
+ };
27
30
  tokenUserProperties?: string[];
28
31
  errorHandler?: <TError extends Error>(context: RouteContext, error: TError) => any | Promise<any>;
29
32
  };
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 { Description, PackReferences, SchemaWithId, FunctionPath, DecodedToken, ApiConfig, CollectionDocument, CollectionFunctions } from '.';
3
+ import type { Either, Description, PackReferences, SchemaWithId, FunctionPath, DecodedToken, 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;
@@ -18,9 +18,9 @@ export type IndepthCollection<TCollection> = TCollection extends {
18
18
  export type IndepthCollections = {
19
19
  [P in keyof Collections]: IndepthCollection<Collections[P]>;
20
20
  };
21
- export type ContextOptions<TContext> = {
21
+ export type ContextOptions = {
22
22
  config?: ApiConfig;
23
- parentContext?: TContext;
23
+ parentContext?: RouteContext | Context;
24
24
  collectionName?: string;
25
25
  token?: DecodedToken;
26
26
  inherited?: boolean;
@@ -33,6 +33,12 @@ export type RouteContext = {
33
33
  request: GenericRequest;
34
34
  response: GenericResponse;
35
35
  log: (message: string, details?: any) => Promise<any>;
36
+ limitRate: (params: RateLimitingParams) => Promise<Either<RateLimitingErrors, {
37
+ hits: number;
38
+ points: number;
39
+ last_reach: Date;
40
+ last_maximum_reach: Date;
41
+ }>>;
36
42
  config: ApiConfig;
37
43
  inherited: boolean;
38
44
  calledFunction: string;
@@ -1,4 +1,4 @@
1
- import type { Property, InferProperty, Context } from '.';
1
+ import type { Property, InferProperty, InferResponse, Context } from '.';
2
2
  export type ContractBase = {
3
3
  builtin?: boolean;
4
4
  };
@@ -17,5 +17,5 @@ export type Contract = ContractBase & ({
17
17
  query?: Property;
18
18
  });
19
19
  export type ContractWithRoles = ContractRoles & Contract;
20
- export type ContractToFunction<TContract extends Contract | ContractWithRoles, ContextParameter = Context> = ('payload' extends keyof TContract ? InferProperty<TContract['payload']> : undefined) extends infer Payload ? ('response' extends keyof TContract ? InferProperty<TContract['response']> : any) extends infer Response ? Payload extends undefined ? (payload: Payload | undefined, context: ContextParameter) => Response : (payload: Payload, context: ContextParameter) => Response : never : never;
20
+ export type ContractToFunction<TContract extends Contract | ContractWithRoles, ContextParameter = Context> = ('payload' extends keyof TContract ? InferProperty<TContract['payload']> : undefined) extends infer Payload ? ('response' extends keyof TContract ? InferResponse<TContract['response']> : any) extends infer Response ? Payload extends undefined ? (payload: Payload | undefined, context: ContextParameter) => Response : (payload: Payload, context: ContextParameter) => Response : never : never;
21
21
  export declare const defineContract: <const TContractWithRoles extends ContractWithRoles>(contract: TContractWithRoles) => TContractWithRoles;
package/dist/schema.d.ts CHANGED
@@ -20,7 +20,7 @@ export type InferProperty<T> = T extends TestType<{
20
20
  }> ? K : T extends TestType<{
21
21
  type: 'string';
22
22
  }> ? string : T extends TestType<{
23
- type: 'number';
23
+ type: 'number' | 'integer';
24
24
  }> ? number : T extends TestType<{
25
25
  type: 'boolean';
26
26
  }> ? boolean : T extends TestType<{
@@ -28,6 +28,10 @@ export type InferProperty<T> = T extends TestType<{
28
28
  }> ? Schema<T & {
29
29
  timestamps: false;
30
30
  }> : T extends TestType<{
31
+ additionalProperties: infer K;
32
+ }> ? {
33
+ [P: string]: InferProperty<K> | undefined;
34
+ } : T extends TestType<{
31
35
  type: 'object';
32
36
  }> ? any : T extends TestType<{
33
37
  items: infer K;
@@ -1,4 +1,9 @@
1
+ export declare enum RateLimitingErrors {
2
+ Unauthenticated = "UNAUTHENTICATED",
3
+ LimitReached = "LIMIT_REACHED"
4
+ }
1
5
  export type RateLimitingParams = {
6
+ strategy: 'tenant' | 'ip';
2
7
  limit?: number;
3
8
  scale?: number;
4
9
  increment?: number;
package/dist/security.js CHANGED
@@ -1,2 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RateLimitingErrors = void 0;
4
+ var RateLimitingErrors;
5
+ (function (RateLimitingErrors) {
6
+ RateLimitingErrors["Unauthenticated"] = "UNAUTHENTICATED";
7
+ RateLimitingErrors["LimitReached"] = "LIMIT_REACHED";
8
+ })(RateLimitingErrors || (exports.RateLimitingErrors = RateLimitingErrors = {}));
package/dist/security.mjs CHANGED
@@ -1 +1,6 @@
1
1
  "use strict";
2
+ export var RateLimitingErrors = /* @__PURE__ */ ((RateLimitingErrors2) => {
3
+ RateLimitingErrors2["Unauthenticated"] = "UNAUTHENTICATED";
4
+ RateLimitingErrors2["LimitReached"] = "LIMIT_REACHED";
5
+ return RateLimitingErrors2;
6
+ })(RateLimitingErrors || {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/types",
3
- "version": "0.0.27",
3
+ "version": "0.0.29",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",