@akanjs/nest 0.0.4

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/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # akan
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build akan` to build the library.
8
+
9
+ ## Running unit tests
10
+
11
+ Run `nx test akan` to execute the unit tests via [Jest](https://jestjs.io).
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./src";
package/index.js ADDED
@@ -0,0 +1,21 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var nest_exports = {};
16
+ module.exports = __toCommonJS(nest_exports);
17
+ __reExport(nest_exports, require("./src"), module.exports);
18
+ // Annotate the CommonJS export names for ESM import in node:
19
+ 0 && (module.exports = {
20
+ ...require("./src")
21
+ });
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@akanjs/nest",
3
+ "version": "0.0.4",
4
+ "type": "commonjs",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/akan-team/akanjs.git",
11
+ "directory": "pkgs/@akanjs/nest"
12
+ },
13
+ "dependencies": {
14
+ "@apollo/server": "4.11.2",
15
+ "@inquirer/prompts": "7.2.1",
16
+ "@nestjs/apollo": "12.2.2",
17
+ "@nestjs/common": "10.4.15",
18
+ "@nestjs/core": "10.4.15",
19
+ "@nestjs/graphql": "12.2.2",
20
+ "@nestjs/passport": "10.0.3",
21
+ "@nestjs/platform-express": "10.4.15",
22
+ "@nestjs/platform-socket.io": "10.4.15",
23
+ "@nestjs/websockets": "10.4.15",
24
+ "@socket.io/redis-adapter": "8.3.0",
25
+ "@urql/core": "5.1.0",
26
+ "apple-signin": "1.0.9",
27
+ "bull": "4.16.5",
28
+ "class-transformer": "0.5.1",
29
+ "class-validator": "0.14.1",
30
+ "dayjs": "1.11.13",
31
+ "express": "4.21.2",
32
+ "graphql": "16.10.0",
33
+ "iap": "1.1.1",
34
+ "immer": "10.1.1",
35
+ "jsonwebtoken": "9.0.2",
36
+ "mongoose": "8.9.3",
37
+ "next": "15.1.3",
38
+ "passport": "0.7.0",
39
+ "passport-apple": "2.0.2",
40
+ "passport-facebook": "3.0.0",
41
+ "passport-github": "1.1.0",
42
+ "passport-google-oauth20": "2.0.0",
43
+ "passport-kakao": "1.0.1",
44
+ "passport-naver": "1.0.6",
45
+ "picocolors": "1.1.1",
46
+ "pluralize": "8.0.0",
47
+ "react": "18.2.0",
48
+ "react-dom": "18.2.0",
49
+ "redis": "4.7.0",
50
+ "reflect-metadata": "0.2.2",
51
+ "rxjs": "7.8.1",
52
+ "socket.io": "4.8.1",
53
+ "socket.io-client": "4.8.1",
54
+ "tunnel-ssh": "5.2.0",
55
+ "ua-parser-js": "1.0.40"
56
+ },
57
+ "main": "./index.js"
58
+ }
@@ -0,0 +1,51 @@
1
+ import type { Account as SerAccount } from "@akanjs/signal";
2
+ import { CanActivate, ExecutionContext } from "@nestjs/common";
3
+ import type { Socket } from "socket.io";
4
+ export interface RequestContext {
5
+ account: SerAccount;
6
+ ip?: string;
7
+ userAgent?: string;
8
+ geolocation?: string;
9
+ headers: Record<string, string | undefined>;
10
+ cookies?: Record<string, string>;
11
+ }
12
+ export interface ReqType {
13
+ method: string;
14
+ url: string;
15
+ params: object;
16
+ query: object;
17
+ body: object;
18
+ }
19
+ export interface GqlReqType {
20
+ parentType?: {
21
+ name?: string;
22
+ };
23
+ fieldName?: string;
24
+ }
25
+ export declare const getRequest: (context: ExecutionContext) => unknown;
26
+ export declare const getResponse: (context: ExecutionContext) => unknown;
27
+ export declare const getArgs: (context: ExecutionContext) => {
28
+ [key: string]: any;
29
+ };
30
+ export declare const getSocket: (context: ExecutionContext) => Socket<import("socket.io").DefaultEventsMap, import("socket.io").DefaultEventsMap, import("socket.io").DefaultEventsMap, any>;
31
+ export declare class Public implements CanActivate {
32
+ canActivate(context: ExecutionContext): boolean;
33
+ }
34
+ export declare class None implements CanActivate {
35
+ canActivate(): boolean;
36
+ }
37
+ export declare class Every implements CanActivate {
38
+ canActivate(context: ExecutionContext): boolean;
39
+ }
40
+ export declare class Owner implements CanActivate {
41
+ canActivate(context: ExecutionContext): boolean;
42
+ }
43
+ export declare class Admin implements CanActivate {
44
+ canActivate(context: ExecutionContext): boolean;
45
+ }
46
+ export declare class SuperAdmin implements CanActivate {
47
+ canActivate(context: ExecutionContext): boolean;
48
+ }
49
+ export declare class User implements CanActivate {
50
+ canActivate(context: ExecutionContext): boolean;
51
+ }
@@ -0,0 +1,160 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var __decorateClass = (decorators, target, key, kind) => {
29
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
30
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
31
+ if (decorator = decorators[i])
32
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
33
+ if (kind && result)
34
+ __defProp(target, key, result);
35
+ return result;
36
+ };
37
+ var authGuards_exports = {};
38
+ __export(authGuards_exports, {
39
+ Admin: () => Admin,
40
+ Every: () => Every,
41
+ None: () => None,
42
+ Owner: () => Owner,
43
+ Public: () => Public,
44
+ SuperAdmin: () => SuperAdmin,
45
+ User: () => User,
46
+ getArgs: () => getArgs,
47
+ getRequest: () => getRequest,
48
+ getResponse: () => getResponse,
49
+ getSocket: () => getSocket
50
+ });
51
+ module.exports = __toCommonJS(authGuards_exports);
52
+ var import_common = require("@nestjs/common");
53
+ var import_graphql = require("@nestjs/graphql");
54
+ var Auth = __toESM(require("./authorization"));
55
+ const getRequest = (context) => {
56
+ const type = context.getType();
57
+ if (type === "ws")
58
+ throw new Error("Getting Request in Websocket is not allowed");
59
+ return type === "http" ? context.switchToHttp().getRequest() : import_graphql.GqlExecutionContext.create(context).getContext().req;
60
+ };
61
+ const getResponse = (context) => {
62
+ const type = context.getType();
63
+ if (type === "ws")
64
+ throw new Error("Getting Response in Websocket is not allowed");
65
+ return type === "http" ? context.switchToHttp().getResponse() : import_graphql.GqlExecutionContext.create(context).getContext().req.res;
66
+ };
67
+ const getArgs = (context) => {
68
+ const type = context.getType();
69
+ if (type === "ws")
70
+ throw new Error("Getting Args in Websocket is not allowed");
71
+ if (type === "graphql")
72
+ return import_graphql.GqlExecutionContext.create(context).getArgs();
73
+ else if (type === "http") {
74
+ const { params, query, body } = context.switchToHttp().getRequest();
75
+ return { ...params, ...query, ...body };
76
+ } else
77
+ throw new Error("Getting Args in Unknown context is not allowed");
78
+ };
79
+ const getSocket = (context) => {
80
+ const type = context.getType();
81
+ if (type !== "ws")
82
+ throw new Error("Getting Socket in Http or GraphQL is not allowed");
83
+ const socket = context.getArgByIndex(0);
84
+ return socket;
85
+ };
86
+ let Public = class {
87
+ canActivate(context) {
88
+ return true;
89
+ }
90
+ };
91
+ Public = __decorateClass([
92
+ (0, import_common.Injectable)()
93
+ ], Public);
94
+ let None = class {
95
+ canActivate() {
96
+ return false;
97
+ }
98
+ };
99
+ None = __decorateClass([
100
+ (0, import_common.Injectable)()
101
+ ], None);
102
+ let Every = class {
103
+ canActivate(context) {
104
+ const { account } = getRequest(context);
105
+ return Auth.allow(account, ["user", "admin", "superAdmin"]);
106
+ }
107
+ };
108
+ Every = __decorateClass([
109
+ (0, import_common.Injectable)()
110
+ ], Every);
111
+ let Owner = class {
112
+ canActivate(context) {
113
+ const { account } = getRequest(context);
114
+ return Auth.allow(account, ["user", "admin", "superAdmin"]);
115
+ }
116
+ };
117
+ Owner = __decorateClass([
118
+ (0, import_common.Injectable)()
119
+ ], Owner);
120
+ let Admin = class {
121
+ canActivate(context) {
122
+ const { account } = getRequest(context);
123
+ return Auth.allow(account, ["admin", "superAdmin"]);
124
+ }
125
+ };
126
+ Admin = __decorateClass([
127
+ (0, import_common.Injectable)()
128
+ ], Admin);
129
+ let SuperAdmin = class {
130
+ canActivate(context) {
131
+ const { account } = getRequest(context);
132
+ return Auth.allow(account, ["superAdmin"]);
133
+ }
134
+ };
135
+ SuperAdmin = __decorateClass([
136
+ (0, import_common.Injectable)()
137
+ ], SuperAdmin);
138
+ let User = class {
139
+ canActivate(context) {
140
+ const { account } = getRequest(context);
141
+ return Auth.allow(account, ["user"]);
142
+ }
143
+ };
144
+ User = __decorateClass([
145
+ (0, import_common.Injectable)()
146
+ ], User);
147
+ // Annotate the CommonJS export names for ESM import in node:
148
+ 0 && (module.exports = {
149
+ Admin,
150
+ Every,
151
+ None,
152
+ Owner,
153
+ Public,
154
+ SuperAdmin,
155
+ User,
156
+ getArgs,
157
+ getRequest,
158
+ getResponse,
159
+ getSocket
160
+ });
@@ -0,0 +1,18 @@
1
+ export declare const Account: (...dataOrPipes: ({
2
+ nullable?: boolean;
3
+ } | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
4
+ export declare const Self: (...dataOrPipes: ({
5
+ nullable?: boolean;
6
+ } | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
7
+ export declare const Me: (...dataOrPipes: ({
8
+ nullable?: boolean;
9
+ } | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
10
+ export declare const UserIp: (...dataOrPipes: ({
11
+ nullable?: boolean;
12
+ } | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
13
+ export declare const Access: (...dataOrPipes: ({
14
+ nullable?: boolean;
15
+ } | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
16
+ export declare const Req: (...dataOrPipes: unknown[]) => ParameterDecorator;
17
+ export declare const Res: (...dataOrPipes: unknown[]) => ParameterDecorator;
18
+ export declare const Ws: (...dataOrPipes: unknown[]) => ParameterDecorator;
@@ -0,0 +1,122 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var authentication_exports = {};
29
+ __export(authentication_exports, {
30
+ Access: () => Access,
31
+ Account: () => Account,
32
+ Me: () => Me,
33
+ Req: () => Req,
34
+ Res: () => Res,
35
+ Self: () => Self,
36
+ UserIp: () => UserIp,
37
+ Ws: () => Ws
38
+ });
39
+ module.exports = __toCommonJS(authentication_exports);
40
+ var import_base = require("@akanjs/base");
41
+ var import_common = require("@nestjs/common");
42
+ var import_ua_parser_js = __toESM(require("ua-parser-js"));
43
+ var import_authGuards = require("./authGuards");
44
+ const Account = (0, import_common.createParamDecorator)((option, context) => {
45
+ const { account } = (0, import_authGuards.getRequest)(context);
46
+ return account;
47
+ });
48
+ const Self = (0, import_common.createParamDecorator)((option, context) => {
49
+ const { account } = (0, import_authGuards.getRequest)(context);
50
+ const self = account.self;
51
+ if (!self && !option.nullable)
52
+ throw new import_common.UnauthorizedException("No or Invalid Account in Self (User)");
53
+ return self;
54
+ });
55
+ const Me = (0, import_common.createParamDecorator)((option, context) => {
56
+ const { account } = (0, import_authGuards.getRequest)(context);
57
+ const me = account.me;
58
+ if (!me && !option.nullable)
59
+ throw new import_common.UnauthorizedException("No or Invalid Account in Me (Admin)");
60
+ return me;
61
+ });
62
+ const UserIp = (0, import_common.createParamDecorator)((option, context) => {
63
+ const req = (0, import_authGuards.getRequest)(context);
64
+ const ip = req.ip;
65
+ if (!ip && !option.nullable)
66
+ throw new import_common.UnauthorizedException("Invalid IP");
67
+ return { ip };
68
+ });
69
+ const Access = (0, import_common.createParamDecorator)((option, context) => {
70
+ const req = (0, import_authGuards.getRequest)(context);
71
+ const res = new import_ua_parser_js.default(req.userAgent).getResult();
72
+ if (!req.userAgent && !option.nullable)
73
+ throw new import_common.UnauthorizedException("Invalid UserAgent");
74
+ return {
75
+ ...req.geolocation ? JSON.parse(req.geolocation) : {},
76
+ osName: res.os.name,
77
+ osVersion: res.os.version,
78
+ browserName: res.browser.name,
79
+ browserVersion: res.browser.version,
80
+ mobileModel: res.device.model,
81
+ mobileVendor: res.device.vendor,
82
+ deviceType: res.device.type ?? "desktop",
83
+ at: (0, import_base.dayjs)(),
84
+ period: 0
85
+ };
86
+ });
87
+ const Req = (0, import_common.createParamDecorator)((option, context) => {
88
+ return (0, import_authGuards.getRequest)(context);
89
+ });
90
+ const Res = (0, import_common.createParamDecorator)((option, context) => {
91
+ return (0, import_authGuards.getResponse)(context);
92
+ });
93
+ const Ws = (0, import_common.createParamDecorator)((option, context) => {
94
+ const socket = context.getArgByIndex(0);
95
+ const { __subscribe__ } = context.getArgByIndex(1);
96
+ return {
97
+ socket,
98
+ subscribe: __subscribe__,
99
+ onDisconnect: (handler) => {
100
+ socket.on("disconnect", handler);
101
+ },
102
+ onSubscribe: (handler) => {
103
+ if (__subscribe__)
104
+ handler();
105
+ },
106
+ onUnsubscribe: (handler) => {
107
+ if (!__subscribe__)
108
+ handler();
109
+ }
110
+ };
111
+ });
112
+ // Annotate the CommonJS export names for ESM import in node:
113
+ 0 && (module.exports = {
114
+ Access,
115
+ Account,
116
+ Me,
117
+ Req,
118
+ Res,
119
+ Self,
120
+ UserIp,
121
+ Ws
122
+ });
@@ -0,0 +1,3 @@
1
+ import { Account } from "@akanjs/signal";
2
+ export declare const verifyToken: (secret: string, authorization: string | undefined) => Account;
3
+ export declare const allow: (account: Account | null, roles: ("user" | "admin" | "superAdmin")[], userId?: string) => boolean;
@@ -0,0 +1,79 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var authorization_exports = {};
29
+ __export(authorization_exports, {
30
+ allow: () => allow,
31
+ verifyToken: () => verifyToken
32
+ });
33
+ module.exports = __toCommonJS(authorization_exports);
34
+ var import_base = require("@akanjs/base");
35
+ var import_signal = require("@akanjs/signal");
36
+ var import_apollo = require("@nestjs/apollo");
37
+ var jwt = __toESM(require("jsonwebtoken"));
38
+ const verifyToken = (secret, authorization) => {
39
+ const [type, token] = authorization?.split(" ") ?? [void 0, void 0];
40
+ if (!token || type !== "Bearer")
41
+ return import_signal.defaultAccount;
42
+ try {
43
+ const account = jwt.verify(token, secret);
44
+ if (account.appName !== import_base.baseEnv.appName || account.environment !== import_base.baseEnv.environment)
45
+ return import_signal.defaultAccount;
46
+ return {
47
+ __InternalArg__: "Account",
48
+ self: account.self && !account.self.removedAt ? account.self : void 0,
49
+ me: account.me && !account.me.removedAt ? account.me : void 0,
50
+ appName: account.appName,
51
+ environment: account.environment
52
+ };
53
+ } catch (e) {
54
+ return import_signal.defaultAccount;
55
+ }
56
+ };
57
+ const allow = (account, roles, userId) => {
58
+ if (!account)
59
+ throw new import_apollo.AuthenticationError("No Authentication Account");
60
+ for (const role of roles) {
61
+ if (role === "user" && account.self?.roles.includes("user"))
62
+ return true;
63
+ else if (role === "admin" && account.me?.roles.includes("admin"))
64
+ return true;
65
+ else if (role === "superAdmin" && account.me?.roles.includes("superAdmin"))
66
+ return true;
67
+ }
68
+ throw new import_apollo.AuthenticationError(
69
+ `No Authentication With Roles: ${roles.join(", ")}, Your roles are ${[
70
+ ...account.self?.roles ?? [],
71
+ ...account.me?.roles ?? []
72
+ ].join(", ")}${!account.self?.roles.length && !account.me?.roles.length ? " (No Roles)" : ""}`
73
+ );
74
+ };
75
+ // Annotate the CommonJS export names for ESM import in node:
76
+ 0 && (module.exports = {
77
+ allow,
78
+ verifyToken
79
+ });
@@ -0,0 +1,5 @@
1
+ import { ArgumentsHost, ExceptionFilter } from "@nestjs/common";
2
+ export declare class AllExceptionsFilter implements ExceptionFilter {
3
+ private readonly logger;
4
+ catch(exception: Error, host: ArgumentsHost): void;
5
+ }
@@ -0,0 +1,78 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var __decorateClass = (decorators, target, key, kind) => {
19
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
20
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
21
+ if (decorator = decorators[i])
22
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
23
+ if (kind && result)
24
+ __defProp(target, key, result);
25
+ return result;
26
+ };
27
+ var exceptions_exports = {};
28
+ __export(exceptions_exports, {
29
+ AllExceptionsFilter: () => AllExceptionsFilter
30
+ });
31
+ module.exports = __toCommonJS(exceptions_exports);
32
+ var import_common = require("@akanjs/common");
33
+ var import_common2 = require("@nestjs/common");
34
+ let AllExceptionsFilter = class {
35
+ logger = new import_common.Logger("Exception Filter");
36
+ catch(exception, host) {
37
+ if (host.getType() !== "http") {
38
+ const gqlArgs = host.getArgByIndex(1);
39
+ const gqlReq = host.getArgByIndex(3);
40
+ const reqType2 = gqlReq?.parentType?.name ?? "unknown";
41
+ const reqName2 = gqlReq?.fieldName ?? "unknown";
42
+ this.logger.error(
43
+ `GraphQL Error
44
+ Request: ${reqType2}-${reqName2}
45
+ Args: ${JSON.stringify(gqlArgs, null, 2)}
46
+ ${exception.stack}`
47
+ );
48
+ throw exception;
49
+ }
50
+ const ctx = host.switchToHttp();
51
+ const res = ctx.getResponse();
52
+ const req = ctx.getRequest();
53
+ const reqType = req.method;
54
+ const reqName = req.url;
55
+ const status = exception instanceof import_common2.HttpException ? exception.getStatus() : null;
56
+ if (status) {
57
+ res.status(status).json({
58
+ statusCode: status,
59
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
60
+ path: req.url,
61
+ message: exception instanceof import_common2.HttpException ? exception.getResponse() : exception.message
62
+ });
63
+ this.logger.error(
64
+ `Http Error: ${status}
65
+ Request: ${reqType}-${reqName}
66
+ Body: ${JSON.stringify(req.body, null, 2)}
67
+ ${exception.stack}`
68
+ );
69
+ }
70
+ }
71
+ };
72
+ AllExceptionsFilter = __decorateClass([
73
+ (0, import_common2.Catch)()
74
+ ], AllExceptionsFilter);
75
+ // Annotate the CommonJS export names for ESM import in node:
76
+ 0 && (module.exports = {
77
+ AllExceptionsFilter
78
+ });
@@ -0,0 +1,22 @@
1
+ import * as fs from "fs";
2
+ export declare const objPath: (o: unknown, p: string) => unknown;
3
+ export declare class FileSystem {
4
+ filename: string;
5
+ dirname: string;
6
+ writeStream?: fs.WriteStream;
7
+ constructor(dirname?: string, filename?: string);
8
+ init(): Promise<unknown>;
9
+ write(body: string): boolean;
10
+ }
11
+ export interface ExportForm<T> {
12
+ items: T[];
13
+ path: string;
14
+ fields?: string[];
15
+ options?: {
16
+ append: boolean;
17
+ };
18
+ delimiter?: string;
19
+ }
20
+ export declare const exportToCsv: <T>({ items, path, fields, delimiter, options }: ExportForm<T>) => Promise<void>;
21
+ export declare const exportToJson: <T>(items: T | T[], localPath: string) => void;
22
+ export declare const readJson: (localPath: string) => unknown;