@akanjs/nest 0.0.4
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/README.md +11 -0
- package/index.d.ts +1 -0
- package/index.js +21 -0
- package/package.json +58 -0
- package/src/authGuards.d.ts +51 -0
- package/src/authGuards.js +160 -0
- package/src/authentication.d.ts +18 -0
- package/src/authentication.js +122 -0
- package/src/authorization.d.ts +3 -0
- package/src/authorization.js +79 -0
- package/src/exceptions.d.ts +5 -0
- package/src/exceptions.js +78 -0
- package/src/exporter.d.ts +22 -0
- package/src/exporter.js +113 -0
- package/src/generateSecrets.d.ts +36 -0
- package/src/generateSecrets.js +139 -0
- package/src/index.d.ts +15 -0
- package/src/index.js +68 -0
- package/src/inquirer.d.ts +20 -0
- package/src/inquirer.js +114 -0
- package/src/interceptors.d.ts +19 -0
- package/src/interceptors.js +132 -0
- package/src/mongoose.d.ts +5 -0
- package/src/mongoose.js +93 -0
- package/src/pipes.d.ts +48 -0
- package/src/pipes.js +147 -0
- package/src/redis-io.adapter.d.ts +19 -0
- package/src/redis-io.adapter.js +84 -0
- package/src/sso.d.ts +75 -0
- package/src/sso.js +187 -0
- package/src/verifyPayment.d.ts +11 -0
- package/src/verifyPayment.js +50 -0
package/src/mongoose.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
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"));
|
|
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
|
+
});
|
package/src/pipes.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Type } from "@akanjs/base";
|
|
2
|
+
import { ArgMeta } from "@akanjs/signal";
|
|
3
|
+
import { ArgumentMetadata, PipeTransform } from "@nestjs/common";
|
|
4
|
+
import { Readable } from "stream";
|
|
5
|
+
export declare class ArrayifyPipe implements PipeTransform {
|
|
6
|
+
transform(value: string | string[], metadata: ArgumentMetadata): string[];
|
|
7
|
+
}
|
|
8
|
+
export declare class IntPipe implements PipeTransform {
|
|
9
|
+
transform(value: string, metadata: ArgumentMetadata): number[];
|
|
10
|
+
}
|
|
11
|
+
export declare class FloatPipe implements PipeTransform {
|
|
12
|
+
transform(value: string, metadata: ArgumentMetadata): number[];
|
|
13
|
+
}
|
|
14
|
+
export declare class BooleanPipe implements PipeTransform {
|
|
15
|
+
transform(value: string, metadata: ArgumentMetadata): boolean[];
|
|
16
|
+
}
|
|
17
|
+
export declare class DayjsPipe implements PipeTransform {
|
|
18
|
+
transform(value: string, metadata: ArgumentMetadata): import("dayjs").Dayjs[];
|
|
19
|
+
}
|
|
20
|
+
export declare class JSONPipe implements PipeTransform {
|
|
21
|
+
transform(value: string | object, metadata: ArgumentMetadata): object;
|
|
22
|
+
}
|
|
23
|
+
interface FileStream {
|
|
24
|
+
originalname: string;
|
|
25
|
+
mimetype: string;
|
|
26
|
+
encoding: string;
|
|
27
|
+
buffer: Buffer;
|
|
28
|
+
}
|
|
29
|
+
export declare class MulterToUploadPipe implements PipeTransform {
|
|
30
|
+
transform(value: FileStream, metadata: ArgumentMetadata): {
|
|
31
|
+
filename: string;
|
|
32
|
+
mimetype: string;
|
|
33
|
+
encoding: string;
|
|
34
|
+
createReadStream: () => Readable;
|
|
35
|
+
} | {
|
|
36
|
+
filename: string;
|
|
37
|
+
mimetype: string;
|
|
38
|
+
encoding: string;
|
|
39
|
+
createReadStream: () => Readable;
|
|
40
|
+
}[];
|
|
41
|
+
}
|
|
42
|
+
export declare const getQueryPipes: (modelRef: Type, arrDepth: number) => Type[];
|
|
43
|
+
export declare const getBodyPipes: (argMeta: ArgMeta) => {
|
|
44
|
+
new (): {
|
|
45
|
+
transform(value: any, metadata: ArgumentMetadata): object[] | null;
|
|
46
|
+
};
|
|
47
|
+
}[];
|
|
48
|
+
export {};
|
package/src/pipes.js
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
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 pipes_exports = {};
|
|
28
|
+
__export(pipes_exports, {
|
|
29
|
+
ArrayifyPipe: () => ArrayifyPipe,
|
|
30
|
+
BooleanPipe: () => BooleanPipe,
|
|
31
|
+
DayjsPipe: () => DayjsPipe,
|
|
32
|
+
FloatPipe: () => FloatPipe,
|
|
33
|
+
IntPipe: () => IntPipe,
|
|
34
|
+
JSONPipe: () => JSONPipe,
|
|
35
|
+
MulterToUploadPipe: () => MulterToUploadPipe,
|
|
36
|
+
getBodyPipes: () => getBodyPipes,
|
|
37
|
+
getQueryPipes: () => getQueryPipes
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(pipes_exports);
|
|
40
|
+
var import_base = require("@akanjs/base");
|
|
41
|
+
var import_signal = require("@akanjs/signal");
|
|
42
|
+
var import_common = require("@nestjs/common");
|
|
43
|
+
var import_stream = require("stream");
|
|
44
|
+
let ArrayifyPipe = class {
|
|
45
|
+
transform(value, metadata) {
|
|
46
|
+
return Array.isArray(value) ? value : value.split(",");
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
ArrayifyPipe = __decorateClass([
|
|
50
|
+
(0, import_common.Injectable)()
|
|
51
|
+
], ArrayifyPipe);
|
|
52
|
+
let IntPipe = class {
|
|
53
|
+
transform(value, metadata) {
|
|
54
|
+
return Array.isArray(value) ? value.map(parseInt) : [parseInt(value)];
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
IntPipe = __decorateClass([
|
|
58
|
+
(0, import_common.Injectable)()
|
|
59
|
+
], IntPipe);
|
|
60
|
+
let FloatPipe = class {
|
|
61
|
+
transform(value, metadata) {
|
|
62
|
+
return Array.isArray(value) ? value.map(parseFloat) : [parseFloat(value)];
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
FloatPipe = __decorateClass([
|
|
66
|
+
(0, import_common.Injectable)()
|
|
67
|
+
], FloatPipe);
|
|
68
|
+
let BooleanPipe = class {
|
|
69
|
+
transform(value, metadata) {
|
|
70
|
+
return Array.isArray(value) ? value.map((v) => Boolean(v)) : [Boolean(value)];
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
BooleanPipe = __decorateClass([
|
|
74
|
+
(0, import_common.Injectable)()
|
|
75
|
+
], BooleanPipe);
|
|
76
|
+
let DayjsPipe = class {
|
|
77
|
+
transform(value, metadata) {
|
|
78
|
+
return Array.isArray(value) ? value.map(import_base.dayjs) : [(0, import_base.dayjs)(value)];
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
DayjsPipe = __decorateClass([
|
|
82
|
+
(0, import_common.Injectable)()
|
|
83
|
+
], DayjsPipe);
|
|
84
|
+
let JSONPipe = class {
|
|
85
|
+
transform(value, metadata) {
|
|
86
|
+
const transformable = typeof value === "string" && value.length;
|
|
87
|
+
const obj = transformable ? JSON.parse(atob(value)) : value;
|
|
88
|
+
return obj;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
JSONPipe = __decorateClass([
|
|
92
|
+
(0, import_common.Injectable)()
|
|
93
|
+
], JSONPipe);
|
|
94
|
+
const convertToFileStream = (value) => ({
|
|
95
|
+
filename: value.originalname,
|
|
96
|
+
mimetype: value.mimetype,
|
|
97
|
+
encoding: value.encoding,
|
|
98
|
+
createReadStream: () => import_stream.Readable.from(value.buffer)
|
|
99
|
+
});
|
|
100
|
+
let MulterToUploadPipe = class {
|
|
101
|
+
transform(value, metadata) {
|
|
102
|
+
return Array.isArray(value) ? value.map(convertToFileStream) : convertToFileStream(value);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
MulterToUploadPipe = __decorateClass([
|
|
106
|
+
(0, import_common.Injectable)()
|
|
107
|
+
], MulterToUploadPipe);
|
|
108
|
+
const gqlScalarPipeMap = /* @__PURE__ */ new Map([
|
|
109
|
+
[import_base.Int, IntPipe],
|
|
110
|
+
[import_base.Float, FloatPipe],
|
|
111
|
+
[Boolean, BooleanPipe],
|
|
112
|
+
[Date, DayjsPipe],
|
|
113
|
+
[import_base.JSON, JSONPipe]
|
|
114
|
+
]);
|
|
115
|
+
const getQueryPipes = (modelRef, arrDepth) => {
|
|
116
|
+
const pipes = arrDepth ? [ArrayifyPipe] : [];
|
|
117
|
+
const scalarPipe = gqlScalarPipeMap.get(modelRef);
|
|
118
|
+
if (scalarPipe)
|
|
119
|
+
pipes.push(scalarPipe);
|
|
120
|
+
return pipes;
|
|
121
|
+
};
|
|
122
|
+
const getBodyPipes = (argMeta) => {
|
|
123
|
+
const [returnRef] = (0, import_base.getNonArrayModel)(argMeta.returns());
|
|
124
|
+
if (returnRef.prototype !== Date.prototype && !(0, import_base.isGqlScalar)(returnRef))
|
|
125
|
+
return [];
|
|
126
|
+
let BodyPipe = class {
|
|
127
|
+
transform(value, metadata) {
|
|
128
|
+
return (0, import_signal.deserializeArg)(argMeta, value);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
BodyPipe = __decorateClass([
|
|
132
|
+
(0, import_common.Injectable)()
|
|
133
|
+
], BodyPipe);
|
|
134
|
+
return [BodyPipe];
|
|
135
|
+
};
|
|
136
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
137
|
+
0 && (module.exports = {
|
|
138
|
+
ArrayifyPipe,
|
|
139
|
+
BooleanPipe,
|
|
140
|
+
DayjsPipe,
|
|
141
|
+
FloatPipe,
|
|
142
|
+
IntPipe,
|
|
143
|
+
JSONPipe,
|
|
144
|
+
MulterToUploadPipe,
|
|
145
|
+
getBodyPipes,
|
|
146
|
+
getQueryPipes
|
|
147
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { INestApplicationContext } from "@nestjs/common";
|
|
2
|
+
import { IoAdapter } from "@nestjs/platform-socket.io";
|
|
3
|
+
import { ServerOptions } from "socket.io";
|
|
4
|
+
interface RedisIoAdapterOption extends Partial<ServerOptions> {
|
|
5
|
+
jwtSecret: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class RedisIoAdapter extends IoAdapter {
|
|
8
|
+
private adapterConstructor;
|
|
9
|
+
private readonly logger;
|
|
10
|
+
private server;
|
|
11
|
+
private pubClient;
|
|
12
|
+
private subClient;
|
|
13
|
+
option: RedisIoAdapterOption;
|
|
14
|
+
constructor(appOrHttpServer: INestApplicationContext, option: RedisIoAdapterOption);
|
|
15
|
+
connectToRedis(url: string): Promise<void>;
|
|
16
|
+
createIOServer(port: number, options?: ServerOptions): any;
|
|
17
|
+
destroy(): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
});
|
package/src/sso.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { Type } from "@akanjs/base";
|
|
2
|
+
import type { SSOType } from "@akanjs/signal";
|
|
3
|
+
import * as jwt from "jsonwebtoken";
|
|
4
|
+
export interface SSOCredential {
|
|
5
|
+
clientID: string;
|
|
6
|
+
clientSecret?: string;
|
|
7
|
+
}
|
|
8
|
+
export type AppleCredential = SSOCredential & {
|
|
9
|
+
teamID: string;
|
|
10
|
+
keyID: string;
|
|
11
|
+
keyFilePath: string;
|
|
12
|
+
};
|
|
13
|
+
export type SSOOptions = {
|
|
14
|
+
[key in SSOType]?: SSOCredential | AppleCredential;
|
|
15
|
+
};
|
|
16
|
+
export declare const getSsoProviders: (host: string, ssoOptions: SSOOptions) => Type[];
|
|
17
|
+
export interface KakaoResponse {
|
|
18
|
+
name?: string;
|
|
19
|
+
email: string;
|
|
20
|
+
}
|
|
21
|
+
export interface NaverResponse {
|
|
22
|
+
name?: string;
|
|
23
|
+
email: string;
|
|
24
|
+
}
|
|
25
|
+
export interface GithubResponse {
|
|
26
|
+
id: string;
|
|
27
|
+
displayName: string;
|
|
28
|
+
username: string;
|
|
29
|
+
profileUrl: string;
|
|
30
|
+
photos: {
|
|
31
|
+
value: string;
|
|
32
|
+
}[];
|
|
33
|
+
}
|
|
34
|
+
export interface GoogleResponse {
|
|
35
|
+
id: string;
|
|
36
|
+
displayName: string;
|
|
37
|
+
name: {
|
|
38
|
+
familyName: string;
|
|
39
|
+
givenName: string;
|
|
40
|
+
};
|
|
41
|
+
emails: {
|
|
42
|
+
value: string;
|
|
43
|
+
verified: boolean;
|
|
44
|
+
}[];
|
|
45
|
+
photos: {
|
|
46
|
+
value: string;
|
|
47
|
+
}[];
|
|
48
|
+
}
|
|
49
|
+
export interface FacebookResponse {
|
|
50
|
+
id: string;
|
|
51
|
+
name: {
|
|
52
|
+
familyName: string;
|
|
53
|
+
givenName: string;
|
|
54
|
+
};
|
|
55
|
+
emails: {
|
|
56
|
+
value: string;
|
|
57
|
+
verified: boolean;
|
|
58
|
+
}[];
|
|
59
|
+
}
|
|
60
|
+
export interface SsoCookie {
|
|
61
|
+
prepareUserId?: string;
|
|
62
|
+
ssoFor: "user" | "admin";
|
|
63
|
+
signinRedirect: string;
|
|
64
|
+
signupRedirect: string;
|
|
65
|
+
adminRedirect?: string;
|
|
66
|
+
errorRedirect?: string;
|
|
67
|
+
}
|
|
68
|
+
export declare const verifyAppleUser: (payload: {
|
|
69
|
+
code: string;
|
|
70
|
+
}, origin: string, sso: AppleCredential) => Promise<{
|
|
71
|
+
tokens: {
|
|
72
|
+
id_token?: string;
|
|
73
|
+
};
|
|
74
|
+
data: string | jwt.JwtPayload | null;
|
|
75
|
+
}>;
|
package/src/sso.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
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 __decorateClass = (decorators, target, key, kind) => {
|
|
29
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
30
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
31
|
+
if (decorator = decorators[i])
|
|
32
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
33
|
+
if (kind && result)
|
|
34
|
+
__defProp(target, key, result);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
var sso_exports = {};
|
|
38
|
+
__export(sso_exports, {
|
|
39
|
+
getSsoProviders: () => getSsoProviders,
|
|
40
|
+
verifyAppleUser: () => verifyAppleUser
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(sso_exports);
|
|
43
|
+
var import_common = require("@nestjs/common");
|
|
44
|
+
var import_passport = require("@nestjs/passport");
|
|
45
|
+
var appleSignin = __toESM(require("apple-signin"));
|
|
46
|
+
var jwt = __toESM(require("jsonwebtoken"));
|
|
47
|
+
var import_passport_apple = require("passport-apple");
|
|
48
|
+
var import_passport_facebook = require("passport-facebook");
|
|
49
|
+
var import_passport_github = require("passport-github");
|
|
50
|
+
var import_passport_google_oauth20 = require("passport-google-oauth20");
|
|
51
|
+
var import_passport_kakao = require("passport-kakao");
|
|
52
|
+
var import_passport_naver = require("passport-naver");
|
|
53
|
+
const getSsoProviders = (host, ssoOptions) => {
|
|
54
|
+
const origin = host === "localhost" ? "http://localhost:8080/backend" : `https://${host}/backend`;
|
|
55
|
+
const providers = [];
|
|
56
|
+
if (ssoOptions.kakao) {
|
|
57
|
+
let KakaoOauthStrategy = class extends (0, import_passport.PassportStrategy)(import_passport_kakao.Strategy, "kakao") {
|
|
58
|
+
constructor() {
|
|
59
|
+
super({
|
|
60
|
+
...ssoOptions.kakao,
|
|
61
|
+
callbackURL: `${origin}/user/kakao/callback`,
|
|
62
|
+
scope: ["account_email", "profile_nickname"]
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
validate(jwt2, refreshToken, profile) {
|
|
66
|
+
return {
|
|
67
|
+
name: profile.displayName,
|
|
68
|
+
email: profile._json.kakao_account.email,
|
|
69
|
+
password: profile.id
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
KakaoOauthStrategy = __decorateClass([
|
|
74
|
+
(0, import_common.Injectable)()
|
|
75
|
+
], KakaoOauthStrategy);
|
|
76
|
+
providers.push(KakaoOauthStrategy);
|
|
77
|
+
}
|
|
78
|
+
if (ssoOptions.naver) {
|
|
79
|
+
let NaverOauthStrategy = class extends (0, import_passport.PassportStrategy)(import_passport_naver.Strategy, "naver") {
|
|
80
|
+
constructor() {
|
|
81
|
+
super({ ...ssoOptions.naver, callbackURL: `${origin}/user/naver/callback` });
|
|
82
|
+
}
|
|
83
|
+
validate(jwt2, refreshToken, profile) {
|
|
84
|
+
return {
|
|
85
|
+
name: profile.displayName,
|
|
86
|
+
email: profile._json.email,
|
|
87
|
+
password: profile.id
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
NaverOauthStrategy = __decorateClass([
|
|
92
|
+
(0, import_common.Injectable)()
|
|
93
|
+
], NaverOauthStrategy);
|
|
94
|
+
providers.push(NaverOauthStrategy);
|
|
95
|
+
}
|
|
96
|
+
if (ssoOptions.github) {
|
|
97
|
+
let GithubOauthStrategy = class extends (0, import_passport.PassportStrategy)(import_passport_github.Strategy, "github") {
|
|
98
|
+
constructor() {
|
|
99
|
+
super({ ...ssoOptions.github, callbackURL: `${origin}/user/github/callback`, scope: ["user"] });
|
|
100
|
+
}
|
|
101
|
+
validate(accessToken, _refreshToken, profile) {
|
|
102
|
+
return profile;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
GithubOauthStrategy = __decorateClass([
|
|
106
|
+
(0, import_common.Injectable)()
|
|
107
|
+
], GithubOauthStrategy);
|
|
108
|
+
providers.push(GithubOauthStrategy);
|
|
109
|
+
}
|
|
110
|
+
if (ssoOptions.google) {
|
|
111
|
+
let GoogleOauthStrategy = class extends (0, import_passport.PassportStrategy)(import_passport_google_oauth20.Strategy, "google") {
|
|
112
|
+
constructor() {
|
|
113
|
+
super({ ...ssoOptions.google, callbackURL: `${origin}/user/google/callback`, scope: ["email", "profile"] });
|
|
114
|
+
}
|
|
115
|
+
validate(_accessToken, _refreshToken, profile) {
|
|
116
|
+
return profile;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
GoogleOauthStrategy = __decorateClass([
|
|
120
|
+
(0, import_common.Injectable)()
|
|
121
|
+
], GoogleOauthStrategy);
|
|
122
|
+
providers.push(GoogleOauthStrategy);
|
|
123
|
+
}
|
|
124
|
+
if (ssoOptions.facebook) {
|
|
125
|
+
let FacebookOauthStrategy = class extends (0, import_passport.PassportStrategy)(import_passport_facebook.Strategy, "facebook") {
|
|
126
|
+
constructor() {
|
|
127
|
+
super({
|
|
128
|
+
...ssoOptions.facebook,
|
|
129
|
+
callbackURL: `${origin}/user/facebook/callback`,
|
|
130
|
+
scope: ["email"],
|
|
131
|
+
profileFields: ["emails", "name"]
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
validate(_accessToken, _refreshToken, profile) {
|
|
135
|
+
return profile;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
FacebookOauthStrategy = __decorateClass([
|
|
139
|
+
(0, import_common.Injectable)()
|
|
140
|
+
], FacebookOauthStrategy);
|
|
141
|
+
providers.push(FacebookOauthStrategy);
|
|
142
|
+
}
|
|
143
|
+
if (ssoOptions.apple) {
|
|
144
|
+
let AppleOauthStrategy = class extends (0, import_passport.PassportStrategy)(import_passport_apple.Strategy, "apple") {
|
|
145
|
+
constructor() {
|
|
146
|
+
super({
|
|
147
|
+
...ssoOptions.apple,
|
|
148
|
+
callbackURL: `${origin}/user/apple/callback`,
|
|
149
|
+
passReqToCallback: true,
|
|
150
|
+
scope: ["name", "email"]
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
validate(req, accessToken, refreshToken, idToken, profile, cb) {
|
|
154
|
+
cb(null, idToken);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
AppleOauthStrategy = __decorateClass([
|
|
158
|
+
(0, import_common.Injectable)()
|
|
159
|
+
], AppleOauthStrategy);
|
|
160
|
+
providers.push(AppleOauthStrategy);
|
|
161
|
+
}
|
|
162
|
+
return providers;
|
|
163
|
+
};
|
|
164
|
+
const verifyAppleUser = async (payload, origin, sso) => {
|
|
165
|
+
const signinAgent = appleSignin;
|
|
166
|
+
const clientSecret = signinAgent.getClientSecret({
|
|
167
|
+
clientID: sso.clientID,
|
|
168
|
+
teamId: sso.teamID,
|
|
169
|
+
keyIdentifier: sso.keyID,
|
|
170
|
+
privateKeyPath: sso.keyFilePath
|
|
171
|
+
});
|
|
172
|
+
const tokens = await signinAgent.getAuthorizationToken(payload.code, {
|
|
173
|
+
clientID: sso.clientID,
|
|
174
|
+
clientSecret,
|
|
175
|
+
redirectUri: `${origin}/user/apple/callback`
|
|
176
|
+
});
|
|
177
|
+
if (!tokens.id_token) {
|
|
178
|
+
throw new Error("No id_token found in Apple's response");
|
|
179
|
+
}
|
|
180
|
+
const data = jwt.decode(tokens.id_token);
|
|
181
|
+
return { tokens, data };
|
|
182
|
+
};
|
|
183
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
184
|
+
0 && (module.exports = {
|
|
185
|
+
getSsoProviders,
|
|
186
|
+
verifyAppleUser
|
|
187
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface VerifyPaymentType {
|
|
2
|
+
packageName: string;
|
|
3
|
+
platform: string;
|
|
4
|
+
productId: string;
|
|
5
|
+
receipt: string;
|
|
6
|
+
secret?: string;
|
|
7
|
+
subscription?: boolean;
|
|
8
|
+
keyObject?: any;
|
|
9
|
+
}
|
|
10
|
+
export declare const verifyPayment: (payment: VerifyPaymentType) => Promise<unknown>;
|
|
11
|
+
export {};
|