@akanjs/nest 0.9.56 → 0.9.58-canary.0
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/cjs/src/authorization.js +51 -36
- package/cjs/src/guards.js +40 -0
- package/cjs/src/index.js +8 -13
- package/cjs/src/interceptors.js +3 -3
- package/cjs/src/internalParams.js +80 -0
- package/esm/src/authorization.js +46 -34
- package/esm/src/guards.js +16 -0
- package/esm/src/index.js +4 -7
- package/esm/src/interceptors.js +1 -1
- package/esm/src/internalParams.js +54 -0
- package/package.json +1 -1
- package/src/authorization.d.ts +28 -3
- package/src/guards.d.ts +10 -0
- package/src/index.d.ts +3 -5
- package/src/internalParams.d.ts +27 -0
- package/cjs/src/authGuards.js +0 -160
- package/cjs/src/authentication.js +0 -122
- package/cjs/src/sso.js +0 -187
- package/cjs/src/verifyPayment.js +0 -50
- package/esm/src/authGuards.js +0 -119
- package/esm/src/authentication.js +0 -82
- package/esm/src/sso.js +0 -155
- package/esm/src/verifyPayment.js +0 -17
- package/src/authGuards.d.ts +0 -51
- package/src/authentication.d.ts +0 -18
- package/src/sso.d.ts +0 -75
- package/src/verifyPayment.d.ts +0 -11
package/cjs/src/authorization.js
CHANGED
|
@@ -27,53 +27,68 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
28
|
var authorization_exports = {};
|
|
29
29
|
__export(authorization_exports, {
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
getArgs: () => getArgs,
|
|
31
|
+
getRequest: () => getRequest,
|
|
32
|
+
getResponse: () => getResponse,
|
|
33
|
+
getSocket: () => getSocket,
|
|
34
|
+
resolveJwt: () => resolveJwt
|
|
32
35
|
});
|
|
33
36
|
module.exports = __toCommonJS(authorization_exports);
|
|
34
37
|
var import_base = require("@akanjs/base");
|
|
35
|
-
var
|
|
36
|
-
var
|
|
38
|
+
var import_common = require("@akanjs/common");
|
|
39
|
+
var import_graphql = require("@nestjs/graphql");
|
|
37
40
|
var jwt = __toESM(require("jsonwebtoken"));
|
|
38
|
-
const
|
|
41
|
+
const resolveJwt = (secret, authorization, defaultResolved) => {
|
|
39
42
|
const [type, token] = authorization?.split(" ") ?? [void 0, void 0];
|
|
40
43
|
if (!token || type !== "Bearer")
|
|
41
|
-
return
|
|
44
|
+
return defaultResolved;
|
|
42
45
|
try {
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
45
|
-
return
|
|
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
|
-
};
|
|
46
|
+
const resolved = jwt.verify(token, secret);
|
|
47
|
+
if (resolved.appName !== import_base.baseEnv.appName || resolved.environment !== import_base.baseEnv.environment)
|
|
48
|
+
return defaultResolved;
|
|
49
|
+
return resolved;
|
|
53
50
|
} catch (e) {
|
|
54
|
-
|
|
51
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
52
|
+
import_common.Logger.error(`failed to verify token for ${authorization}: ${message}`);
|
|
53
|
+
return defaultResolved;
|
|
55
54
|
}
|
|
56
55
|
};
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
)
|
|
56
|
+
const getRequest = (context) => {
|
|
57
|
+
const type = context.getType();
|
|
58
|
+
if (type === "ws")
|
|
59
|
+
throw new Error("Getting Request in Websocket is not allowed");
|
|
60
|
+
return type === "http" ? context.switchToHttp().getRequest() : import_graphql.GqlExecutionContext.create(context).getContext().req;
|
|
61
|
+
};
|
|
62
|
+
const getResponse = (context) => {
|
|
63
|
+
const type = context.getType();
|
|
64
|
+
if (type === "ws")
|
|
65
|
+
throw new Error("Getting Response in Websocket is not allowed");
|
|
66
|
+
return type === "http" ? context.switchToHttp().getResponse() : import_graphql.GqlExecutionContext.create(context).getContext().req.res;
|
|
67
|
+
};
|
|
68
|
+
const getArgs = (context) => {
|
|
69
|
+
const type = context.getType();
|
|
70
|
+
if (type === "ws")
|
|
71
|
+
throw new Error("Getting Args in Websocket is not allowed");
|
|
72
|
+
if (type === "graphql")
|
|
73
|
+
return import_graphql.GqlExecutionContext.create(context).getArgs();
|
|
74
|
+
else if (type === "http") {
|
|
75
|
+
const { params, query, body } = context.switchToHttp().getRequest();
|
|
76
|
+
return { ...params, ...query, ...body };
|
|
77
|
+
} else
|
|
78
|
+
throw new Error("Getting Args in Unknown context is not allowed");
|
|
79
|
+
};
|
|
80
|
+
const getSocket = (context) => {
|
|
81
|
+
const type = context.getType();
|
|
82
|
+
if (type !== "ws")
|
|
83
|
+
throw new Error("Getting Socket in Http or GraphQL is not allowed");
|
|
84
|
+
const socket = context.getArgByIndex(0);
|
|
85
|
+
return socket;
|
|
74
86
|
};
|
|
75
87
|
// Annotate the CommonJS export names for ESM import in node:
|
|
76
88
|
0 && (module.exports = {
|
|
77
|
-
|
|
78
|
-
|
|
89
|
+
getArgs,
|
|
90
|
+
getRequest,
|
|
91
|
+
getResponse,
|
|
92
|
+
getSocket,
|
|
93
|
+
resolveJwt
|
|
79
94
|
});
|
|
@@ -0,0 +1,40 @@
|
|
|
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 guards_exports = {};
|
|
19
|
+
__export(guards_exports, {
|
|
20
|
+
None: () => None,
|
|
21
|
+
Public: () => Public
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(guards_exports);
|
|
24
|
+
class Public {
|
|
25
|
+
static name = "Public";
|
|
26
|
+
canActivate(context) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
class None {
|
|
31
|
+
static name = "None";
|
|
32
|
+
canActivate(context) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
None,
|
|
39
|
+
Public
|
|
40
|
+
});
|
package/cjs/src/index.js
CHANGED
|
@@ -28,21 +28,16 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var src_exports = {};
|
|
30
30
|
__export(src_exports, {
|
|
31
|
-
Exporter: () => Exporter
|
|
32
|
-
guards: () => guards
|
|
31
|
+
Exporter: () => Exporter
|
|
33
32
|
});
|
|
34
33
|
module.exports = __toCommonJS(src_exports);
|
|
35
34
|
__reExport(src_exports, require("./authorization"), module.exports);
|
|
36
|
-
__reExport(src_exports, require("./
|
|
37
|
-
var guards = __toESM(require("./authGuards"));
|
|
38
|
-
__reExport(src_exports, require("./authentication"), module.exports);
|
|
35
|
+
__reExport(src_exports, require("./guards"), module.exports);
|
|
39
36
|
__reExport(src_exports, require("./interceptors"), module.exports);
|
|
40
37
|
__reExport(src_exports, require("./redis-io.adapter"), module.exports);
|
|
41
38
|
__reExport(src_exports, require("./pipes"), module.exports);
|
|
42
39
|
var Exporter = __toESM(require("./exporter"));
|
|
43
40
|
__reExport(src_exports, require("./exporter"), module.exports);
|
|
44
|
-
__reExport(src_exports, require("./verifyPayment"), module.exports);
|
|
45
|
-
__reExport(src_exports, require("./sso"), module.exports);
|
|
46
41
|
__reExport(src_exports, require("./exceptions"), module.exports);
|
|
47
42
|
__reExport(src_exports, require("./generateSecrets"), module.exports);
|
|
48
43
|
__reExport(src_exports, require("./mongoose"), module.exports);
|
|
@@ -50,24 +45,24 @@ __reExport(src_exports, require("./searchClient"), module.exports);
|
|
|
50
45
|
__reExport(src_exports, require("./cacheClient"), module.exports);
|
|
51
46
|
__reExport(src_exports, require("./databaseClient"), module.exports);
|
|
52
47
|
__reExport(src_exports, require("./decorators"), module.exports);
|
|
48
|
+
__reExport(src_exports, require("./internalParams"), module.exports);
|
|
49
|
+
__reExport(src_exports, require("./guards"), module.exports);
|
|
53
50
|
// Annotate the CommonJS export names for ESM import in node:
|
|
54
51
|
0 && (module.exports = {
|
|
55
52
|
Exporter,
|
|
56
|
-
guards,
|
|
57
53
|
...require("./authorization"),
|
|
58
|
-
...require("./
|
|
59
|
-
...require("./authentication"),
|
|
54
|
+
...require("./guards"),
|
|
60
55
|
...require("./interceptors"),
|
|
61
56
|
...require("./redis-io.adapter"),
|
|
62
57
|
...require("./pipes"),
|
|
63
58
|
...require("./exporter"),
|
|
64
|
-
...require("./verifyPayment"),
|
|
65
|
-
...require("./sso"),
|
|
66
59
|
...require("./exceptions"),
|
|
67
60
|
...require("./generateSecrets"),
|
|
68
61
|
...require("./mongoose"),
|
|
69
62
|
...require("./searchClient"),
|
|
70
63
|
...require("./cacheClient"),
|
|
71
64
|
...require("./databaseClient"),
|
|
72
|
-
...require("./decorators")
|
|
65
|
+
...require("./decorators"),
|
|
66
|
+
...require("./internalParams"),
|
|
67
|
+
...require("./guards")
|
|
73
68
|
});
|
package/cjs/src/interceptors.js
CHANGED
|
@@ -55,7 +55,7 @@ var import_common2 = require("@nestjs/common");
|
|
|
55
55
|
var import_graphql = require("@nestjs/graphql");
|
|
56
56
|
var import_rxjs = require("rxjs");
|
|
57
57
|
var import_operators = require("rxjs/operators");
|
|
58
|
-
var
|
|
58
|
+
var import_authorization = require("./authorization");
|
|
59
59
|
var _logger, _CACHE_PREFIX, _generateCacheKey, generateCacheKey_fn, _getCache, getCache_fn, _setCache, setCache_fn;
|
|
60
60
|
let CacheInterceptor = class {
|
|
61
61
|
constructor(redis) {
|
|
@@ -74,7 +74,7 @@ let CacheInterceptor = class {
|
|
|
74
74
|
__privateGet(this, _logger).warn(`CacheInterceptor: ${key} is not Query endpoint or cache is not set`);
|
|
75
75
|
return next.handle();
|
|
76
76
|
}
|
|
77
|
-
const args = (0,
|
|
77
|
+
const args = (0, import_authorization.getArgs)(context);
|
|
78
78
|
const cacheKey = __privateMethod(this, _generateCacheKey, generateCacheKey_fn).call(this, key, args);
|
|
79
79
|
const cachedData = await __privateMethod(this, _getCache, getCache_fn).call(this, cacheKey);
|
|
80
80
|
if (cachedData) {
|
|
@@ -163,7 +163,7 @@ let LoggingInterceptor = class {
|
|
|
163
163
|
logger = new import_common.Logger("IO");
|
|
164
164
|
intercept(context, next) {
|
|
165
165
|
const gqlReq = context.getArgByIndex(3);
|
|
166
|
-
const req = (0,
|
|
166
|
+
const req = (0, import_authorization.getRequest)(context);
|
|
167
167
|
const reqType = gqlReq?.parentType?.name ?? req.method;
|
|
168
168
|
const reqName = gqlReq?.fieldName ?? req.url;
|
|
169
169
|
const before = Date.now();
|
|
@@ -0,0 +1,80 @@
|
|
|
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 internalParams_exports = {};
|
|
19
|
+
__export(internalParams_exports, {
|
|
20
|
+
Req: () => Req,
|
|
21
|
+
Res: () => Res,
|
|
22
|
+
Ws: () => Ws,
|
|
23
|
+
getNestParamDecorator: () => getNestParamDecorator
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(internalParams_exports);
|
|
26
|
+
var import_common = require("@nestjs/common");
|
|
27
|
+
var import_authorization = require("./authorization");
|
|
28
|
+
const paramDecoratorCache = /* @__PURE__ */ new Map();
|
|
29
|
+
const getNestParamDecorator = (pipe) => {
|
|
30
|
+
const existingParamDecorator = paramDecoratorCache.get(pipe);
|
|
31
|
+
if (existingParamDecorator)
|
|
32
|
+
return existingParamDecorator;
|
|
33
|
+
const pipeInstance = new pipe();
|
|
34
|
+
const paramDecorator = (0, import_common.createParamDecorator)((option, context) => {
|
|
35
|
+
const param = pipeInstance.getParam(context);
|
|
36
|
+
if (!option.nullable && (param === null || param === void 0))
|
|
37
|
+
throw new Error(`${pipe.name} is required`);
|
|
38
|
+
return param;
|
|
39
|
+
});
|
|
40
|
+
paramDecoratorCache.set(pipe, paramDecorator);
|
|
41
|
+
return paramDecorator;
|
|
42
|
+
};
|
|
43
|
+
class Req {
|
|
44
|
+
getParam(context) {
|
|
45
|
+
return (0, import_authorization.getRequest)(context);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
class Res {
|
|
49
|
+
getParam(context) {
|
|
50
|
+
return (0, import_authorization.getResponse)(context);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
class Ws {
|
|
54
|
+
getParam(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
|
+
}
|
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
+
0 && (module.exports = {
|
|
76
|
+
Req,
|
|
77
|
+
Res,
|
|
78
|
+
Ws,
|
|
79
|
+
getNestParamDecorator
|
|
80
|
+
});
|
package/esm/src/authorization.js
CHANGED
|
@@ -1,45 +1,57 @@
|
|
|
1
1
|
import { baseEnv } from "@akanjs/base";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { Logger } from "@akanjs/common";
|
|
3
|
+
import { GqlExecutionContext } from "@nestjs/graphql";
|
|
4
4
|
import * as jwt from "jsonwebtoken";
|
|
5
|
-
const
|
|
5
|
+
const resolveJwt = (secret, authorization, defaultResolved) => {
|
|
6
6
|
const [type, token] = authorization?.split(" ") ?? [void 0, void 0];
|
|
7
7
|
if (!token || type !== "Bearer")
|
|
8
|
-
return
|
|
8
|
+
return defaultResolved;
|
|
9
9
|
try {
|
|
10
|
-
const
|
|
11
|
-
if (
|
|
12
|
-
return
|
|
13
|
-
return
|
|
14
|
-
__InternalArg__: "Account",
|
|
15
|
-
self: account.self && !account.self.removedAt ? account.self : void 0,
|
|
16
|
-
me: account.me && !account.me.removedAt ? account.me : void 0,
|
|
17
|
-
appName: account.appName,
|
|
18
|
-
environment: account.environment
|
|
19
|
-
};
|
|
10
|
+
const resolved = jwt.verify(token, secret);
|
|
11
|
+
if (resolved.appName !== baseEnv.appName || resolved.environment !== baseEnv.environment)
|
|
12
|
+
return defaultResolved;
|
|
13
|
+
return resolved;
|
|
20
14
|
} catch (e) {
|
|
21
|
-
|
|
15
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
16
|
+
Logger.error(`failed to verify token for ${authorization}: ${message}`);
|
|
17
|
+
return defaultResolved;
|
|
22
18
|
}
|
|
23
19
|
};
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
)
|
|
20
|
+
const getRequest = (context) => {
|
|
21
|
+
const type = context.getType();
|
|
22
|
+
if (type === "ws")
|
|
23
|
+
throw new Error("Getting Request in Websocket is not allowed");
|
|
24
|
+
return type === "http" ? context.switchToHttp().getRequest() : GqlExecutionContext.create(context).getContext().req;
|
|
25
|
+
};
|
|
26
|
+
const getResponse = (context) => {
|
|
27
|
+
const type = context.getType();
|
|
28
|
+
if (type === "ws")
|
|
29
|
+
throw new Error("Getting Response in Websocket is not allowed");
|
|
30
|
+
return type === "http" ? context.switchToHttp().getResponse() : GqlExecutionContext.create(context).getContext().req.res;
|
|
31
|
+
};
|
|
32
|
+
const getArgs = (context) => {
|
|
33
|
+
const type = context.getType();
|
|
34
|
+
if (type === "ws")
|
|
35
|
+
throw new Error("Getting Args in Websocket is not allowed");
|
|
36
|
+
if (type === "graphql")
|
|
37
|
+
return GqlExecutionContext.create(context).getArgs();
|
|
38
|
+
else if (type === "http") {
|
|
39
|
+
const { params, query, body } = context.switchToHttp().getRequest();
|
|
40
|
+
return { ...params, ...query, ...body };
|
|
41
|
+
} else
|
|
42
|
+
throw new Error("Getting Args in Unknown context is not allowed");
|
|
43
|
+
};
|
|
44
|
+
const getSocket = (context) => {
|
|
45
|
+
const type = context.getType();
|
|
46
|
+
if (type !== "ws")
|
|
47
|
+
throw new Error("Getting Socket in Http or GraphQL is not allowed");
|
|
48
|
+
const socket = context.getArgByIndex(0);
|
|
49
|
+
return socket;
|
|
41
50
|
};
|
|
42
51
|
export {
|
|
43
|
-
|
|
44
|
-
|
|
52
|
+
getArgs,
|
|
53
|
+
getRequest,
|
|
54
|
+
getResponse,
|
|
55
|
+
getSocket,
|
|
56
|
+
resolveJwt
|
|
45
57
|
};
|
package/esm/src/index.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
export * from "./authorization";
|
|
2
|
-
export * from "./
|
|
3
|
-
import * as guards from "./authGuards";
|
|
4
|
-
export * from "./authentication";
|
|
2
|
+
export * from "./guards";
|
|
5
3
|
export * from "./interceptors";
|
|
6
4
|
export * from "./redis-io.adapter";
|
|
7
5
|
export * from "./pipes";
|
|
8
6
|
import * as Exporter from "./exporter";
|
|
9
7
|
export * from "./exporter";
|
|
10
|
-
export * from "./verifyPayment";
|
|
11
|
-
export * from "./sso";
|
|
12
8
|
export * from "./exceptions";
|
|
13
9
|
export * from "./generateSecrets";
|
|
14
10
|
export * from "./mongoose";
|
|
@@ -16,7 +12,8 @@ export * from "./searchClient";
|
|
|
16
12
|
export * from "./cacheClient";
|
|
17
13
|
export * from "./databaseClient";
|
|
18
14
|
export * from "./decorators";
|
|
15
|
+
export * from "./internalParams";
|
|
16
|
+
export * from "./guards";
|
|
19
17
|
export {
|
|
20
|
-
Exporter
|
|
21
|
-
guards
|
|
18
|
+
Exporter
|
|
22
19
|
};
|
package/esm/src/interceptors.js
CHANGED
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
import { GqlExecutionContext } from "@nestjs/graphql";
|
|
39
39
|
import { throwError, TimeoutError } from "rxjs";
|
|
40
40
|
import { catchError, map, tap, timeout } from "rxjs/operators";
|
|
41
|
-
import { getArgs, getRequest } from "./
|
|
41
|
+
import { getArgs, getRequest } from "./authorization";
|
|
42
42
|
let CacheInterceptor = class {
|
|
43
43
|
constructor(redis) {
|
|
44
44
|
this.redis = redis;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { createParamDecorator } from "@nestjs/common";
|
|
2
|
+
import { getRequest, getResponse } from "./authorization";
|
|
3
|
+
const paramDecoratorCache = /* @__PURE__ */ new Map();
|
|
4
|
+
const getNestParamDecorator = (pipe) => {
|
|
5
|
+
const existingParamDecorator = paramDecoratorCache.get(pipe);
|
|
6
|
+
if (existingParamDecorator)
|
|
7
|
+
return existingParamDecorator;
|
|
8
|
+
const pipeInstance = new pipe();
|
|
9
|
+
const paramDecorator = createParamDecorator((option, context) => {
|
|
10
|
+
const param = pipeInstance.getParam(context);
|
|
11
|
+
if (!option.nullable && (param === null || param === void 0))
|
|
12
|
+
throw new Error(`${pipe.name} is required`);
|
|
13
|
+
return param;
|
|
14
|
+
});
|
|
15
|
+
paramDecoratorCache.set(pipe, paramDecorator);
|
|
16
|
+
return paramDecorator;
|
|
17
|
+
};
|
|
18
|
+
class Req {
|
|
19
|
+
getParam(context) {
|
|
20
|
+
return getRequest(context);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
class Res {
|
|
24
|
+
getParam(context) {
|
|
25
|
+
return getResponse(context);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
class Ws {
|
|
29
|
+
getParam(context) {
|
|
30
|
+
const socket = context.getArgByIndex(0);
|
|
31
|
+
const { __subscribe__ } = context.getArgByIndex(1);
|
|
32
|
+
return {
|
|
33
|
+
socket,
|
|
34
|
+
subscribe: __subscribe__,
|
|
35
|
+
onDisconnect: (handler) => {
|
|
36
|
+
socket.on("disconnect", handler);
|
|
37
|
+
},
|
|
38
|
+
onSubscribe: (handler) => {
|
|
39
|
+
if (__subscribe__)
|
|
40
|
+
handler();
|
|
41
|
+
},
|
|
42
|
+
onUnsubscribe: (handler) => {
|
|
43
|
+
if (!__subscribe__)
|
|
44
|
+
handler();
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
Req,
|
|
51
|
+
Res,
|
|
52
|
+
Ws,
|
|
53
|
+
getNestParamDecorator
|
|
54
|
+
};
|
package/package.json
CHANGED
package/src/authorization.d.ts
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Environment } from "@akanjs/base";
|
|
2
|
+
import { ExecutionContext } from "@nestjs/common";
|
|
3
|
+
import { Socket } from "socket.io";
|
|
4
|
+
interface ResolvedToken {
|
|
5
|
+
appName: string;
|
|
6
|
+
environment: Environment;
|
|
7
|
+
}
|
|
8
|
+
export declare const resolveJwt: <Resolved extends ResolvedToken>(secret: string, authorization: string | undefined, defaultResolved: Resolved) => Resolved;
|
|
9
|
+
export interface ReqType {
|
|
10
|
+
method: string;
|
|
11
|
+
url: string;
|
|
12
|
+
params: object;
|
|
13
|
+
query: object;
|
|
14
|
+
body: object;
|
|
15
|
+
}
|
|
16
|
+
export interface GqlReqType {
|
|
17
|
+
parentType?: {
|
|
18
|
+
name?: string;
|
|
19
|
+
};
|
|
20
|
+
fieldName?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare const getRequest: (context: ExecutionContext) => unknown;
|
|
23
|
+
export declare const getResponse: (context: ExecutionContext) => unknown;
|
|
24
|
+
export declare const getArgs: (context: ExecutionContext) => {
|
|
25
|
+
[key: string]: any;
|
|
26
|
+
};
|
|
27
|
+
export declare const getSocket: (context: ExecutionContext) => Socket<import("socket.io").DefaultEventsMap, import("socket.io").DefaultEventsMap, import("socket.io").DefaultEventsMap, any>;
|
|
28
|
+
export {};
|
package/src/guards.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CanActivate, ExecutionContext } from "@nestjs/common";
|
|
2
|
+
export declare class Public implements Guard {
|
|
3
|
+
static name: string;
|
|
4
|
+
canActivate(context: ExecutionContext): boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare class None implements Guard {
|
|
7
|
+
static name: string;
|
|
8
|
+
canActivate(context: ExecutionContext): boolean;
|
|
9
|
+
}
|
|
10
|
+
export type Guard = CanActivate;
|
package/src/index.d.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
export * from "./authorization";
|
|
2
|
-
export * from "./
|
|
3
|
-
export * as guards from "./authGuards";
|
|
4
|
-
export * from "./authentication";
|
|
2
|
+
export * from "./guards";
|
|
5
3
|
export * from "./interceptors";
|
|
6
4
|
export * from "./redis-io.adapter";
|
|
7
5
|
export * from "./pipes";
|
|
8
6
|
export * as Exporter from "./exporter";
|
|
9
7
|
export * from "./exporter";
|
|
10
|
-
export * from "./verifyPayment";
|
|
11
|
-
export * from "./sso";
|
|
12
8
|
export * from "./exceptions";
|
|
13
9
|
export * from "./generateSecrets";
|
|
14
10
|
export * from "./mongoose";
|
|
@@ -16,3 +12,5 @@ export * from "./searchClient";
|
|
|
16
12
|
export * from "./cacheClient";
|
|
17
13
|
export * from "./databaseClient";
|
|
18
14
|
export * from "./decorators";
|
|
15
|
+
export * from "./internalParams";
|
|
16
|
+
export * from "./guards";
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Type } from "@akanjs/base";
|
|
2
|
+
import { ArgsOption } from "@akanjs/signal";
|
|
3
|
+
import { ExecutionContext } from "@nestjs/common";
|
|
4
|
+
import type { Request as ExpressRequest, Response as ExpressResponse } from "express";
|
|
5
|
+
import type { Socket } from "socket.io";
|
|
6
|
+
export interface InternalParamPipe<ParamType = any> {
|
|
7
|
+
getParam: (context: ExecutionContext) => ParamType | null;
|
|
8
|
+
}
|
|
9
|
+
export type InternalParam<ParamType = any> = Type<InternalParamPipe<ParamType>>;
|
|
10
|
+
export declare const getNestParamDecorator: (pipe: InternalParam) => (option: ArgsOption) => ParameterDecorator;
|
|
11
|
+
export declare class Req implements InternalParamPipe {
|
|
12
|
+
getParam(context: ExecutionContext): ExpressRequest & {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export declare class Res implements InternalParamPipe {
|
|
17
|
+
getParam(context: ExecutionContext): ExpressResponse;
|
|
18
|
+
}
|
|
19
|
+
export declare class Ws implements InternalParamPipe {
|
|
20
|
+
getParam(context: ExecutionContext): {
|
|
21
|
+
socket: Socket<import("socket.io").DefaultEventsMap, import("socket.io").DefaultEventsMap, import("socket.io").DefaultEventsMap, any>;
|
|
22
|
+
subscribe: boolean;
|
|
23
|
+
onDisconnect: (handler: () => void) => void;
|
|
24
|
+
onSubscribe: (handler: () => void) => void;
|
|
25
|
+
onUnsubscribe: (handler: () => void) => void;
|
|
26
|
+
};
|
|
27
|
+
}
|