@akanjs/nest 0.0.97 → 0.0.99

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.cjs +21 -0
  2. package/index.js +1 -21
  3. package/package.json +4 -4
  4. package/src/{authGuards.mjs → authGuards.cjs} +56 -15
  5. package/src/authGuards.js +15 -56
  6. package/src/authentication.cjs +122 -0
  7. package/src/authentication.js +27 -67
  8. package/src/authorization.cjs +79 -0
  9. package/src/authorization.js +12 -46
  10. package/src/cacheClient.cjs +45 -0
  11. package/src/cacheClient.js +5 -26
  12. package/src/databaseClient.cjs +51 -0
  13. package/src/databaseClient.js +8 -29
  14. package/src/{decorators.mjs → decorators.cjs} +33 -6
  15. package/src/decorators.js +6 -33
  16. package/src/{exceptions.mjs → exceptions.cjs} +29 -8
  17. package/src/exceptions.js +8 -29
  18. package/src/{exporter.mjs → exporter.cjs} +40 -3
  19. package/src/exporter.js +3 -40
  20. package/src/{generateSecrets.mjs → generateSecrets.cjs} +43 -13
  21. package/src/generateSecrets.js +13 -43
  22. package/src/index.cjs +73 -0
  23. package/src/index.js +21 -72
  24. package/src/{interceptors.mjs → interceptors.cjs} +55 -36
  25. package/src/interceptors.js +36 -55
  26. package/src/mongoose.cjs +93 -0
  27. package/src/mongoose.js +11 -44
  28. package/src/{pipes.mjs → pipes.cjs} +51 -22
  29. package/src/pipes.js +22 -51
  30. package/src/redis-io.adapter.cjs +84 -0
  31. package/src/redis-io.adapter.js +12 -35
  32. package/src/{searchClient.mjs → searchClient.cjs} +28 -7
  33. package/src/searchClient.js +7 -28
  34. package/src/{sso.mjs → sso.cjs} +56 -24
  35. package/src/sso.js +24 -56
  36. package/src/verifyPayment.cjs +50 -0
  37. package/src/verifyPayment.js +4 -37
  38. package/index.mjs +0 -1
  39. package/src/authentication.mjs +0 -82
  40. package/src/authorization.mjs +0 -45
  41. package/src/cacheClient.mjs +0 -24
  42. package/src/databaseClient.mjs +0 -30
  43. package/src/index.mjs +0 -22
  44. package/src/mongoose.mjs +0 -60
  45. package/src/redis-io.adapter.mjs +0 -61
  46. package/src/verifyPayment.mjs +0 -17
