@aeriajs/core 0.0.231 → 0.0.232

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.
@@ -1,7 +1,7 @@
1
1
  import type { Collection, Token } from '@aeriajs/types';
2
- export declare enum FunctionExposedStatus {
3
- FunctionNotExposed = "FUNCTION_NOT_EXPOSED",
4
- FunctionNotGranted = "FUNCTION_NOT_GRANTED",
5
- FunctionAccessible = "FUNCTION_ACCESSIBLE"
6
- }
7
- export declare const isFunctionExposed: (collection: Collection, fnName: string, token?: Token) => Promise<FunctionExposedStatus>;
2
+ export declare const FunctionExposedStatus: {
3
+ readonly FunctionNotExposed: "FUNCTION_NOT_EXPOSED";
4
+ readonly FunctionNotGranted: "FUNCTION_NOT_GRANTED";
5
+ readonly FunctionAccessible: "FUNCTION_ACCESSIBLE";
6
+ };
7
+ export declare const isFunctionExposed: (collection: Collection, fnName: string, token?: Token) => Promise<"FUNCTION_NOT_EXPOSED" | "FUNCTION_NOT_GRANTED" | "FUNCTION_ACCESSIBLE">;
@@ -3,35 +3,34 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isFunctionExposed = exports.FunctionExposedStatus = void 0;
4
4
  const entrypoint_1 = require("@aeriajs/entrypoint");
5
5
  const common_1 = require("@aeriajs/common");
6
- var FunctionExposedStatus;
7
- (function (FunctionExposedStatus) {
8
- FunctionExposedStatus["FunctionNotExposed"] = "FUNCTION_NOT_EXPOSED";
9
- FunctionExposedStatus["FunctionNotGranted"] = "FUNCTION_NOT_GRANTED";
10
- FunctionExposedStatus["FunctionAccessible"] = "FUNCTION_ACCESSIBLE";
11
- })(FunctionExposedStatus || (exports.FunctionExposedStatus = FunctionExposedStatus = {}));
6
+ exports.FunctionExposedStatus = {
7
+ FunctionNotExposed: 'FUNCTION_NOT_EXPOSED',
8
+ FunctionNotGranted: 'FUNCTION_NOT_GRANTED',
9
+ FunctionAccessible: 'FUNCTION_ACCESSIBLE',
10
+ };
12
11
  const isFunctionExposed = async (collection, fnName, token) => {
13
12
  const config = await (0, entrypoint_1.getConfig)();
14
13
  if (!collection.functions) {
15
- return FunctionExposedStatus.FunctionNotExposed;
14
+ return exports.FunctionExposedStatus.FunctionNotExposed;
16
15
  }
17
16
  if (collection.exposedFunctions && fnName in collection.exposedFunctions) {
18
17
  const exposed = collection.exposedFunctions[fnName];
19
18
  if (exposed === false) {
20
- return FunctionExposedStatus.FunctionNotExposed;
19
+ return exports.FunctionExposedStatus.FunctionNotExposed;
21
20
  }
22
21
  if (!token) {
23
- return FunctionExposedStatus.FunctionAccessible;
22
+ return exports.FunctionExposedStatus.FunctionAccessible;
24
23
  }
25
24
  return (0, common_1.isGranted)(exposed, token)
26
- ? FunctionExposedStatus.FunctionAccessible
27
- : FunctionExposedStatus.FunctionNotGranted;
25
+ ? exports.FunctionExposedStatus.FunctionAccessible
26
+ : exports.FunctionExposedStatus.FunctionNotGranted;
28
27
  }
29
28
  if (config.security.exposeFunctionsByDefault) {
30
29
  if (config.security.exposeFunctionsByDefault !== 'unauthenticated' && (!token || !token.authenticated)) {
31
- return FunctionExposedStatus.FunctionNotGranted;
30
+ return exports.FunctionExposedStatus.FunctionNotGranted;
32
31
  }
33
- return FunctionExposedStatus.FunctionAccessible;
32
+ return exports.FunctionExposedStatus.FunctionAccessible;
34
33
  }
35
- return FunctionExposedStatus.FunctionNotExposed;
34
+ return exports.FunctionExposedStatus.FunctionNotExposed;
36
35
  };
37
36
  exports.isFunctionExposed = isFunctionExposed;
@@ -1,32 +1,31 @@
1
1
  "use strict";
