@akanjs/nest 0.0.40 → 0.0.41

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,80 +0,0 @@
1
- import * as socket_io from 'socket.io';
2
- import { Socket } from 'socket.io';
3
- import { A as Account } from './signalDecorators-Bh7Aniud.js';
4
- import { ExecutionContext, CanActivate } from '@nestjs/common';
5
-
6
- interface RequestContext {
7
- account: Account;
8
- ip?: string;
9
- userAgent?: string;
10
- geolocation?: string;
11
- headers: Record<string, string | undefined>;
12
- cookies?: Record<string, string>;
13
- }
14
- interface ReqType {
15
- method: string;
16
- url: string;
17
- params: object;
18
- query: object;
19
- body: object;
20
- }
21
- interface GqlReqType {
22
- parentType?: {
23
- name?: string;
24
- };
25
- fieldName?: string;
26
- }
27
- declare const getRequest: (context: ExecutionContext) => unknown;
28
- declare const getResponse: (context: ExecutionContext) => unknown;
29
- declare const getArgs: (context: ExecutionContext) => {
30
- [key: string]: any;
31
- };
32
- declare const getSocket: (context: ExecutionContext) => Socket<socket_io.DefaultEventsMap, socket_io.DefaultEventsMap, socket_io.DefaultEventsMap, any>;
33
- declare class Public implements CanActivate {
34
- canActivate(context: ExecutionContext): boolean;
35
- }
36
- declare class None implements CanActivate {
37
- canActivate(): boolean;
38
- }
39
- declare class Every implements CanActivate {
40
- canActivate(context: ExecutionContext): boolean;
41
- }
42
- declare class Owner implements CanActivate {
43
- canActivate(context: ExecutionContext): boolean;
44
- }
45
- declare class Admin implements CanActivate {
46
- canActivate(context: ExecutionContext): boolean;
47
- }
48
- declare class SuperAdmin implements CanActivate {
49
- canActivate(context: ExecutionContext): boolean;
50
- }
51
- declare class User implements CanActivate {
52
- canActivate(context: ExecutionContext): boolean;
53
- }
54
-
55
- type authGuards_Admin = Admin;
56
- declare const authGuards_Admin: typeof Admin;
57
- type authGuards_Every = Every;
58
- declare const authGuards_Every: typeof Every;
59
- type authGuards_GqlReqType = GqlReqType;
60
- type authGuards_None = None;
61
- declare const authGuards_None: typeof None;
62
- type authGuards_Owner = Owner;
63
- declare const authGuards_Owner: typeof Owner;
64
- type authGuards_Public = Public;
65
- declare const authGuards_Public: typeof Public;
66
- type authGuards_ReqType = ReqType;
67
- type authGuards_RequestContext = RequestContext;
68
- type authGuards_SuperAdmin = SuperAdmin;
69
- declare const authGuards_SuperAdmin: typeof SuperAdmin;
70
- type authGuards_User = User;
71
- declare const authGuards_User: typeof User;
72
- declare const authGuards_getArgs: typeof getArgs;
73
- declare const authGuards_getRequest: typeof getRequest;
74
- declare const authGuards_getResponse: typeof getResponse;
75
- declare const authGuards_getSocket: typeof getSocket;
76
- declare namespace authGuards {
77
- export { authGuards_Admin as Admin, authGuards_Every as Every, type authGuards_GqlReqType as GqlReqType, authGuards_None as None, authGuards_Owner as Owner, authGuards_Public as Public, type authGuards_ReqType as ReqType, type authGuards_RequestContext as RequestContext, authGuards_SuperAdmin as SuperAdmin, authGuards_User as User, authGuards_getArgs as getArgs, authGuards_getRequest as getRequest, authGuards_getResponse as getResponse, authGuards_getSocket as getSocket };
78
- }
79
-
80
- export { Admin as A, Every as E, type GqlReqType as G, None as N, Owner as O, Public as P, type RequestContext as R, SuperAdmin as S, User as U, authGuards as a, type ReqType as b, getResponse as c, getArgs as d, getSocket as e, getRequest as g };
@@ -1,33 +0,0 @@
1
- import { SshOptions } from 'tunnel-ssh';
2
-
3
- type Environment = "testing" | "debug" | "develop" | "main";
4
- interface BaseEnv {
5
- repoName: string;
6
- serveDomain: string;
7
- appName: string;
8
- environment: Environment;
9
- operationType: "server" | "client";
10
- operationMode: "local" | "edge" | "cloud" | "module";
11
- networkType: "mainnet" | "testnet" | "debugnet";
12
- tunnelUsername: string;
13
- tunnelPassword: string;
14
- }
15
- type BackendEnv = BaseEnv & {
16
- hostname: string | null;
17
- appCode: number;
18
- mongo: {
19
- username?: string;
20
- password?: string;
21
- sshOptions?: SshOptions;
22
- };
23
- redis?: {
24
- sshOptions?: SshOptions;
25
- };
26
- port?: number;
27
- mongoUri?: string;
28
- redisUri?: string;
29
- meiliUri?: string;
30
- onCleanup?: () => Promise<void>;
31
- };
32
-
33
- export type { BaseEnv as B, Environment as E, BackendEnv as a };
@@ -1,36 +0,0 @@
1
- import * as fs from 'fs';
2
-
3
- declare const objPath: (o: unknown, p: string) => unknown;
4
- declare class FileSystem {
5
- filename: string;
6
- dirname: string;
7
- writeStream?: fs.WriteStream;
8
- constructor(dirname?: string, filename?: string);
9
- init(): Promise<unknown>;
10
- write(body: string): boolean;
11
- }
12
- interface ExportForm<T> {
13
- items: T[];
14
- path: string;
15
- fields?: string[];
16
- options?: {
17
- append: boolean;
18
- };
19
- delimiter?: string;
20
- }
21
- declare const exportToCsv: <T>({ items, path, fields, delimiter, options }: ExportForm<T>) => Promise<void>;
22
- declare const exportToJson: <T>(items: T | T[], localPath: string) => void;
23
- declare const readJson: (localPath: string) => unknown;
24
-
25
- type exporter_ExportForm<T> = ExportForm<T>;
26
- type exporter_FileSystem = FileSystem;
27
- declare const exporter_FileSystem: typeof FileSystem;
28
- declare const exporter_exportToCsv: typeof exportToCsv;
29
- declare const exporter_exportToJson: typeof exportToJson;
30
- declare const exporter_objPath: typeof objPath;
31
- declare const exporter_readJson: typeof readJson;
32
- declare namespace exporter {
33
- export { type exporter_ExportForm as ExportForm, exporter_FileSystem as FileSystem, exporter_exportToCsv as exportToCsv, exporter_exportToJson as exportToJson, exporter_objPath as objPath, exporter_readJson as readJson };
34
- }
35
-
36
- export { type ExportForm as E, FileSystem as F, exportToCsv as a, exportToJson as b, exporter as e, objPath as o, readJson as r };
@@ -1,121 +0,0 @@
1
- import { E as Environment } from './baseEnv-Qb_Lg-a-.js';
2
- import { Dayjs } from 'dayjs';
3
-
4
- declare class Enum<T> {
5
- readonly values: T[];
6
- readonly value: T;
7
- readonly valueMap: Map<T, number>;
8
- constructor(values: T[]);
9
- has(value: T): boolean;
10
- indexOf(value: T): number;
11
- find(callback: (value: T, index: number, array: T[]) => boolean): T;
12
- findIndex(callback: (value: T, index: number, array: T[]) => boolean): number;
13
- filter(callback: (value: T, index: number, array: T[]) => boolean): T[];
14
- map<R>(callback: (value: T, index: number, array: T[]) => R): R[];
15
- forEach(callback: (value: T, index: number, array: T[]) => void): void;
16
- }
17
-
18
- type Type<T = any> = new (...args: any[]) => T;
19
- interface GraphQLUpload {
20
- name: string;
21
- description: string;
22
- specifiedByUrl: string;
23
- serialize: any;
24
- parseValue: any;
25
- parseLiteral: any;
26
- extensions: any;
27
- astNode: any;
28
- extensionASTNodes: any;
29
- toConfig(): any;
30
- toString(): string;
31
- toJSON(): string;
32
- inspect(): string;
33
- }
34
- interface GraphQLJSON<TInternal = unknown, TExternal = TInternal> {
35
- name: string;
36
- description: string;
37
- specifiedByURL: string;
38
- serialize: any;
39
- parseValue: any;
40
- parseLiteral: any;
41
- extensions: any;
42
- astNode: any;
43
- extensionASTNodes: any;
44
- get [Symbol.toStringTag](): string;
45
- toConfig(): any;
46
- toString(): string;
47
- toJSON(): string;
48
- }
49
-
50
- declare class Int {
51
- __Scalar__: "int";
52
- }
53
- declare class Float {
54
- __Scalar__: "float";
55
- }
56
- declare class ID {
57
- __Scalar__: "id";
58
- }
59
- declare class JSON {
60
- __Scalar__: "json";
61
- }
62
- type SingleFieldType = Int | Float | StringConstructor | BooleanConstructor | ID | DateConstructor | JSON | Type | GraphQLJSON | GraphQLUpload;
63
-
64
- type ReturnType<T extends SingleFieldType = SingleFieldType> = (of?: any) => T | [T] | [[T]] | Map<string, any>;
65
-
66
- declare const ssoTypes: readonly ["github", "google", "facebook", "apple", "naver", "kakao"];
67
- type SSOType = (typeof ssoTypes)[number];
68
- declare const argTypes: readonly ["Body", "Param", "Query", "Upload", "Msg", "Room"];
69
- type ArgType = (typeof argTypes)[number];
70
- interface ArgsOption {
71
- nullable?: boolean;
72
- example?: string | number | boolean | Dayjs;
73
- enum?: Enum<string | number>;
74
- }
75
- interface ArgMeta {
76
- name: string;
77
- returns: ReturnType;
78
- argsOption: ArgsOption;
79
- key: string;
80
- idx: number;
81
- type: ArgType;
82
- }
83
- declare const Account: (option?: {
84
- nullable?: boolean;
85
- }) => (prototype: object, key: string, idx: number) => void;
86
- type Account<AddData = unknown> = {
87
- __InternalArg__: "Account";
88
- self?: Self;
89
- me?: Me;
90
- appName: string;
91
- environment: Environment;
92
- } & AddData;
93
- declare const Self: (option?: {
94
- nullable?: boolean;
95
- }) => (prototype: object, key: string, idx: number) => void;
96
- interface Self {
97
- __InternalArg__: "Self";
98
- id: string;
99
- nickname: string;
100
- roles: string[];
101
- image: {
102
- url: string;
103
- imageSize: [number, number];
104
- } | null;
105
- profileStatus: "active" | "prepare" | "applied" | "approved" | "reapplied" | "featured" | "reserved" | "rejected";
106
- status: "prepare" | "active" | "restricted" | "dormant";
107
- removedAt: Dayjs | null;
108
- }
109
- declare const Me: (option?: {
110
- nullable?: boolean;
111
- }) => (prototype: object, key: string, idx: number) => void;
112
- interface Me {
113
- __InternalArg__: "Me";
114
- id: string;
115
- accountId: string;
116
- roles: string[];
117
- status: "active";
118
- removedAt: Dayjs | null;
119
- }
120
-
121
- export { Account as A, type SSOType as S, type Type as T, type ArgMeta as a };
package/src/authGuards.js DELETED
@@ -1,193 +0,0 @@
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var authGuards_exports = {};
30
- __export(authGuards_exports, {
31
- Admin: () => Admin,
32
- Every: () => Every,
33
- None: () => None,
34
- Owner: () => Owner,
35
- Public: () => Public,
36
- SuperAdmin: () => SuperAdmin,
37
- User: () => User,
38
- getArgs: () => getArgs,
39
- getRequest: () => getRequest,
40
- getResponse: () => getResponse,
41
- getSocket: () => getSocket
42
- });
43
- module.exports = __toCommonJS(authGuards_exports);
44
- var import_common = require("@nestjs/common");
45
- var import_graphql = require("@nestjs/graphql");
46
- var Auth = __toESM(require("./authorization"));
47
- function _ts_decorate(decorators, target, key, desc) {
48
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
49
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
50
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
51
- return c > 3 && r && Object.defineProperty(target, key, r), r;
52
- }
53
- __name(_ts_decorate, "_ts_decorate");
54
- const getRequest = /* @__PURE__ */ __name((context) => {
55
- const type = context.getType();
56
- if (type === "ws") throw new Error("Getting Request in Websocket is not allowed");
57
- return type === "http" ? context.switchToHttp().getRequest() : import_graphql.GqlExecutionContext.create(context).getContext().req;
58
- }, "getRequest");
59
- const getResponse = /* @__PURE__ */ __name((context) => {
60
- const type = context.getType();
61
- if (type === "ws") throw new Error("Getting Response in Websocket is not allowed");
62
- return type === "http" ? context.switchToHttp().getResponse() : import_graphql.GqlExecutionContext.create(context).getContext().req.res;
63
- }, "getResponse");
64
- const getArgs = /* @__PURE__ */ __name((context) => {
65
- const type = context.getType();
66
- if (type === "ws") throw new Error("Getting Args in Websocket is not allowed");
67
- if (type === "graphql") return import_graphql.GqlExecutionContext.create(context).getArgs();
68
- else if (type === "http") {
69
- const { params, query, body } = context.switchToHttp().getRequest();
70
- return {
71
- ...params,
72
- ...query,
73
- ...body
74
- };
75
- } else throw new Error("Getting Args in Unknown context is not allowed");
76
- }, "getArgs");
77
- const getSocket = /* @__PURE__ */ __name((context) => {
78
- const type = context.getType();
79
- if (type !== "ws") throw new Error("Getting Socket in Http or GraphQL is not allowed");
80
- const socket = context.getArgByIndex(0);
81
- return socket;
82
- }, "getSocket");
83
- class Public {
84
- static {
85
- __name(this, "Public");
86
- }
87
- canActivate(context) {
88
- return true;
89
- }
90
- }
91
- Public = _ts_decorate([
92
- (0, import_common.Injectable)()
93
- ], Public);
94
- class None {
95
- static {
96
- __name(this, "None");
97
- }
98
- canActivate() {
99
- return false;
100
- }
101
- }
102
- None = _ts_decorate([
103
- (0, import_common.Injectable)()
104
- ], None);
105
- class Every {
106
- static {
107
- __name(this, "Every");
108
- }
109
- canActivate(context) {
110
- const { account } = getRequest(context);
111
- return Auth.allow(account, [
112
- "user",
113
- "admin",
114
- "superAdmin"
115
- ]);
116
- }
117
- }
118
- Every = _ts_decorate([
119
- (0, import_common.Injectable)()
120
- ], Every);
121
- class Owner {
122
- static {
123
- __name(this, "Owner");
124
- }
125
- canActivate(context) {
126
- const { account } = getRequest(context);
127
- return Auth.allow(account, [
128
- "user",
129
- "admin",
130
- "superAdmin"
131
- ]);
132
- }
133
- }
134
- Owner = _ts_decorate([
135
- (0, import_common.Injectable)()
136
- ], Owner);
137
- class Admin {
138
- static {
139
- __name(this, "Admin");
140
- }
141
- canActivate(context) {
142
- const { account } = getRequest(context);
143
- return Auth.allow(account, [
144
- "admin",
145
- "superAdmin"
146
- ]);
147
- }
148
- }
149
- Admin = _ts_decorate([
150
- (0, import_common.Injectable)()
151
- ], Admin);
152
- class SuperAdmin {
153
- static {
154
- __name(this, "SuperAdmin");
155
- }
156
- canActivate(context) {
157
- const { account } = getRequest(context);
158
- return Auth.allow(account, [
159
- "superAdmin"
160
- ]);
161
- }
162
- }
163
- SuperAdmin = _ts_decorate([
164
- (0, import_common.Injectable)()
165
- ], SuperAdmin);
166
- class User {
167
- static {
168
- __name(this, "User");
169
- }
170
- canActivate(context) {
171
- const { account } = getRequest(context);
172
- return Auth.allow(account, [
173
- "user"
174
- ]);
175
- }
176
- }
177
- User = _ts_decorate([
178
- (0, import_common.Injectable)()
179
- ], User);
180
- // Annotate the CommonJS export names for ESM import in node:
181
- 0 && (module.exports = {
182
- Admin,
183
- Every,
184
- None,
185
- Owner,
186
- Public,
187
- SuperAdmin,
188
- User,
189
- getArgs,
190
- getRequest,
191
- getResponse,
192
- getSocket
193
- });
@@ -1,119 +0,0 @@
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var authentication_exports = {};
30
- __export(authentication_exports, {
31
- Access: () => Access,
32
- Account: () => Account,
33
- Me: () => Me,
34
- Req: () => Req,
35
- Res: () => Res,
36
- Self: () => Self,
37
- UserIp: () => UserIp,
38
- Ws: () => Ws
39
- });
40
- module.exports = __toCommonJS(authentication_exports);
41
- var import_base = require("@akanjs/base");
42
- var import_common = require("@nestjs/common");
43
- var import_ua_parser_js = __toESM(require("ua-parser-js"));
44
- var import_authGuards = require("./authGuards");
45
- const Account = (0, import_common.createParamDecorator)((option, context) => {
46
- const { account } = (0, import_authGuards.getRequest)(context);
47
- return account;
48
- });
49
- const Self = (0, import_common.createParamDecorator)((option, context) => {
50
- const { account } = (0, import_authGuards.getRequest)(context);
51
- const self = account.self;
52
- if (!self && !option.nullable) 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) throw new import_common.UnauthorizedException("No or Invalid Account in Me (Admin)");
59
- return me;
60
- });
61
- const UserIp = (0, import_common.createParamDecorator)((option, context) => {
62
- const req = (0, import_authGuards.getRequest)(context);
63
- const ip = req.ip;
64
- if (!ip && !option.nullable) throw new import_common.UnauthorizedException("Invalid IP");
65
- return {
66
- ip
67
- };
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) throw new import_common.UnauthorizedException("Invalid UserAgent");
73
- return {
74
- ...req.geolocation ? JSON.parse(req.geolocation) : {},
75
- osName: res.os.name,
76
- osVersion: res.os.version,
77
- browserName: res.browser.name,
78
- browserVersion: res.browser.version,
79
- mobileModel: res.device.model,
80
- mobileVendor: res.device.vendor,
81
- deviceType: res.device.type ?? "desktop",
82
- at: (0, import_base.dayjs)(),
83
- period: 0
84
- };
85
- });
86
- const Req = (0, import_common.createParamDecorator)((option, context) => {
87
- return (0, import_authGuards.getRequest)(context);
88
- });
89
- const Res = (0, import_common.createParamDecorator)((option, context) => {
90
- return (0, import_authGuards.getResponse)(context);
91
- });
92
- const Ws = (0, import_common.createParamDecorator)((option, context) => {
93
- const socket = context.getArgByIndex(0);
94
- const { __subscribe__ } = context.getArgByIndex(1);
95
- return {
96
- socket,
97
- subscribe: __subscribe__,
98
- onDisconnect: /* @__PURE__ */ __name((handler) => {
99
- socket.on("disconnect", handler);
100
- }, "onDisconnect"),
101
- onSubscribe: /* @__PURE__ */ __name((handler) => {
102
- if (__subscribe__) handler();
103
- }, "onSubscribe"),
104
- onUnsubscribe: /* @__PURE__ */ __name((handler) => {
105
- if (!__subscribe__) handler();
106
- }, "onUnsubscribe")
107
- };
108
- });
109
- // Annotate the CommonJS export names for ESM import in node:
110
- 0 && (module.exports = {
111
- Access,
112
- Account,
113
- Me,
114
- Req,
115
- Res,
116
- Self,
117
- UserIp,
118
- Ws
119
- });
@@ -1,75 +0,0 @@
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var authorization_exports = {};
30
- __export(authorization_exports, {
31
- allow: () => allow,
32
- verifyToken: () => verifyToken
33
- });
34
- module.exports = __toCommonJS(authorization_exports);
35
- var import_base = require("@akanjs/base");
36
- var import_signal = require("@akanjs/signal");
37
- var import_apollo = require("@nestjs/apollo");
38
- var jwt = __toESM(require("jsonwebtoken"));
39
- const verifyToken = /* @__PURE__ */ __name((secret, authorization) => {
40
- const [type, token] = authorization?.split(" ") ?? [
41
- void 0,
42
- void 0
43
- ];
44
- if (!token || type !== "Bearer") return import_signal.defaultAccount;
45
- try {
46
- const account = jwt.verify(token, secret);
47
- if (account.appName !== import_base.baseEnv.appName || account.environment !== import_base.baseEnv.environment) return import_signal.defaultAccount;
48
- return {
49
- __InternalArg__: "Account",
50
- self: account.self && !account.self.removedAt ? account.self : void 0,
51
- me: account.me && !account.me.removedAt ? account.me : void 0,
52
- appName: account.appName,
53
- environment: account.environment
54
- };
55
- } catch (e) {
56
- return import_signal.defaultAccount;
57
- }
58
- }, "verifyToken");
59
- const allow = /* @__PURE__ */ __name((account, roles, userId) => {
60
- if (!account) throw new import_apollo.AuthenticationError("No Authentication Account");
61
- for (const role of roles) {
62
- if (role === "user" && account.self?.roles.includes("user")) return true;
63
- else if (role === "admin" && account.me?.roles.includes("admin")) return true;
64
- else if (role === "superAdmin" && account.me?.roles.includes("superAdmin")) return true;
65
- }
66
- throw new import_apollo.AuthenticationError(`No Authentication With Roles: ${roles.join(", ")}, Your roles are ${[
67
- ...account.self?.roles ?? [],
68
- ...account.me?.roles ?? []
69
- ].join(", ")}${!account.self?.roles.length && !account.me?.roles.length ? " (No Roles)" : ""}`);
70
- }, "allow");
71
- // Annotate the CommonJS export names for ESM import in node:
72
- 0 && (module.exports = {
73
- allow,
74
- verifyToken
75
- });