package/src/mongoose.mjs DELETED
@@ -1,60 +0,0 @@
1
- import { Logger } from "@akanjs/common";
2
- import mongoose from "mongoose";
3
- const initMongoDB = ({
4
- logging,
5
- threshold = 5e3,
6
- sendReport = false
7
- }) => {
8
- const mongoDBLogger = new Logger("MongoDB");
9
- if (logging)
10
- mongoose.set("debug", function(collection, method, ...methodArgs) {
11
- mongoDBLogger.verbose(
12
- `${collection}.${method}(${methodArgs.slice(0, -1).map((arg) => JSON.stringify(arg)).join(", ")})`
13
- );
14
- });
15
- const originalExec = mongoose.Query.prototype.exec;
16
- const getQueryInfo = (queryAgent) => {
17
- const model = queryAgent.model;
18
- const collectionName = model.collection.collectionName;
19
- const dbName = model.db.name;
20
- const query = queryAgent.getQuery();
21
- const queryOptions = queryAgent.getOptions();
22
- return { dbName, collectionName, query, queryOptions };
23
- };
24
- mongoose.Query.prototype.exec = function(...args) {
25
- const start = Date.now();
26
- return originalExec.apply(this, args).then((result) => {
27
- const duration = Date.now() - start;
28
- const { dbName, collectionName, query, queryOptions } = getQueryInfo(this);
29
- if (logging)
30
- mongoDBLogger.verbose(
31
- `Queried ${dbName}.${collectionName}.query(${JSON.stringify(query)}, ${JSON.stringify(
32
- queryOptions
33
- )}) - ${duration}ms`
34
- );
35
- return result;
36
- });
37
- };
38
- const originalAggregate = mongoose.Model.aggregate;
39
- const getAggregateInfo = (aggregateModel) => {
40
- const dbName = aggregateModel.db.db?.databaseName ?? "unknown";
41
- const collectionName = aggregateModel.collection.collectionName;
42
- return { dbName, collectionName };
43
- };
44
- mongoose.Model.aggregate = function(...args) {
45
- const startTime = Date.now();
46
- return originalAggregate.apply(this, args).then((result) => {
47
- const duration = Date.now() - startTime;
48
- const { dbName, collectionName } = getAggregateInfo(this);
49
- if (logging)
50
- mongoDBLogger.verbose(
51
- `Aggregated ${dbName}.${collectionName}.aggregate(${args.map((arg) => JSON.stringify(arg)).join(", ")}) - ${duration}ms`
52
- );
53
- return result;
54
- });
55
- };
56
- mongoose.set("transactionAsyncLocalStorage", true);
57
- };
58
- export {
59
- initMongoDB
60
- };
@@ -1,61 +0,0 @@
1
- import { Logger, sleep } from "@akanjs/common";
2
- import { IoAdapter } from "@nestjs/platform-socket.io";
3
- import { createAdapter } from "@socket.io/redis-adapter";
4
- import { createClient } from "redis";
5
- class RedisIoAdapter extends IoAdapter {
6
- adapterConstructor;
7
- logger = new Logger("RedisIoAdapter");
8
- server;
9
- pubClient;
10
- subClient;
11
- option;
12
- constructor(appOrHttpServer, option) {
13
- super(appOrHttpServer);
14
- this.option = option;
15
- }
16
- async connectToRedis(url) {
17
- this.pubClient = createClient({ url });
18
- this.subClient = this.pubClient.duplicate();
19
- this.pubClient.on("disconnect", (err) => {
20
- this.logger.error(`Redis pub database is disconnected. Error: ${err}`);
21
- void this.pubClient.connect();
22
- });
23
- this.subClient.on("disconnect", (err) => {
24
- this.logger.error(`Redis sub database is disconnected. Error: ${err}`);
25
- void this.subClient.connect();
26
- });
27
- this.pubClient.on("error", (err) => {
28
- this.logger.error(`Redis pub database is errored. Error: ${err}`);
29
- const reconnect = async () => {
30
- await this.pubClient.quit();
31
- await sleep(1e3);
32
- await this.pubClient.connect();
33
- };
34
- void reconnect();
35
- });
36
- this.subClient.on("error", (err) => {
37
- this.logger.error(`Redis sub database is errored. Error: ${err}`);
38
- const reconnect = async () => {
39
- await this.subClient.quit();
40
- await sleep(1e3);
41
- await this.subClient.connect();
42
- };
43
- void reconnect();
44
- });
45
- await Promise.all([this.pubClient.connect(), this.subClient.connect()]);
46
- this.adapterConstructor = createAdapter(this.pubClient, this.subClient);
47
- }
48
- createIOServer(port, options) {
49
- this.server = super.createIOServer(port, options);
50
- this.server.adapter(this.adapterConstructor);
51
- return this.server;
52
- }
53
- async destroy() {
54
- await Promise.all([this.pubClient.quit(), this.subClient.quit()]);
55
- await this.close(this.server);
56
- this.logger.log("RedisIoAdapter is closed");
57
- }
58
- }
59
- export {
60
- RedisIoAdapter
61
- };
@@ -1,17 +0,0 @@
1
- import iap from "iap";
2
- const verifyPayment = async (payment) => {
3
- return new Promise(
4
- (resolve, reject) => (
5
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
6
- iap.verifyPayment(payment.platform, { ...payment }, (error, response) => {
7
- if (error)
8
- reject(`App Purchase Verify Failed. ${response}`);
9
- else
10
- resolve(response);
11
- })
12
- )
13
- );
14
- };
15
- export {
16
- verifyPayment
17
- };