2
2
  import { getConfig } from "@aeriajs/entrypoint";
3
3
  import { isGranted } from "@aeriajs/common";
4
- export var FunctionExposedStatus = /* @__PURE__ */ ((FunctionExposedStatus2) => {
5
- FunctionExposedStatus2["FunctionNotExposed"] = "FUNCTION_NOT_EXPOSED";
6
- FunctionExposedStatus2["FunctionNotGranted"] = "FUNCTION_NOT_GRANTED";
7
- FunctionExposedStatus2["FunctionAccessible"] = "FUNCTION_ACCESSIBLE";
8
- return FunctionExposedStatus2;
9
- })(FunctionExposedStatus || {});
4
+ export const FunctionExposedStatus = {
5
+ FunctionNotExposed: "FUNCTION_NOT_EXPOSED",
6
+ FunctionNotGranted: "FUNCTION_NOT_GRANTED",
7
+ FunctionAccessible: "FUNCTION_ACCESSIBLE"
8
+ };
10
9
  export const isFunctionExposed = async (collection, fnName, token) => {
11
10
  const config = await getConfig();
12
11
  if (!collection.functions) {
13
- return "FUNCTION_NOT_EXPOSED" /* FunctionNotExposed */;
12
+ return FunctionExposedStatus.FunctionNotExposed;
14
13
  }
15
14
  if (collection.exposedFunctions && fnName in collection.exposedFunctions) {
16
15
  const exposed = collection.exposedFunctions[fnName];
17
16
  if (exposed === false) {
18
- return "FUNCTION_NOT_EXPOSED" /* FunctionNotExposed */;
17
+ return FunctionExposedStatus.FunctionNotExposed;
19
18
  }
20
19
  if (!token) {
21
- return "FUNCTION_ACCESSIBLE" /* FunctionAccessible */;
20
+ return FunctionExposedStatus.FunctionAccessible;
22
21
  }
23
- return isGranted(exposed, token) ? "FUNCTION_ACCESSIBLE" /* FunctionAccessible */ : "FUNCTION_NOT_GRANTED" /* FunctionNotGranted */;
22
+ return isGranted(exposed, token) ? FunctionExposedStatus.FunctionAccessible : FunctionExposedStatus.FunctionNotGranted;
24
23
  }
25
24
  if (config.security.exposeFunctionsByDefault) {
26
25
  if (config.security.exposeFunctionsByDefault !== "unauthenticated" && (!token || !token.authenticated)) {
27
- return "FUNCTION_NOT_GRANTED" /* FunctionNotGranted */;
26
+ return FunctionExposedStatus.FunctionNotGranted;
28
27
  }
29
- return "FUNCTION_ACCESSIBLE" /* FunctionAccessible */;
28
+ return FunctionExposedStatus.FunctionAccessible;
30
29
  }
31
- return "FUNCTION_NOT_EXPOSED" /* FunctionNotExposed */;
30
+ return FunctionExposedStatus.FunctionNotExposed;
32
31
  };
package/dist/assets.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import type { Context, Collection, Token } from '@aeriajs/types';
2
- import { ACError } from '@aeriajs/types';
3
2
  export declare const internalGetCollectionAsset: <TCollectionName extends string, TAssetName extends keyof Collections[TCollectionName] & keyof Collection>(collectionName: TCollectionName, assetName: TAssetName) => Promise<{
4
3
  readonly _tag: "Error";
5
- readonly error: ACError.ResourceNotFound;
4
+ readonly error: "RESOURCE_NOT_FOUND";
6
5
  readonly result: undefined;
7
6
  } | {
8
7
  readonly _tag: "Result";
@@ -11,7 +10,7 @@ export declare const internalGetCollectionAsset: <TCollectionName extends string
11
10
  }>;
