@aeriajs/builtins 0.0.74 → 0.0.76

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.
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCurrentUser = exports.ActivationErrors = void 0;
4
+ const core_1 = require("@aeriajs/core");
5
+ const common_1 = require("@aeriajs/common");
6
+ var ActivationErrors;
7
+ (function (ActivationErrors) {
8
+ ActivationErrors["UserNotFound"] = "USER_NOT_FOUND";
9
+ ActivationErrors["AlreadyActiveUser"] = "ALREADY_ACTIVE_USER";
10
+ ActivationErrors["InvalidLink"] = "INVALID_LINK";
11
+ })(ActivationErrors || (exports.ActivationErrors = ActivationErrors = {}));
12
+ exports.getCurrentUser = (0, core_1.defineExposedFunction)(async (_payload, context) => {
13
+ if (!context.token.authenticated) {
14
+ return (0, common_1.left)({});
15
+ }
16
+ const user = await context.collections.user.functions.get({
17
+ filters: {
18
+ _id: context.token.sub,
19
+ },
20
+ });
21
+ if (!user) {
22
+ throw new Error();
23
+ }
24
+ const nonNullableUser = user;
25
+ return (0, common_1.right)(nonNullableUser);
26
+ });
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ import { defineExposedFunction } from "@aeriajs/core";
3
+ import { left, right } from "@aeriajs/common";
4
+ export var ActivationErrors = /* @__PURE__ */ ((ActivationErrors2) => {
5
+ ActivationErrors2["UserNotFound"] = "USER_NOT_FOUND";
6
+ ActivationErrors2["AlreadyActiveUser"] = "ALREADY_ACTIVE_USER";
7
+ ActivationErrors2["InvalidLink"] = "INVALID_LINK";
8
+ return ActivationErrors2;
9
+ })(ActivationErrors || {});
10
+ export const getCurrentUser = defineExposedFunction(async (_payload, context) => {
11
+ if (!context.token.authenticated) {
12
+ return left({});
13
+ }
14
+ const user = await context.collections.user.functions.get({
15
+ filters: {
16
+ _id: context.token.sub
17
+ }
18
+ });
19
+ if (!user) {
20
+ throw new Error();
21
+ }
22
+ const nonNullableUser = user;
23
+ return right(nonNullableUser);
24
+ });
@@ -9,6 +9,6 @@ export declare const getInfo: (payload: {
9
9
  userId: string;
10
10
  token: string;
11
11
  }, context: Context<typeof description>) => Promise<import("@aeriajs/types").Left<ActivationErrors.InvalidLink> | import("@aeriajs/types").Left<ActivationErrors.UserNotFound> | import("@aeriajs/types").Left<ActivationErrors.AlreadyActiveUser> | import("@aeriajs/types").Right<{
12
- readonly name: string;
13
- readonly email: string;
12
+ readonly name: any;
13
+ readonly email: any;
14
14
  }>>;