@aeriajs/builtins 0.0.95 → 0.0.97

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.
@@ -7,7 +7,7 @@ export declare const download: (payload: {
7
7
  fileId: string;
8
8
  options: readonly ('picture' | 'download')[];
9
9
  noHeaders?: boolean;
10
- }, context: Context<typeof description>) => Promise<import("@aeriajs/types").EndpointError<{
10
+ }, context: Context<typeof description>) => Promise<import("../../../../types/dist/result.js").Result.Error<{
11
11
  readonly code: ACError.ResourceNotFound;
12
12
  } & {
13
13
  httpStatus: HTTPStatus.NotFound;
@@ -142,7 +142,7 @@ export declare const file: Omit<import("@aeriajs/types").Collection<{
142
142
  };
143
143
  };
144
144
  functions: {
145
- readonly get: (payload: import("@aeriajs/types").GetPayload<import("@aeriajs/types").SchemaWithId<any>>, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetOptions | undefined) => Promise<any>;
145
+ readonly get: (payload: import("@aeriajs/types").GetPayload<import("@aeriajs/types").SchemaWithId<any>>, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetOptions | undefined) => Promise<import("@aeriajs/types").GetReturnType<any>>;
146
146
  readonly insert: (payload: {
147
147
  what: {
148
148
  content: string;
@@ -348,7 +348,7 @@ export declare const file: Omit<import("@aeriajs/types").Collection<{
348
348
  readonly ask: true;
349
349
  };
350
350
  };
351
- }>) => Promise<import("@aeriajs/types").EndpointError<{
351
+ }>) => Promise<import("../../../../types/dist/result.js").Result.Error<{
352
352
  readonly code: import("@aeriajs/types").ACError.ResourceNotFound;
353
353
  } & {
354
354
  httpStatus: import("@aeriajs/types").HTTPStatus.NotFound;
@@ -612,7 +612,7 @@ export declare const file: Omit<import("@aeriajs/types").Collection<{
612
612
  };
613
613
  };
