@akanjs/nest 0.0.98 → 0.0.100
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/index.js +21 -1
- package/index.mjs +1 -0
- package/package.json +2 -2
- package/src/authGuards.js +56 -15
- package/src/{authGuards.cjs → authGuards.mjs} +15 -56
- package/src/authentication.js +67 -27
- package/src/authentication.mjs +82 -0
- package/src/authorization.js +46 -12
- package/src/authorization.mjs +45 -0
- package/src/cacheClient.js +26 -5
- package/src/cacheClient.mjs +24 -0
- package/src/databaseClient.js +29 -8
- package/src/databaseClient.mjs +30 -0
- package/src/decorators.js +33 -6
- package/src/{decorators.cjs → decorators.mjs} +6 -33
- package/src/exceptions.js +29 -8
- package/src/{exceptions.cjs → exceptions.mjs} +8 -29
- package/src/exporter.js +40 -3
- package/src/{exporter.cjs → exporter.mjs} +3 -40
- package/src/generateSecrets.js +43 -13
- package/src/{generateSecrets.cjs → generateSecrets.mjs} +13 -43
- package/src/index.js +72 -21
- package/src/index.mjs +22 -0
- package/src/interceptors.js +55 -36
- package/src/{interceptors.cjs → interceptors.mjs} +36 -55
- package/src/mongoose.js +44 -11
- package/src/mongoose.mjs +60 -0
- package/src/pipes.js +51 -22
- package/src/{pipes.cjs → pipes.mjs} +22 -51
- package/src/redis-io.adapter.js +35 -12
- package/src/redis-io.adapter.mjs +61 -0
- package/src/searchClient.js +28 -7
- package/src/{searchClient.cjs → searchClient.mjs} +7 -28
- package/src/sso.js +56 -24
- package/src/{sso.cjs → sso.mjs} +24 -56
- package/src/verifyPayment.js +37 -4
- package/src/verifyPayment.mjs +17 -0
- package/index.cjs +0 -21
- package/src/authentication.cjs +0 -122
- package/src/authorization.cjs +0 -79
- package/src/cacheClient.cjs +0 -45
- package/src/databaseClient.cjs +0 -51
- package/src/index.cjs +0 -73
- package/src/mongoose.cjs +0 -93
- package/src/redis-io.adapter.cjs +0 -84
- package/src/verifyPayment.cjs +0 -50
package/index.js
CHANGED
|
@@ -1 +1,21 @@
|
|
|
1
|
-
|
|
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/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src";
|
package/package.json
CHANGED
package/src/authGuards.js
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
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);
|
|
3
28
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
29
|
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
30
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
@@ -9,27 +34,42 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
9
34
|
__defProp(target, key, result);
|
|
10
35
|
return result;
|
|
11
36
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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"));
|
|
15
55
|
const getRequest = (context) => {
|
|
16
56
|
const type = context.getType();
|
|
17
57
|
if (type === "ws")
|
|
18
58
|
throw new Error("Getting Request in Websocket is not allowed");
|
|
19
|
-
return type === "http" ? context.switchToHttp().getRequest() : GqlExecutionContext.create(context).getContext().req;
|
|
59
|
+
return type === "http" ? context.switchToHttp().getRequest() : import_graphql.GqlExecutionContext.create(context).getContext().req;
|
|
20
60
|
};
|
|
21
61
|
const getResponse = (context) => {
|
|
22
62
|
const type = context.getType();
|
|
23
63
|
if (type === "ws")
|
|
24
64
|
throw new Error("Getting Response in Websocket is not allowed");
|
|
25
|
-
return type === "http" ? context.switchToHttp().getResponse() : GqlExecutionContext.create(context).getContext().req.res;
|
|
65
|
+
return type === "http" ? context.switchToHttp().getResponse() : import_graphql.GqlExecutionContext.create(context).getContext().req.res;
|
|
26
66
|
};
|
|
27
67
|
const getArgs = (context) => {
|
|
28
68
|
const type = context.getType();
|
|
29
69
|
if (type === "ws")
|
|
30
70
|
throw new Error("Getting Args in Websocket is not allowed");
|
|
31
71
|
if (type === "graphql")
|
|
32
|
-
return GqlExecutionContext.create(context).getArgs();
|
|
72
|
+
return import_graphql.GqlExecutionContext.create(context).getArgs();
|
|
33
73
|
else if (type === "http") {
|
|
34
74
|
const { params, query, body } = context.switchToHttp().getRequest();
|
|
35
75
|
return { ...params, ...query, ...body };
|
|
@@ -49,7 +89,7 @@ let Public = class {
|
|
|
49
89
|
}
|
|
50
90
|
};
|
|
51
91
|
Public = __decorateClass([
|
|
52
|
-
Injectable()
|
|
92
|
+
(0, import_common.Injectable)()
|
|
53
93
|
], Public);
|
|
54
94
|
let None = class {
|
|
55
95
|
canActivate() {
|
|
@@ -57,7 +97,7 @@ let None = class {
|
|
|
57
97
|
}
|
|
58
98
|
};
|
|
59
99
|
None = __decorateClass([
|
|
60
|
-
Injectable()
|
|
100
|
+
(0, import_common.Injectable)()
|
|
61
101
|
], None);
|
|
62
102
|
let Every = class {
|
|
63
103
|
canActivate(context) {
|
|
@@ -66,7 +106,7 @@ let Every = class {
|
|
|
66
106
|
}
|
|
67
107
|
};
|
|
68
108
|
Every = __decorateClass([
|
|
69
|
-
Injectable()
|
|
109
|
+
(0, import_common.Injectable)()
|
|
70
110
|
], Every);
|
|
71
111
|
let Owner = class {
|
|
72
112
|
canActivate(context) {
|
|
@@ -75,7 +115,7 @@ let Owner = class {
|
|
|
75
115
|
}
|
|
76
116
|
};
|
|
77
117
|
Owner = __decorateClass([
|
|
78
|
-
Injectable()
|
|
118
|
+
(0, import_common.Injectable)()
|
|
79
119
|
], Owner);
|
|
80
120
|
let Admin = class {
|
|
81
121
|
canActivate(context) {
|
|
@@ -84,7 +124,7 @@ let Admin = class {
|
|
|
84
124
|
}
|
|
85
125
|
};
|
|
86
126
|
Admin = __decorateClass([
|
|
87
|
-
Injectable()
|
|
127
|
+
(0, import_common.Injectable)()
|
|
88
128
|
], Admin);
|
|
89
129
|
let SuperAdmin = class {
|
|
90
130
|
canActivate(context) {
|
|
@@ -93,7 +133,7 @@ let SuperAdmin = class {
|
|
|
93
133
|
}
|
|
94
134
|
};
|
|
95
135
|
SuperAdmin = __decorateClass([
|
|
96
|
-
Injectable()
|
|
136
|
+
(0, import_common.Injectable)()
|
|
97
137
|
], SuperAdmin);
|
|
98
138
|
let User = class {
|
|
99
139
|
canActivate(context) {
|
|
@@ -102,9 +142,10 @@ let User = class {
|
|
|
102
142
|
}
|
|
103
143
|
};
|
|
104
144
|
User = __decorateClass([
|
|
105
|
-
Injectable()
|
|
145
|
+
(0, import_common.Injectable)()
|
|
106
146
|
], User);
|
|
107
|
-
export
|
|
147
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
148
|
+
0 && (module.exports = {
|
|
108
149
|
Admin,
|
|
109
150
|
Every,
|
|
110
151
|
None,
|
|
@@ -116,4 +157,4 @@ export {
|
|
|
116
157
|
getRequest,
|
|
117
158
|
getResponse,
|
|
118
159
|
getSocket
|
|
119
|
-
};
|
|
160
|
+
});
|
|
@@ -1,30 +1,5 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
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
3
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
29
4
|
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
30
5
|
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
@@ -34,42 +9,27 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
34
9
|
__defProp(target, key, result);
|
|
35
10
|
return result;
|
|
36
11
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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"), 1);
|
|
12
|
+
import { Injectable } from "@nestjs/common";
|
|
13
|
+
import { GqlExecutionContext } from "@nestjs/graphql";
|
|
14
|
+
import * as Auth from "./authorization";
|
|
55
15
|
const getRequest = (context) => {
|
|
56
16
|
const type = context.getType();
|
|
57
17
|
if (type === "ws")
|
|
58
18
|
throw new Error("Getting Request in Websocket is not allowed");
|
|
59
|
-
return type === "http" ? context.switchToHttp().getRequest() :
|
|
19
|
+
return type === "http" ? context.switchToHttp().getRequest() : GqlExecutionContext.create(context).getContext().req;
|
|
60
20
|
};
|
|
61
21
|
const getResponse = (context) => {
|
|
62
22
|
const type = context.getType();
|
|
63
23
|
if (type === "ws")
|
|
64
24
|
throw new Error("Getting Response in Websocket is not allowed");
|
|
65
|
-
return type === "http" ? context.switchToHttp().getResponse() :
|
|
25
|
+
return type === "http" ? context.switchToHttp().getResponse() : GqlExecutionContext.create(context).getContext().req.res;
|
|
66
26
|
};
|
|
67
27
|
const getArgs = (context) => {
|
|
68
28
|
const type = context.getType();
|
|
69
29
|
if (type === "ws")
|
|
70
30
|
throw new Error("Getting Args in Websocket is not allowed");
|
|
71
31
|
if (type === "graphql")
|
|
72
|
-
return
|
|
32
|
+
return GqlExecutionContext.create(context).getArgs();
|
|
73
33
|
else if (type === "http") {
|
|
74
34
|
const { params, query, body } = context.switchToHttp().getRequest();
|
|
75
35
|
return { ...params, ...query, ...body };
|
|
@@ -89,7 +49,7 @@ let Public = class {
|
|
|
89
49
|
}
|
|
90
50
|
};
|
|
91
51
|
Public = __decorateClass([
|
|
92
|
-
|
|
52
|
+
Injectable()
|
|
93
53
|
], Public);
|
|
94
54
|
let None = class {
|
|
95
55
|
canActivate() {
|
|
@@ -97,7 +57,7 @@ let None = class {
|
|
|
97
57
|
}
|
|
98
58
|
};
|
|
99
59
|
None = __decorateClass([
|
|
100
|
-
|
|
60
|
+
Injectable()
|
|
101
61
|
], None);
|
|
102
62
|
let Every = class {
|
|
103
63
|
canActivate(context) {
|
|
@@ -106,7 +66,7 @@ let Every = class {
|
|
|
106
66
|
}
|
|
107
67
|
};
|
|
108
68
|
Every = __decorateClass([
|
|
109
|
-
|
|
69
|
+
Injectable()
|
|
110
70
|
], Every);
|
|
111
71
|
let Owner = class {
|
|
112
72
|
canActivate(context) {
|
|
@@ -115,7 +75,7 @@ let Owner = class {
|
|
|
115
75
|
}
|
|
116
76
|
};
|
|
117
77
|
Owner = __decorateClass([
|
|
118
|
-
|
|
78
|
+
Injectable()
|
|
119
79
|
], Owner);
|
|
120
80
|
let Admin = class {
|
|
121
81
|
canActivate(context) {
|
|
@@ -124,7 +84,7 @@ let Admin = class {
|
|
|
124
84
|
}
|
|
125
85
|
};
|
|
126
86
|
Admin = __decorateClass([
|
|
127
|
-
|
|
87
|
+
Injectable()
|
|
128
88
|
], Admin);
|
|
129
89
|
let SuperAdmin = class {
|
|
130
90
|
canActivate(context) {
|
|
@@ -133,7 +93,7 @@ let SuperAdmin = class {
|
|
|
133
93
|
}
|
|
134
94
|
};
|
|
135
95
|
SuperAdmin = __decorateClass([
|
|
136
|
-
|
|
96
|
+
Injectable()
|
|
137
97
|
], SuperAdmin);
|
|
138
98
|
let User = class {
|
|
139
99
|
canActivate(context) {
|
|
@@ -142,10 +102,9 @@ let User = class {
|
|
|
142
102
|
}
|
|
143
103
|
};
|
|
144
104
|
User = __decorateClass([
|
|
145
|
-
|
|
105
|
+
Injectable()
|
|
146
106
|
], User);
|
|
147
|
-
|
|
148
|
-
0 && (module.exports = {
|
|
107
|
+
export {
|
|
149
108
|
Admin,
|
|
150
109
|
Every,
|
|
151
110
|
None,
|
|
@@ -157,4 +116,4 @@ User = __decorateClass([
|
|
|
157
116
|
getRequest,
|
|
158
117
|
getResponse,
|
|
159
118
|
getSocket
|
|
160
|
-
}
|
|
119
|
+
};
|
package/src/authentication.js
CHANGED
|
@@ -1,37 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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);
|
|
7
46
|
return account;
|
|
8
47
|
});
|
|
9
|
-
const Self = createParamDecorator((option, context) => {
|
|
10
|
-
const { account } = getRequest(context);
|
|
48
|
+
const Self = (0, import_common.createParamDecorator)((option, context) => {
|
|
49
|
+
const { account } = (0, import_authGuards.getRequest)(context);
|
|
11
50
|
const self = account.self;
|
|
12
51
|
if (!self && !option.nullable)
|
|
13
|
-
throw new UnauthorizedException("No or Invalid Account in Self (User)");
|
|
52
|
+
throw new import_common.UnauthorizedException("No or Invalid Account in Self (User)");
|
|
14
53
|
return self;
|
|
15
54
|
});
|
|
16
|
-
const Me = createParamDecorator((option, context) => {
|
|
17
|
-
const { account } = getRequest(context);
|
|
55
|
+
const Me = (0, import_common.createParamDecorator)((option, context) => {
|
|
56
|
+
const { account } = (0, import_authGuards.getRequest)(context);
|
|
18
57
|
const me = account.me;
|
|
19
58
|
if (!me && !option.nullable)
|
|
20
|
-
throw new UnauthorizedException("No or Invalid Account in Me (Admin)");
|
|
59
|
+
throw new import_common.UnauthorizedException("No or Invalid Account in Me (Admin)");
|
|
21
60
|
return me;
|
|
22
61
|
});
|
|
23
|
-
const UserIp = createParamDecorator((option, context) => {
|
|
24
|
-
const req = getRequest(context);
|
|
62
|
+
const UserIp = (0, import_common.createParamDecorator)((option, context) => {
|
|
63
|
+
const req = (0, import_authGuards.getRequest)(context);
|
|
25
64
|
const ip = req.ip;
|
|
26
65
|
if (!ip && !option.nullable)
|
|
27
|
-
throw new UnauthorizedException("Invalid IP");
|
|
66
|
+
throw new import_common.UnauthorizedException("Invalid IP");
|
|
28
67
|
return { ip };
|
|
29
68
|
});
|
|
30
|
-
const Access = createParamDecorator((option, context) => {
|
|
31
|
-
const req = getRequest(context);
|
|
32
|
-
const res = new
|
|
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();
|
|
33
72
|
if (!req.userAgent && !option.nullable)
|
|
34
|
-
throw new UnauthorizedException("Invalid UserAgent");
|
|
73
|
+
throw new import_common.UnauthorizedException("Invalid UserAgent");
|
|
35
74
|
return {
|
|
36
75
|
...req.geolocation ? JSON.parse(req.geolocation) : {},
|
|
37
76
|
osName: res.os.name,
|
|
@@ -41,17 +80,17 @@ const Access = createParamDecorator((option, context) => {
|
|
|
41
80
|
mobileModel: res.device.model,
|
|
42
81
|
mobileVendor: res.device.vendor,
|
|
43
82
|
deviceType: res.device.type ?? "desktop",
|
|
44
|
-
at: dayjs(),
|
|
83
|
+
at: (0, import_base.dayjs)(),
|
|
45
84
|
period: 0
|
|
46
85
|
};
|
|
47
86
|
});
|
|
48
|
-
const Req = createParamDecorator((option, context) => {
|
|
49
|
-
return getRequest(context);
|
|
87
|
+
const Req = (0, import_common.createParamDecorator)((option, context) => {
|
|
88
|
+
return (0, import_authGuards.getRequest)(context);
|
|
50
89
|
});
|
|
51
|
-
const Res = createParamDecorator((option, context) => {
|
|
52
|
-
return getResponse(context);
|
|
90
|
+
const Res = (0, import_common.createParamDecorator)((option, context) => {
|
|
91
|
+
return (0, import_authGuards.getResponse)(context);
|
|
53
92
|
});
|
|
54
|
-
const Ws = createParamDecorator((option, context) => {
|
|
93
|
+
const Ws = (0, import_common.createParamDecorator)((option, context) => {
|
|
55
94
|
const socket = context.getArgByIndex(0);
|
|
56
95
|
const { __subscribe__ } = context.getArgByIndex(1);
|
|
57
96
|
return {
|
|
@@ -70,7 +109,8 @@ const Ws = createParamDecorator((option, context) => {
|
|
|
70
109
|
}
|
|
71
110
|
};
|
|
72
111
|
});
|
|
73
|
-
export
|
|
112
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
113
|
+
0 && (module.exports = {
|
|
74
114
|
Access,
|
|
75
115
|
Account,
|
|
76
116
|
Me,
|
|
@@ -79,4 +119,4 @@ export {
|
|
|
79
119
|
Self,
|
|
80
120
|
UserIp,
|
|
81
121
|
Ws
|
|
82
|
-
};
|
|
122
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { dayjs } from "@akanjs/base";
|
|
2
|
+
import { createParamDecorator, UnauthorizedException } from "@nestjs/common";
|
|
3
|
+
import UAParser from "ua-parser-js";
|
|
4
|
+
import { getRequest, getResponse } from "./authGuards";
|
|
5
|
+
const Account = createParamDecorator((option, context) => {
|
|
6
|
+
const { account } = getRequest(context);
|
|
7
|
+
return account;
|
|
8
|
+
});
|
|
9
|
+
const Self = createParamDecorator((option, context) => {
|
|
10
|
+
const { account } = getRequest(context);
|
|
11
|
+
const self = account.self;
|
|
12
|
+
if (!self && !option.nullable)
|
|
13
|
+
throw new UnauthorizedException("No or Invalid Account in Self (User)");
|
|
14
|
+
return self;
|
|
15
|
+
});
|
|
16
|
+
const Me = createParamDecorator((option, context) => {
|
|
17
|
+
const { account } = getRequest(context);
|
|
18
|
+
const me = account.me;
|
|
19
|
+
if (!me && !option.nullable)
|
|
20
|
+
throw new UnauthorizedException("No or Invalid Account in Me (Admin)");
|
|
21
|
+
return me;
|
|
22
|
+
});
|
|
23
|
+
const UserIp = createParamDecorator((option, context) => {
|
|
24
|
+
const req = getRequest(context);
|
|
25
|
+
const ip = req.ip;
|
|
26
|
+
if (!ip && !option.nullable)
|
|
27
|
+
throw new UnauthorizedException("Invalid IP");
|
|
28
|
+
return { ip };
|
|
29
|
+
});
|
|
30
|
+
const Access = createParamDecorator((option, context) => {
|
|
31
|
+
const req = getRequest(context);
|
|
32
|
+
const res = new UAParser(req.userAgent).getResult();
|
|
33
|
+
if (!req.userAgent && !option.nullable)
|
|
34
|
+
throw new UnauthorizedException("Invalid UserAgent");
|
|
35
|
+
return {
|
|
36
|
+
...req.geolocation ? JSON.parse(req.geolocation) : {},
|
|
37
|
+
osName: res.os.name,
|
|
38
|
+
osVersion: res.os.version,
|
|
39
|
+
browserName: res.browser.name,
|
|
40
|
+
browserVersion: res.browser.version,
|
|
41
|
+
mobileModel: res.device.model,
|
|
42
|
+
mobileVendor: res.device.vendor,
|
|
43
|
+
deviceType: res.device.type ?? "desktop",
|
|
44
|
+
at: dayjs(),
|
|
45
|
+
period: 0
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
const Req = createParamDecorator((option, context) => {
|
|
49
|
+
return getRequest(context);
|
|
50
|
+
});
|
|
51
|
+
const Res = createParamDecorator((option, context) => {
|
|
52
|
+
return getResponse(context);
|
|
53
|
+
});
|
|
54
|
+
const Ws = createParamDecorator((option, context) => {
|
|
55
|
+
const socket = context.getArgByIndex(0);
|
|
56
|
+
const { __subscribe__ } = context.getArgByIndex(1);
|
|
57
|
+
return {
|
|
58
|
+
socket,
|
|
59
|
+
subscribe: __subscribe__,
|
|
60
|
+
onDisconnect: (handler) => {
|
|
61
|
+
socket.on("disconnect", handler);
|
|
62
|
+
},
|
|
63
|
+
onSubscribe: (handler) => {
|
|
64
|
+
if (__subscribe__)
|
|
65
|
+
handler();
|
|
66
|
+
},
|
|
67
|
+
onUnsubscribe: (handler) => {
|
|
68
|
+
if (!__subscribe__)
|
|
69
|
+
handler();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
export {
|
|
74
|
+
Access,
|
|
75
|
+
Account,
|
|
76
|
+
Me,
|
|
77
|
+
Req,
|
|
78
|
+
Res,
|
|
79
|
+
Self,
|
|
80
|
+
UserIp,
|
|
81
|
+
Ws
|
|
82
|
+
};
|
package/src/authorization.js
CHANGED
|
@@ -1,15 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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"));
|
|
5
38
|
const verifyToken = (secret, authorization) => {
|
|
6
39
|
const [type, token] = authorization?.split(" ") ?? [void 0, void 0];
|
|
7
40
|
if (!token || type !== "Bearer")
|
|
8
|
-
return defaultAccount;
|
|
41
|
+
return import_signal.defaultAccount;
|
|
9
42
|
try {
|
|
10
43
|
const account = jwt.verify(token, secret);
|
|
11
|
-
if (account.appName !== baseEnv.appName || account.environment !== baseEnv.environment)
|
|
12
|
-
return defaultAccount;
|
|
44
|
+
if (account.appName !== import_base.baseEnv.appName || account.environment !== import_base.baseEnv.environment)
|
|
45
|
+
return import_signal.defaultAccount;
|
|
13
46
|
return {
|
|
14
47
|
__InternalArg__: "Account",
|
|
15
48
|
self: account.self && !account.self.removedAt ? account.self : void 0,
|
|
@@ -18,12 +51,12 @@ const verifyToken = (secret, authorization) => {
|
|
|
18
51
|
environment: account.environment
|
|
19
52
|
};
|
|
20
53
|
} catch (e) {
|
|
21
|
-
return defaultAccount;
|
|
54
|
+
return import_signal.defaultAccount;
|
|
22
55
|
}
|
|
23
56
|
};
|
|
24
57
|
const allow = (account, roles, userId) => {
|
|
25
58
|
if (!account)
|
|
26
|
-
throw new AuthenticationError("No Authentication Account");
|
|
59
|
+
throw new import_apollo.AuthenticationError("No Authentication Account");
|
|
27
60
|
for (const role of roles) {
|
|
28
61
|
if (role === "user" && account.self?.roles.includes("user"))
|
|
29
62
|
return true;
|
|
@@ -32,14 +65,15 @@ const allow = (account, roles, userId) => {
|
|
|
32
65
|
else if (role === "superAdmin" && account.me?.roles.includes("superAdmin"))
|
|
33
66
|
return true;
|
|
34
67
|
}
|
|
35
|
-
throw new AuthenticationError(
|
|
68
|
+
throw new import_apollo.AuthenticationError(
|
|
36
69
|
`No Authentication With Roles: ${roles.join(", ")}, Your roles are ${[
|
|
37
70
|
...account.self?.roles ?? [],
|
|
38
71
|
...account.me?.roles ?? []
|
|
39
72
|
].join(", ")}${!account.self?.roles.length && !account.me?.roles.length ? " (No Roles)" : ""}`
|
|
40
73
|
);
|
|
41
74
|
};
|
|
42
|
-
export
|
|
75
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
76
|
+
0 && (module.exports = {
|
|
43
77
|
allow,
|
|
44
78
|
verifyToken
|
|
45
|
-
};
|
|
79
|
+
});
|