@akanjs/nest 0.0.99 → 0.0.101

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.
Files changed (46) hide show
  1. package/index.js +21 -1
  2. package/index.mjs +1 -0
  3. package/package.json +4 -4
  4. package/src/authGuards.js +56 -15
  5. package/src/{authGuards.cjs → authGuards.mjs} +15 -56
  6. package/src/authentication.js +67 -27
  7. package/src/authentication.mjs +82 -0
  8. package/src/authorization.js +46 -12
  9. package/src/authorization.mjs +45 -0
  10. package/src/cacheClient.js +26 -5
  11. package/src/cacheClient.mjs +24 -0
  12. package/src/databaseClient.js +29 -8
  13. package/src/databaseClient.mjs +30 -0
  14. package/src/decorators.js +33 -6
  15. package/src/{decorators.cjs → decorators.mjs} +6 -33
  16. package/src/exceptions.js +29 -8
  17. package/src/{exceptions.cjs → exceptions.mjs} +8 -29
  18. package/src/exporter.js +40 -3
  19. package/src/{exporter.cjs → exporter.mjs} +3 -40
  20. package/src/generateSecrets.js +43 -13
  21. package/src/{generateSecrets.cjs → generateSecrets.mjs} +13 -43
  22. package/src/index.js +72 -21
  23. package/src/index.mjs +22 -0
  24. package/src/interceptors.js +55 -36
  25. package/src/{interceptors.cjs → interceptors.mjs} +36 -55
  26. package/src/mongoose.js +44 -11
  27. package/src/mongoose.mjs +60 -0
  28. package/src/pipes.js +51 -22
  29. package/src/{pipes.cjs → pipes.mjs} +22 -51
  30. package/src/redis-io.adapter.js +35 -12
  31. package/src/redis-io.adapter.mjs +61 -0
  32. package/src/searchClient.js +28 -7
  33. package/src/{searchClient.cjs → searchClient.mjs} +7 -28
  34. package/src/sso.js +56 -24
  35. package/src/{sso.cjs → sso.mjs} +24 -56
  36. package/src/verifyPayment.js +37 -4
  37. package/src/verifyPayment.mjs +17 -0
  38. package/index.cjs +0 -21
  39. package/src/authentication.cjs +0 -122
  40. package/src/authorization.cjs +0 -79
  41. package/src/cacheClient.cjs +0 -45
  42. package/src/databaseClient.cjs +0 -51
  43. package/src/index.cjs +0 -73
  44. package/src/mongoose.cjs +0 -93
  45. package/src/redis-io.adapter.cjs +0 -84
  46. package/src/verifyPayment.cjs +0 -50