614
614
  functions: {
615
- readonly get: (payload: import("@aeriajs/types").GetPayload<import("@aeriajs/types").SchemaWithId<any>>, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetOptions | undefined) => Promise<any>;
615
+ readonly get: (payload: import("@aeriajs/types").GetPayload<import("@aeriajs/types").SchemaWithId<any>>, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetOptions | undefined) => Promise<import("@aeriajs/types").GetReturnType<any>>;
616
616
  readonly insert: (payload: {
617
617
  what: {
618
618
  content: string;
@@ -818,7 +818,7 @@ export declare const file: Omit<import("@aeriajs/types").Collection<{
818
818
  readonly ask: true;
819
819
  };
820
820
  };
821
- }>) => Promise<import("@aeriajs/types").EndpointError<{
821
+ }>) => Promise<import("../../../../types/dist/result.js").Result.Error<{
822
822
  readonly code: import("@aeriajs/types").ACError.ResourceNotFound;
823
823
  } & {
824
824
  httpStatus: import("@aeriajs/types").HTTPStatus.NotFound;
@@ -27,8 +27,12 @@ export declare const log: Omit<import("@aeriajs/types").Collection<{
27
27
  readonly filters: readonly ["context", "message", "owner"];
28
28
  };
29
29
  functions: {
30
- readonly get: (payload: import("@aeriajs/types").GetPayload<import("@aeriajs/types").SchemaWithId<any>>, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetOptions | undefined) => Promise<any>;
31
- readonly getAll: (_payload: import("@aeriajs/types").GetAllPayload<import("@aeriajs/types").SchemaWithId<import("@aeriajs/types").Description>> | undefined, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetAllOptions | undefined) => Promise<import("@aeriajs/types").SchemaWithId<any>[]>;
30
+ readonly get: (payload: import("@aeriajs/types").GetPayload<import("@aeriajs/types").SchemaWithId<any>>, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetOptions | undefined) => Promise<import("@aeriajs/types").GetReturnType<any>>;
31
+ readonly getAll: (_payload: import("@aeriajs/types").GetAllPayload<import("@aeriajs/types").SchemaWithId<import("@aeriajs/types").Description>> | undefined, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetAllOptions | undefined) => Promise<{
32
+ readonly _tag: "Result";
33
+ readonly error: undefined;
34
+ readonly result: import("@aeriajs/types").SchemaWithId<any>[];
35
+ }>;
32
36
  readonly insert: (payload: import("@aeriajs/types").InsertPayload<import("@aeriajs/types").SchemaWithId<any>>, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").InsertOptions | undefined) => Promise<import("@aeriajs/types").InsertReturnType<import("@aeriajs/types").SchemaWithId<any>>>;
33
37
  };
34
38
  exposedFunctions: {
@@ -92,8 +96,12 @@ export declare const log: Omit<import("@aeriajs/types").Collection<{
92
96
  readonly filters: readonly ["context", "message", "owner"];
93
97
  };
94
98
  functions: {
95
- readonly get: (payload: import("@aeriajs/types").GetPayload<import("@aeriajs/types").SchemaWithId<any>>, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetOptions | undefined) => Promise<any>;
96
- readonly getAll: (_payload: import("@aeriajs/types").GetAllPayload<import("@aeriajs/types").SchemaWithId<import("@aeriajs/types").Description>> | undefined, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetAllOptions | undefined) => Promise<import("@aeriajs/types").SchemaWithId<any>[]>;
99
+ readonly get: (payload: import("@aeriajs/types").GetPayload<import("@aeriajs/types").SchemaWithId<any>>, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetOptions | undefined) => Promise<import("@aeriajs/types").GetReturnType<any>>;
100
+ readonly getAll: (_payload: import("@aeriajs/types").GetAllPayload<import("@aeriajs/types").SchemaWithId<import("@aeriajs/types").Description>> | undefined, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").GetAllOptions | undefined) => Promise<{
101
+ readonly _tag: "Result";
102
+ readonly error: undefined;
103
+ readonly result: import("@aeriajs/types").SchemaWithId<any>[];
104
+ }>;
97
105
  readonly insert: (payload: import("@aeriajs/types").InsertPayload<import("@aeriajs/types").SchemaWithId<any>>, context: import("@aeriajs/types").StrictContext<any>, options?: import("@aeriajs/core").InsertOptions | undefined) => Promise<import("@aeriajs/types").InsertReturnType<import("@aeriajs/types").SchemaWithId<any>>>;
98
106
  };
99
107
  contracts: {
@@ -8,15 +8,15 @@ export declare enum ActivationError {
8
8
  }
9
9
  export declare const activate: (payload: {
10
10
  password: string;
11
- }, context: Context<typeof description>) => Promise<import("@aeriajs/types").GenericResponse | import("@aeriajs/types").EndpointError<{
11
+ }, context: Context<typeof description>) => Promise<import("@aeriajs/types").GenericResponse | import("../../../../types/dist/result.js").Result.Error<{
12
12
  readonly code: ActivationError.InvalidLink;
13
13
  } & {
14
14
  httpStatus: HTTPStatus.NotFound;
15
- }> | import("@aeriajs/types").EndpointError<{
15
+ }> | import("../../../../types/dist/result.js").Result.Error<{
16
16
  readonly code: ActivationError.UserNotFound;
17
17
  } & {
18
18
  httpStatus: HTTPStatus.NotFound;
19
- }> | import("@aeriajs/types").EndpointError<{
19
+ }> | import("../../../../types/dist/result.js").Result.Error<{
20
20
  readonly code: ActivationError.AlreadyActiveUser;
21
21
  } & {
22
22
  httpStatus: HTTPStatus.Forbidden;
@@ -32,27 +32,31 @@ export declare const getDefaultUser: () => Promise<{
32
32
  content: string;
33
33
  };
34
34
  }>;
35
- export declare const authenticate: (props: Props, context: Context<typeof description>) => Promise<Return | import("@aeriajs/types").EndpointError<{
35
+ export declare const authenticate: (props: Props, context: Context<typeof description>) => Promise<import("../../../../types/dist/result.js").Result.Error<{
36
36
  readonly code: ACError.AuthorizationError;
37
37
  } & {
38
38
  httpStatus: HTTPStatus.Unauthorized;
39
39
  }> | {
40
- user: {
41
- _id: null;
42
- name: string;
43
- email: string;
44
- roles: string[];
45
- active: boolean;
46
- };
47
- token: {
48
- type: string;
49
- content: string;
40
+ readonly _tag: "Result";
41
+ readonly error: undefined;
42
+ readonly result: Return | {
43
+ user: {
44
+ _id: null;
45
+ name: string;
46
+ email: string;
47
+ roles: string[];
48
+ active: boolean;
49
+ };
50
+ token: {
51
+ type: string;
52
+ content: string;
53
+ };
50
54
  };
51
- } | import("@aeriajs/types").EndpointError<{
55
+ } | import("../../../../types/dist/result.js").Result.Error<{
52
56
  readonly code: AuthenticationError.InvalidCredentials;
53
57
  } & {
54
58
  httpStatus: HTTPStatus.Unauthorized;
55
- }> | import("@aeriajs/types").EndpointError<{
59
+ }> | import("../../../../types/dist/result.js").Result.Error<{
56
60
  readonly code: AuthenticationError.InactiveUser;
57
61
  } & {
58
62
  httpStatus: HTTPStatus.Unauthorized;
@@ -11,13 +11,13 @@ var AuthenticationError;
11
11
  AuthenticationError["InactiveUser"] = "INACTIVE_USER";
12
12
  })(AuthenticationError || (exports.AuthenticationError = AuthenticationError = {}));
13
13
  const getUser = async (userId, context) => {
14
- const leanUser = await context.collection.functions.get({
14
+ const { error, result: leanUser } = await context.collection.functions.get({
15
15
  filters: {
16
16
  _id: userId,
17
17
  },
18
18
  populate: ['picture_file'],
19
19
  });
20
- if ((0, common_1.isError)(leanUser)) {
20
+ if (error) {
21
21
  throw new Error();
22
22
  }
23
23
  const tokenContent = {
@@ -88,9 +88,9 @@ const authenticate = async (props, context) => {
88
88
  const decodedToken = token
89
89
  ? await (0, core_1.decodeToken)(token.content)
90
90
  : context.token;
91
- return decodedToken.sub
92
- ? getUser(decodedToken.sub, context)
93
- : (0, exports.getDefaultUser)();
91
+ return common_1.Result.result(decodedToken.sub
92
+ ? await getUser(decodedToken.sub, context)
93
+ : await (0, exports.getDefaultUser)());
94
94
  }
95
95
  if (typeof props.email !== 'string') {
96
96
  return context.error(types_1.HTTPStatus.Unauthorized, {
@@ -99,7 +99,7 @@ const authenticate = async (props, context) => {
99
99
  }
100
100
  if (context.config.defaultUser) {
101
101
  if (props.email === context.config.defaultUser.username && props.password === context.config.defaultUser.password) {
102
- return (0, exports.getDefaultUser)();
102
+ return common_1.Result.result(await (0, exports.getDefaultUser)());
103
103
  }
104
104
  }
105
105
  const user = await context.collection.model.findOne({
@@ -121,6 +121,6 @@ const authenticate = async (props, context) => {
121
121
  code: AuthenticationError.InactiveUser,
122
122
  });
123
123
  }
124
- return getUser(user._id, context);
124
+ return common_1.Result.result(await getUser(user._id, context));
125
125
  };
126
126
  exports.authenticate = authenticate;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  import { HTTPStatus, ACError } from "@aeriajs/types";
3
- import { isError } from "@aeriajs/common";
3
+ import { Result } from "@aeriajs/common";
4
4
  import { compare as bcryptCompare } from "bcrypt";
5
5
  import { signToken, decodeToken } from "@aeriajs/core";
6
6
  export var AuthenticationError = /* @__PURE__ */ ((AuthenticationError2) => {
@@ -9,13 +9,13 @@ export var AuthenticationError = /* @__PURE__ */ ((AuthenticationError2) => {
9
9
  return AuthenticationError2;
10
10
  })(AuthenticationError || {});
11
11
  const getUser = async (userId, context) => {
12
- const leanUser = await context.collection.functions.get({
12
+ const { error, result: leanUser } = await context.collection.functions.get({
13
13
  filters: {
14
14
  _id: userId
15
15
  },
16
16
  populate: ["picture_file"]
17
17
  });
18
- if (isError(leanUser)) {
18
+ if (error) {
19
19
  throw new Error();
20
20
  }
21
21
  const tokenContent = {
@@ -82,7 +82,7 @@ export const authenticate = async (props, context) => {
82
82
  });
83
83
  }
84
84
  const decodedToken = token ? await decodeToken(token.content) : context.token;
85
- return decodedToken.sub ? getUser(decodedToken.sub, context) : getDefaultUser();
85
+ return Result.result(decodedToken.sub ? await getUser(decodedToken.sub, context) : await getDefaultUser());
86
86
  }
87
87
  if (typeof props.email !== "string") {
88
88
  return context.error(HTTPStatus.Unauthorized, {
@@ -91,7 +91,7 @@ export const authenticate = async (props, context) => {
91
91
  }
92
92
  if (context.config.defaultUser) {
93
93
  if (props.email === context.config.defaultUser.username && props.password === context.config.defaultUser.password) {
94
- return getDefaultUser();
94
+ return Result.result(await getDefaultUser());
95
95
  }
96
96
  }
97
97
  const user = await context.collection.model.findOne(
@@ -116,5 +116,5 @@ export const authenticate = async (props, context) => {
116
116
  code: "INACTIVE_USER" /* InactiveUser */
117
117
  });
118
118
  }
119
- return getUser(user._id, context);
119
+ return Result.result(await getUser(user._id, context));
120
120
  };
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createAccount = void 0;
4
4
  const types_1 = require("@aeriajs/types");
5
- const common_1 = require("@aeriajs/common");
6
5
  const validation_1 = require("@aeriajs/validation");
7
6
  const bcrypt = require("bcrypt");
8
7
  const createAccount = async (payload, context) => {
@@ -10,7 +9,7 @@ const createAccount = async (payload, context) => {
10
9
  if (!context.config.security.allowSignup) {
11
10
  throw new Error('signup disallowed');
12
11
  }
13
- const validationEither = (0, validation_1.validate)(user, {
12
+ const { error } = (0, validation_1.validate)(user, {
14
13
  type: 'object',
15
14
  required: [
16
15
  'name',
@@ -38,10 +37,10 @@ const createAccount = async (payload, context) => {
38
37
  'active',
39
38
  ],
40
39
  });
41
- if ((0, common_1.isLeft)(validationEither)) {
40
+ if (error) {
42
41
  return context.error(types_1.HTTPStatus.BadRequest, {
43
42
  code: types_1.ACError.MalformedInput,
44
- details: (0, common_1.unwrapEither)(validationEither),
43
+ details: error,
45
44
  });
46
45
  }
47
46
  if (context.config.security.signupDefaults) {
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  import { HTTPStatus, ACError } from "@aeriajs/types";
3
- import { isLeft, unwrapEither } from "@aeriajs/common";
4
3
  import { validate } from "@aeriajs/validation";
5
4
  import * as bcrypt from "bcrypt";
6
5
  export const createAccount = async (payload, context) => {
@@ -8,7 +7,7 @@ export const createAccount = async (payload, context) => {
8
7
  if (!context.config.security.allowSignup) {
9
8
  throw new Error("signup disallowed");
10
9
  }
11
- const validationEither = validate(user, {
10
+ const { error } = validate(user, {
12
11
  type: "object",
13
12
  required: [
14
13
  "name",
@@ -36,10 +35,10 @@ export const createAccount = async (payload, context) => {
36
35
  "active"
37
36
  ]
38
37
  });
39
- if (isLeft(validationEither)) {
38
+ if (error) {
40
39
  return context.error(HTTPStatus.BadRequest, {
41
40
  code: ACError.MalformedInput,
42
- details: unwrapEither(validationEither)
41
+ details: error
43
42
  });
44
43
  }
45
44
  if (context.config.security.signupDefaults) {
@@ -1,11 +1,11 @@
1
- import type { Context, SchemaWithId } from '@aeriajs/types';
1
+ import type { Context } from '@aeriajs/types';
2
2
  import type { description } from './description.js';
3
3
  export declare enum ActivationError {
4
4
  UserNotFound = "USER_NOT_FOUND",
5
5
  AlreadyActiveUser = "ALREADY_ACTIVE_USER",
6
6
  InvalidLink = "INVALID_LINK"
7
7
  }
8
- export declare const getCurrentUser: (_payload: undefined, context: Context<typeof description>) => Promise<SchemaWithId<{
8
+ export declare const getCurrentUser: (_payload: undefined, context: Context<typeof description>) => Promise<import("@aeriajs/types").SchemaWithId<{
9
9
  readonly $id: "user";
10
10
  readonly required: readonly ["name", "roles", "email"];
11
11
  readonly form: readonly ["name", "active", "roles", "email", "phone_number", "picture_file"];
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getCurrentUser = exports.ActivationError = void 0;
4
- const common_1 = require("@aeriajs/common");
5
4
  var ActivationError;
6
5
  (function (ActivationError) {
7
6
  ActivationError["UserNotFound"] = "USER_NOT_FOUND";
@@ -12,15 +11,14 @@ const getCurrentUser = async (_payload, context) => {
12
11
  if (!context.token.authenticated) {
13
12
  throw new Error();
14
13
  }
15
- const user = await context.collections.user.functions.get({
14
+ const { error, result } = await context.collections.user.functions.get({
16
15
  filters: {
17
16
  _id: context.token.sub,
18
17
  },
19
18
  });
20
- if ((0, common_1.isError)(user)) {
19
+ if (error) {
21
20
  throw new Error();
22
21
  }
23
- const nonNullableUser = user;
24
- return nonNullableUser;
22
+ return result;
25
23
  };
26
24
  exports.getCurrentUser = getCurrentUser;
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- import { isError } from "@aeriajs/common";
3
2
  export var ActivationError = /* @__PURE__ */ ((ActivationError2) => {
4
3
  ActivationError2["UserNotFound"] = "USER_NOT_FOUND";
5
4
  ActivationError2["AlreadyActiveUser"] = "ALREADY_ACTIVE_USER";
@@ -10,14 +9,13 @@ export const getCurrentUser = async (_payload, context) => {
10
9
  if (!context.token.authenticated) {
11
10
  throw new Error();
12
11
  }
13
- const user = await context.collections.user.functions.get({
12
+ const { error, result } = await context.collections.user.functions.get({
14
13
  filters: {
15
14
  _id: context.token.sub
16
15
  }
17
16
  });
18
- if (isError(user)) {
17
+ if (error) {
19
18
  throw new Error();
20
19
  }
21
- const nonNullableUser = user;
22
- return nonNullableUser;
20
+ return result;
23
21
  };
@@ -9,15 +9,15 @@ export declare enum ActivationError {
9
9
  export declare const getInfo: (payload: {
10
10
  userId: string;
11
11
  token: string;
12
- }, context: Context<typeof description>) => Promise<import("@aeriajs/types").EndpointError<{
12
+ }, context: Context<typeof description>) => Promise<import("../../../../types/dist/result").Result.Error<{
13
13
  readonly code: ActivationError.InvalidLink;
14
14
  } & {
15
15
  httpStatus: HTTPStatus.NotFound;
16
- }> | import("@aeriajs/types").EndpointError<{
16
+ }> | import("../../../../types/dist/result").Result.Error<{
17
17
  readonly code: ActivationError.UserNotFound;
18
18
  } & {
19
19
  httpStatus: HTTPStatus.NotFound;
20
- }> | import("@aeriajs/types").EndpointError<{
20
+ }> | import("../../../../types/dist/result").Result.Error<{
21
21
  readonly code: ActivationError.AlreadyActiveUser;
22
22
  } & {
23
23
  httpStatus: HTTPStatus.Forbidden;