12
11
  export declare const getCollectionAsset: <TCollectionName extends string, TAssetName extends keyof Collections[TCollectionName] & keyof Collection>(collectionName: TCollectionName, assetName: TAssetName) => Promise<{
13
12
  readonly _tag: "Error";
14
- readonly error: ACError.ResourceNotFound;
13
+ readonly error: "RESOURCE_NOT_FOUND";
15
14
  readonly result: undefined;
16
15
  } | {
17
16
  readonly _tag: "Result";
@@ -22,19 +21,19 @@ export declare const getFunction: <TFunction extends (payload: any, context: Con
22
21
  exposedOnly: boolean;
23
22
  }) => Promise<{
24
23
  readonly _tag: "Error";
25
- readonly error: ACError.ResourceNotFound;
24
+ readonly error: "RESOURCE_NOT_FOUND";
26
25
  readonly result: undefined;
27
26
  } | {
28
27
  readonly _tag: "Error";
29
- readonly error: ACError.FunctionNotFound;
28
+ readonly error: "FUNCTION_NOT_FOUND";
30
29
  readonly result: undefined;
31
30
  } | {
32
31
  readonly _tag: "Error";
33
- readonly error: ACError.FunctionNotExposed;
32
+ readonly error: "FUNCTION_NOT_EXPOSED";
34
33
  readonly result: undefined;
35
34
  } | {
36
35
  readonly _tag: "Error";
37
- readonly error: ACError.AuthorizationError;
36
+ readonly error: "AUTHORIZATION_ERROR";
38
37
  readonly result: undefined;
39
38
  } | {
40
39
  readonly _tag: "Result";
@@ -6,16 +6,16 @@ export declare const preferredRemove: (targetId: ObjectId | (ObjectId | null)[],
6
6
  readonly error: undefined;
7
7
  readonly result: import("mongodb").DeleteResult;
8
8
  } | import("@aeriajs/types").Result.Error<{
9
- readonly code: import("@aeriajs/types").ACError.OwnershipError;
9
+ readonly code: "OWNERSHIP_ERROR";
10
10
  } & {
11
- httpStatus: import("@aeriajs/types").HTTPStatus.Forbidden;
11
+ httpStatus: 403;
12
12
  }> | {
13
13
  readonly _tag: "Result";
14
14
  readonly error: undefined;
15
15
  readonly result: import("mongodb").WithId<Omit<import("@aeriajs/types").PackReferences<import("@aeriajs/types").SchemaWithId<import("@aeriajs/types").Description>>, "_id">> | null;
16
16
  } | import("@aeriajs/types").Result.Error<{
17
- readonly code: import("@aeriajs/types").ACError.ResourceNotFound;
17
+ readonly code: "RESOURCE_NOT_FOUND";
18
18
  } & {
19
- httpStatus: import("@aeriajs/types").HTTPStatus.NotFound;
19
+ httpStatus: 404;
20
20
  }> | undefined>;
21
21
  export declare const cascadingRemove: (target: Record<string, unknown>, context: Context) => Promise<void>;
@@ -1,5 +1,4 @@
1
1
  import type { Description, Property, ValidationError, RouteContext, TempId } from '@aeriajs/types';
2
- import { ACError, TraverseError } from '@aeriajs/types';
3
2
  import { ObjectId } from 'mongodb';
4
3
  export type TraverseOptionsBase = {
5
4
  autoCast?: boolean;
@@ -45,7 +44,7 @@ export declare const traverseDocument: <TWhat>(what: TWhat, description: Descrip
45
44
  readonly result: TWhat;
46
45
  } | {
47
46
  readonly _tag: "Error";
48
- readonly error: ACError.InsecureOperator | ValidationError | TraverseError;
47
+ readonly error: ValidationError | "INVALID_DOCUMENT_ID" | "INVALID_TEMPFILE" | "INSECURE_OPERATOR";
49
48
  readonly result: undefined;
50
49
  }>;
51
50
  export {};
@@ -1,5 +1,5 @@
1
1
  import type { Context, SchemaWithId, RemovePayload } from '@aeriajs/types';
2
- import { Result, HTTPStatus, ACError } from '@aeriajs/types';
2
+ import { Result } from '@aeriajs/types';
3
3
  export type RemoveOptions = {
4
4
  bypassSecurity?: boolean;
5
5
  };
@@ -8,11 +8,11 @@ export declare const remove: <TContext extends Context>(payload: RemovePayload<S
8
8
  readonly error: undefined;
9
9
  readonly result: import("mongodb").WithId<Omit<import("@aeriajs/types").PackReferences<SchemaWithId<import("@aeriajs/types").Description>>, "_id">> | null;
10
10
  } | Result.Error<{
11
- readonly code: ACError.ResourceNotFound;
11
+ readonly code: "RESOURCE_NOT_FOUND";
12
12
  } & {
13
- httpStatus: HTTPStatus.NotFound;
13
+ httpStatus: 404;
14
14
  }> | Result.Error<{
15
- readonly code: ACError.OwnershipError;
15
+ readonly code: "OWNERSHIP_ERROR";
16
16
  } & {
17
- httpStatus: HTTPStatus.Forbidden;
17
+ httpStatus: 403;
18
18
  }>>;
@@ -1,5 +1,5 @@
1
1
  import type { Context, SchemaWithId, RemoveAllPayload } from '@aeriajs/types';
2
- import { Result, ACError, HTTPStatus } from '@aeriajs/types';
2
+ import { Result } from '@aeriajs/types';
3
3
  export type RemoveAllOptions = {
4
4
  bypassSecurity?: boolean;
5
5
  };
@@ -8,7 +8,7 @@ export declare const removeAll: <TContext extends Context>(payload: RemoveAllPay
8
8
  readonly error: undefined;
9
9
  readonly result: import("mongodb").DeleteResult;
10
10
  } | Result.Error<{
11
- readonly code: ACError.OwnershipError;
11
+ readonly code: "OWNERSHIP_ERROR";
12
12
  } & {
13
- httpStatus: HTTPStatus.Forbidden;
13
+ httpStatus: 403;
14
14
  }>>;
@@ -1,5 +1,5 @@
1
1
  import type { Context, RemoveFilePayload } from '@aeriajs/types';
2
- import { Result, ACError, HTTPStatus } from '@aeriajs/types';
2
+ import { Result } from '@aeriajs/types';
3
3
  export type RemoveFileOptions = {
4
4
  bypassSecurity?: boolean;
5
5
  };
@@ -8,7 +8,7 @@ export declare const removeFile: <TContext extends Context>(payload: RemoveFileP
8
8
  readonly error: undefined;
9
9
  readonly result: any;
10
10
  } | Result.Error<{
11
- readonly code: ACError.OwnershipError;
11
+ readonly code: "OWNERSHIP_ERROR";
12
12
  } & {
13
- httpStatus: HTTPStatus.Forbidden;
13
+ httpStatus: 403;
14
14
  }>>;
@@ -1,4 +1,4 @@
1
- import { Result, ACError, HTTPStatus, type Context } from '@aeriajs/types';
1
+ import { Result, type Context } from '@aeriajs/types';
2
2
  export declare const FileMetadata: Pick<{} & Omit<Readonly<import("@aeriajs/types").FilterReadonlyProperties<{
3
3
  readonly name: {
4
4
  readonly type: "string";
@@ -98,10 +98,10 @@ export declare const UploadHeaders: Pick<{} & Omit<Readonly<import("@aeriajs/typ
98
98
  }, never>>;
99
99
  };
100
100
  export declare const upload: <TContext extends Context>(_props: unknown, context: TContext) => Promise<Result.Error<{
101
- readonly code: ACError.MalformedInput;
101
+ readonly code: "MALFORMED_INPUT";
102
102
  readonly details: import("@aeriajs/types").ValidationError | import("@aeriajs/types").PropertyValidationError;
103
103
  } & {
104
- httpStatus: HTTPStatus.BadRequest;
104
+ httpStatus: 400;
105
105
  }> | {
106
106
  readonly _tag: "Result";
107
107
  readonly error: undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aeriajs/core",
3
- "version": "0.0.231",
3
+ "version": "0.0.232",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "aeriaMain": "tests/fixtures/aeriaMain.js",
@@ -42,13 +42,13 @@
42
42
  "mongodb-memory-server": "^9.2.0"
43
43
  },
44
44
  "peerDependencies": {
45
- "@aeriajs/builtins": "^0.0.231",
45
+ "@aeriajs/builtins": "^0.0.232",
46
46
  "@aeriajs/common": "^0.0.132",
47
- "@aeriajs/entrypoint": "^0.0.135",
48
- "@aeriajs/http": "^0.0.159",
49
- "@aeriajs/security": "^0.0.231",
47
+ "@aeriajs/entrypoint": "^0.0.136",
48
+ "@aeriajs/http": "^0.0.160",
49
+ "@aeriajs/security": "^0.0.232",
50
50
  "@aeriajs/types": "^0.0.114",
51
- "@aeriajs/validation": "^0.0.147"
51
+ "@aeriajs/validation": "^0.0.148"
52
52
  },
53
53
  "dependencies": {
54
54
  "mongodb": "^6.5.0",