package/index.cjs DELETED
@@ -1,21 +0,0 @@
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
- });
@@ -1,122 +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 __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"), 1);
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
- });
@@ -1,79 +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 __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"), 1);
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
- });
@@ -1,45 +0,0 @@
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 cacheClient_exports = {};
28
- __export(cacheClient_exports, {
29
- CacheClient: () => CacheClient
30
- });
31
- module.exports = __toCommonJS(cacheClient_exports);
32
- var import_common = require("@nestjs/common");
33
- let CacheClient = class {
34
- redis;
35
- };
36
- __decorateClass([
37
- (0, import_common.Inject)("REDIS_CLIENT")
38
- ], CacheClient.prototype, "redis", 2);
39
- CacheClient = __decorateClass([
40
- (0, import_common.Injectable)()
41
- ], CacheClient);
42
- // Annotate the CommonJS export names for ESM import in node:
43
- 0 && (module.exports = {
44
- CacheClient
45
- });
@@ -1,51 +0,0 @@
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 databaseClient_exports = {};
28
- __export(databaseClient_exports, {
29
- DatabaseClient: () => DatabaseClient
30
- });
31
- module.exports = __toCommonJS(databaseClient_exports);
32
- var import_common = require("@akanjs/common");
33
- var import_common2 = require("@nestjs/common");
34
- var import_mongoose = require("@nestjs/mongoose");
35
- let DatabaseClient = class {
36
- connection;
37
- getModel(modelName) {
38
- const model = this.connection.models[(0, import_common.capitalize)(modelName)];
39
- return model;
40
- }
41
- };
42
- __decorateClass([
43
- (0, import_mongoose.InjectConnection)()
44
- ], DatabaseClient.prototype, "connection", 2);
45
- DatabaseClient = __decorateClass([
46
- (0, import_common2.Injectable)()
47
- ], DatabaseClient);
48
- // Annotate the CommonJS export names for ESM import in node:
49
- 0 && (module.exports = {
50
- DatabaseClient
51
- });
package/src/index.cjs DELETED
@@ -1,73 +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 __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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
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 src_exports = {};
30
- __export(src_exports, {
31
- Exporter: () => Exporter,
32
- guards: () => guards
33
- });
34
- module.exports = __toCommonJS(src_exports);
35
- __reExport(src_exports, require("./authorization"), module.exports);
36
- __reExport(src_exports, require("./authGuards"), module.exports);
37
- var guards = __toESM(require("./authGuards"), 1);
38
- __reExport(src_exports, require("./authentication"), module.exports);
39
- __reExport(src_exports, require("./interceptors"), module.exports);
40
- __reExport(src_exports, require("./redis-io.adapter"), module.exports);
41
- __reExport(src_exports, require("./pipes"), module.exports);
42
- var Exporter = __toESM(require("./exporter"), 1);
43
- __reExport(src_exports, require("./exporter"), module.exports);
44
- __reExport(src_exports, require("./verifyPayment"), module.exports);
45
- __reExport(src_exports, require("./sso"), module.exports);
46
- __reExport(src_exports, require("./exceptions"), module.exports);
47
- __reExport(src_exports, require("./generateSecrets"), module.exports);
48
- __reExport(src_exports, require("./mongoose"), module.exports);
49
- __reExport(src_exports, require("./searchClient"), module.exports);
50
- __reExport(src_exports, require("./cacheClient"), module.exports);
51
- __reExport(src_exports, require("./databaseClient"), module.exports);
52
- __reExport(src_exports, require("./decorators"), module.exports);
53
- // Annotate the CommonJS export names for ESM import in node:
54
- 0 && (module.exports = {
55
- Exporter,
56
- guards,
57
- ...require("./authorization"),
58
- ...require("./authGuards"),
59
- ...require("./authentication"),
60
- ...require("./interceptors"),
61
- ...require("./redis-io.adapter"),
62
- ...require("./pipes"),
63
- ...require("./exporter"),
64
- ...require("./verifyPayment"),
65
- ...require("./sso"),
66
- ...require("./exceptions"),
67
- ...require("./generateSecrets"),
68
- ...require("./mongoose"),
69
- ...require("./searchClient"),
70
- ...require("./cacheClient"),
71
- ...require("./databaseClient"),
72
- ...require("./decorators")
73
- });
package/src/mongoose.cjs DELETED
@@ -1,93 +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 __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 mongoose_exports = {};
29
- __export(mongoose_exports, {
30
- initMongoDB: () => initMongoDB
31
- });
32
- module.exports = __toCommonJS(mongoose_exports);
33
- var import_common = require("@akanjs/common");
34
- var import_mongoose = __toESM(require("mongoose"), 1);
35
- const initMongoDB = ({
36
- logging,
37
- threshold = 5e3,
38
- sendReport = false
39
- }) => {
40
- const mongoDBLogger = new import_common.Logger("MongoDB");
41
- if (logging)
42
- import_mongoose.default.set("debug", function(collection, method, ...methodArgs) {
43
- mongoDBLogger.verbose(
44
- `${collection}.${method}(${methodArgs.slice(0, -1).map((arg) => JSON.stringify(arg)).join(", ")})`
45
- );
46
- });
47
- const originalExec = import_mongoose.default.Query.prototype.exec;
48
- const getQueryInfo = (queryAgent) => {
49
- const model = queryAgent.model;
50
- const collectionName = model.collection.collectionName;
51
- const dbName = model.db.name;
52
- const query = queryAgent.getQuery();
53
- const queryOptions = queryAgent.getOptions();
54
- return { dbName, collectionName, query, queryOptions };
55
- };
56
- import_mongoose.default.Query.prototype.exec = function(...args) {
57
- const start = Date.now();
58
- return originalExec.apply(this, args).then((result) => {
59
- const duration = Date.now() - start;
60
- const { dbName, collectionName, query, queryOptions } = getQueryInfo(this);
61
- if (logging)
62
- mongoDBLogger.verbose(
63
- `Queried ${dbName}.${collectionName}.query(${JSON.stringify(query)}, ${JSON.stringify(
64
- queryOptions
65
- )}) - ${duration}ms`
66
- );
67
- return result;
68
- });
69
- };
70
- const originalAggregate = import_mongoose.default.Model.aggregate;
71
- const getAggregateInfo = (aggregateModel) => {
72
- const dbName = aggregateModel.db.db?.databaseName ?? "unknown";
73
- const collectionName = aggregateModel.collection.collectionName;
74
- return { dbName, collectionName };
75
- };
76
- import_mongoose.default.Model.aggregate = function(...args) {
77
- const startTime = Date.now();
78
- return originalAggregate.apply(this, args).then((result) => {
79
- const duration = Date.now() - startTime;
80
- const { dbName, collectionName } = getAggregateInfo(this);
81
- if (logging)
82
- mongoDBLogger.verbose(
83
- `Aggregated ${dbName}.${collectionName}.aggregate(${args.map((arg) => JSON.stringify(arg)).join(", ")}) - ${duration}ms`
84
- );
85
- return result;
86
- });
87
- };
88
- import_mongoose.default.set("transactionAsyncLocalStorage", true);
89
- };
90
- // Annotate the CommonJS export names for ESM import in node:
91
- 0 && (module.exports = {
92
- initMongoDB
93
- });
@@ -1,84 +0,0 @@
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 redis_io_adapter_exports = {};
19
- __export(redis_io_adapter_exports, {
20
- RedisIoAdapter: () => RedisIoAdapter
21
- });
22
- module.exports = __toCommonJS(redis_io_adapter_exports);
23
- var import_common = require("@akanjs/common");
24
- var import_platform_socket = require("@nestjs/platform-socket.io");
25
- var import_redis_adapter = require("@socket.io/redis-adapter");
26
- var import_redis = require("redis");
27
- class RedisIoAdapter extends import_platform_socket.IoAdapter {
28
- adapterConstructor;
29
- logger = new import_common.Logger("RedisIoAdapter");
30
- server;
31
- pubClient;
32
- subClient;
33
- option;
34
- constructor(appOrHttpServer, option) {
35
- super(appOrHttpServer);
36
- this.option = option;
37
- }
38
- async connectToRedis(url) {
39
- this.pubClient = (0, import_redis.createClient)({ url });
40
- this.subClient = this.pubClient.duplicate();
41
- this.pubClient.on("disconnect", (err) => {
42
- this.logger.error(`Redis pub database is disconnected. Error: ${err}`);
43
- void this.pubClient.connect();
44
- });
45
- this.subClient.on("disconnect", (err) => {
46
- this.logger.error(`Redis sub database is disconnected. Error: ${err}`);
47
- void this.subClient.connect();
48
- });
49
- this.pubClient.on("error", (err) => {
50
- this.logger.error(`Redis pub database is errored. Error: ${err}`);
51
- const reconnect = async () => {
52
- await this.pubClient.quit();
53
- await (0, import_common.sleep)(1e3);
54
- await this.pubClient.connect();
55
- };
56
- void reconnect();
57
- });
58
- this.subClient.on("error", (err) => {
59
- this.logger.error(`Redis sub database is errored. Error: ${err}`);
60
- const reconnect = async () => {
61
- await this.subClient.quit();
62
- await (0, import_common.sleep)(1e3);
63
- await this.subClient.connect();
64
- };
65
- void reconnect();
66
- });
67
- await Promise.all([this.pubClient.connect(), this.subClient.connect()]);
68
- this.adapterConstructor = (0, import_redis_adapter.createAdapter)(this.pubClient, this.subClient);
69
- }
70
- createIOServer(port, options) {
71
- this.server = super.createIOServer(port, options);
72
- this.server.adapter(this.adapterConstructor);
73
- return this.server;
74
- }
75
- async destroy() {
76
- await Promise.all([this.pubClient.quit(), this.subClient.quit()]);
77
- await this.close(this.server);
78
- this.logger.log("RedisIoAdapter is closed");
79
- }
80
- }
81
- // Annotate the CommonJS export names for ESM import in node:
82
- 0 && (module.exports = {
83
- RedisIoAdapter
84
- });
@@ -1,50 +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 __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 verifyPayment_exports = {};
29
- __export(verifyPayment_exports, {
30
- verifyPayment: () => verifyPayment
31
- });
32
- module.exports = __toCommonJS(verifyPayment_exports);
33
- var import_iap = __toESM(require("iap"), 1);
34
- const verifyPayment = async (payment) => {
35
- return new Promise(
36
- (resolve, reject) => (
37
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
38
- import_iap.default.verifyPayment(payment.platform, { ...payment }, (error, response) => {
39
- if (error)
40
- reject(`App Purchase Verify Failed. ${response}`);
41
- else
42
- resolve(response);
43
- })
44
- )
45
- );
46
- };
47
- // Annotate the CommonJS export names for ESM import in node:
48
- 0 && (module.exports = {
49
- verifyPayment
50
- });