@comasoft/nestjs 0.1.2 → 0.1.3
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/dist/filters/http-exception.filter.d.ts +1 -1
- package/dist/filters/http-exception.filter.js +15 -12
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/logger/pino-pretty-transport.js +5 -14
- package/dist/passport/google.strategy.d.ts +13 -0
- package/dist/passport/google.strategy.js +43 -0
- package/dist/passport/index.d.ts +4 -0
- package/dist/passport/index.js +20 -0
- package/dist/passport/kakao.strategy.d.ts +2 -1
- package/dist/passport/kakao.strategy.js +12 -5
- package/package.json +2 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ArgumentsHost, ExceptionFilter, HttpException } from '@nestjs/common';
|
|
2
2
|
import { EventEmitter2 } from '@nestjs/event-emitter';
|
|
3
3
|
export declare class HttpExceptionFilter implements ExceptionFilter {
|
|
4
4
|
private readonly eventEmitter;
|
|
@@ -25,20 +25,25 @@ let HttpExceptionFilter = HttpExceptionFilter_1 = class HttpExceptionFilter {
|
|
|
25
25
|
const request = ctx.getRequest();
|
|
26
26
|
if (exception instanceof common_1.ForbiddenException) {
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
? exception.getStatus()
|
|
30
|
-
: common_1.HttpStatus.INTERNAL_SERVER_ERROR;
|
|
28
|
+
let httpStatus = exception instanceof common_1.HttpException ? exception.getStatus() : common_1.HttpStatus.INTERNAL_SERVER_ERROR;
|
|
31
29
|
let error = {};
|
|
32
30
|
if (exception instanceof common_1.HttpException) {
|
|
33
31
|
error = exception.getResponse();
|
|
34
32
|
}
|
|
35
33
|
else {
|
|
36
34
|
this.logger.error(`Unhandled exception: ${request.method} ${request.url}`);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
error
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
if ((exception === null || exception === void 0 ? void 0 : exception.name) === 'TokenError') {
|
|
36
|
+
httpStatus = common_1.HttpStatus.UNAUTHORIZED;
|
|
37
|
+
error = {
|
|
38
|
+
error: 'Unauthorized',
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
error = {
|
|
43
|
+
error: 'Internal Server Error',
|
|
44
|
+
message: 'An unexpected error occurred.',
|
|
45
|
+
};
|
|
46
|
+
}
|
|
42
47
|
}
|
|
43
48
|
if (typeof error === 'string') {
|
|
44
49
|
response.status(httpStatus).json({
|
|
@@ -51,11 +56,9 @@ let HttpExceptionFilter = HttpExceptionFilter_1 = class HttpExceptionFilter {
|
|
|
51
56
|
}
|
|
52
57
|
else {
|
|
53
58
|
let message = (_a = error.message) !== null && _a !== void 0 ? _a : error.error;
|
|
54
|
-
if (Array.isArray(message) &&
|
|
55
|
-
message.length > 0 &&
|
|
56
|
-
typeof message[0] === 'object') {
|
|
59
|
+
if (Array.isArray(message) && message.length > 0 && typeof message[0] === 'object') {
|
|
57
60
|
message = message
|
|
58
|
-
.map((err) => err.constraints ? Object.values(err.constraints) : 'Invalid input')
|
|
61
|
+
.map((err) => (err.constraints ? Object.values(err.constraints) : 'Invalid input'))
|
|
59
62
|
.flat();
|
|
60
63
|
}
|
|
61
64
|
response.status(httpStatus).json({
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export * from './utils';
|
|
|
7
7
|
export * from './setup-swagger';
|
|
8
8
|
export * from './logger';
|
|
9
9
|
export * from './redis';
|
|
10
|
-
export * from './passport
|
|
10
|
+
export * from './passport';
|
|
11
11
|
export * from './events';
|
|
12
12
|
export * from './notifications';
|
|
13
13
|
export * from './aws';
|
package/dist/index.js
CHANGED
|
@@ -23,7 +23,7 @@ __exportStar(require("./utils"), exports);
|
|
|
23
23
|
__exportStar(require("./setup-swagger"), exports);
|
|
24
24
|
__exportStar(require("./logger"), exports);
|
|
25
25
|
__exportStar(require("./redis"), exports);
|
|
26
|
-
__exportStar(require("./passport
|
|
26
|
+
__exportStar(require("./passport"), exports);
|
|
27
27
|
__exportStar(require("./events"), exports);
|
|
28
28
|
__exportStar(require("./notifications"), exports);
|
|
29
29
|
__exportStar(require("./aws"), exports);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const pinoPretty = require("pino-pretty");
|
|
4
3
|
const date_fns_tz_1 = require("date-fns-tz");
|
|
4
|
+
const pinoPretty = require("pino-pretty");
|
|
5
5
|
function getLevel(level, extras) {
|
|
6
6
|
let levelStr, levelColor;
|
|
7
7
|
switch (level) {
|
|
@@ -86,20 +86,13 @@ function getStatusCodeInfo(statusCode, colors) {
|
|
|
86
86
|
}
|
|
87
87
|
function pinoPrettyTransport(opts) {
|
|
88
88
|
const timezone = opts.timezone || 'Asia/Seoul';
|
|
89
|
-
const ignoreContext = opts.ignoreContext || [
|
|
90
|
-
'InstanceLoader',
|
|
91
|
-
'RouterExplorer',
|
|
92
|
-
];
|
|
89
|
+
const ignoreContext = opts.ignoreContext || ['InstanceLoader', 'RouterExplorer'];
|
|
93
90
|
return pinoPretty(Object.assign(Object.assign({ singleLine: true, colorize: true, colorizeObjects: false, hideObject: true, ignore: 'time,pid,hostname,context,level' }, opts), { levelFirst: true, messageFormat(log, messageKey, levelLabel, extras) {
|
|
94
91
|
if (ignoreContext.includes(log.context)) {
|
|
95
92
|
return;
|
|
96
93
|
}
|
|
97
|
-
const timestamp = log.time
|
|
98
|
-
|
|
99
|
-
: '';
|
|
100
|
-
const tz = log.time
|
|
101
|
-
? (0, date_fns_tz_1.formatInTimeZone)(new Date(log.time), timezone, 'zzz')
|
|
102
|
-
: '';
|
|
94
|
+
const timestamp = log.time ? (0, date_fns_tz_1.formatInTimeZone)(new Date(log.time), timezone, 'HH:mm:ss') : '';
|
|
95
|
+
const tz = log.time ? (0, date_fns_tz_1.formatInTimeZone)(new Date(log.time), timezone, 'zzz') : '';
|
|
103
96
|
if (log.method) {
|
|
104
97
|
const { methodColor, methodStr } = getMethodInfo(log.method, extras.colors);
|
|
105
98
|
const { responseTimeColor, responseTimeStr } = getResponseTimeInfo(log.responseTime, extras.colors);
|
|
@@ -135,9 +128,7 @@ function pinoPrettyTransport(opts) {
|
|
|
135
128
|
}
|
|
136
129
|
}
|
|
137
130
|
const { levelStr, levelColor } = getLevel(log.level, extras);
|
|
138
|
-
const context = log.context
|
|
139
|
-
? extras.colors.yellow(`[${log.context}]`)
|
|
140
|
-
: '';
|
|
131
|
+
const context = log.context ? extras.colors.yellow(`[${log.context}]`) : '';
|
|
141
132
|
const arr = [
|
|
142
133
|
extras.colors.dim(extras.colors.white(timestamp)),
|
|
143
134
|
extras.colors.gray(tz),
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare const GoogleStrategy_base: new (...args: any[]) => any;
|
|
2
|
+
export declare class GoogleStrategy extends GoogleStrategy_base {
|
|
3
|
+
constructor();
|
|
4
|
+
validate(accessToken: string, refreshToken: string, profile: any): Promise<{
|
|
5
|
+
vendor_uid: any;
|
|
6
|
+
name: any;
|
|
7
|
+
nickname: any;
|
|
8
|
+
email: any;
|
|
9
|
+
profile_image: any;
|
|
10
|
+
refresh_token: string;
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.GoogleStrategy = void 0;
|
|
13
|
+
const passport_1 = require("@nestjs/passport");
|
|
14
|
+
const passport_google_oauth20_1 = require("passport-google-oauth20");
|
|
15
|
+
class GoogleStrategy extends (0, passport_1.PassportStrategy)(passport_google_oauth20_1.Strategy, 'google') {
|
|
16
|
+
constructor() {
|
|
17
|
+
const clientID = process.env.GOOGLE_CLIENT_ID;
|
|
18
|
+
const clientSecret = process.env.GOOGLE_CLIENT_SECRET;
|
|
19
|
+
const callbackURL = process.env.GOOGLE_CALLBACK_URL;
|
|
20
|
+
if (!clientID || !clientSecret || !callbackURL) {
|
|
21
|
+
throw new Error('Google OAuth Environment Variables are not set');
|
|
22
|
+
}
|
|
23
|
+
super({
|
|
24
|
+
clientID,
|
|
25
|
+
clientSecret,
|
|
26
|
+
callbackURL,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
validate(accessToken, refreshToken, profile) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const user = profile._json;
|
|
32
|
+
return {
|
|
33
|
+
vendor_uid: user.sub,
|
|
34
|
+
name: user.name,
|
|
35
|
+
nickname: user.given_name,
|
|
36
|
+
email: user === null || user === void 0 ? void 0 : user.email,
|
|
37
|
+
profile_image: user === null || user === void 0 ? void 0 : user.picture,
|
|
38
|
+
refresh_token: refreshToken,
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.GoogleStrategy = GoogleStrategy;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./google.strategy"), exports);
|
|
18
|
+
__exportStar(require("./jwt.strategy"), exports);
|
|
19
|
+
__exportStar(require("./kakao.strategy"), exports);
|
|
20
|
+
__exportStar(require("./local.strategy"), exports);
|
|
@@ -2,11 +2,12 @@ declare const KakaoStrategy_base: new (...args: any[]) => any;
|
|
|
2
2
|
export declare class KakaoStrategy extends KakaoStrategy_base {
|
|
3
3
|
constructor();
|
|
4
4
|
validate(accessToken: string, refreshToken: string, profile: any): Promise<{
|
|
5
|
-
|
|
5
|
+
vendor_uid: any;
|
|
6
6
|
name: any;
|
|
7
7
|
nickname: any;
|
|
8
8
|
email: any;
|
|
9
9
|
profile_image: any;
|
|
10
|
+
refresh_token: string;
|
|
10
11
|
}>;
|
|
11
12
|
}
|
|
12
13
|
export {};
|
|
@@ -12,23 +12,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.KakaoStrategy = void 0;
|
|
13
13
|
const passport_1 = require("@nestjs/passport");
|
|
14
14
|
const passport_kakao_1 = require("passport-kakao");
|
|
15
|
-
class KakaoStrategy extends (0, passport_1.PassportStrategy)(passport_kakao_1.Strategy,
|
|
15
|
+
class KakaoStrategy extends (0, passport_1.PassportStrategy)(passport_kakao_1.Strategy, 'kakao') {
|
|
16
16
|
constructor() {
|
|
17
|
+
const clientID = process.env.KAKAO_CLIENT_ID;
|
|
18
|
+
const clientSecret = process.env.KAKAO_CLIENT_SECRET;
|
|
19
|
+
const callbackURL = process.env.KAKAO_CALLBACK_URL;
|
|
20
|
+
if (!clientID || !callbackURL) {
|
|
21
|
+
throw new Error('Kakao OAuth Environment Variables are not set');
|
|
22
|
+
}
|
|
17
23
|
super({
|
|
18
|
-
clientID
|
|
19
|
-
clientSecret
|
|
20
|
-
callbackURL
|
|
24
|
+
clientID,
|
|
25
|
+
clientSecret,
|
|
26
|
+
callbackURL,
|
|
21
27
|
});
|
|
22
28
|
}
|
|
23
29
|
validate(accessToken, refreshToken, profile) {
|
|
24
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
31
|
const { properties, kakao_account } = profile._json;
|
|
26
32
|
return {
|
|
27
|
-
|
|
33
|
+
vendor_uid: profile.id,
|
|
28
34
|
name: profile.displayName,
|
|
29
35
|
nickname: properties === null || properties === void 0 ? void 0 : properties.nickname,
|
|
30
36
|
email: kakao_account === null || kakao_account === void 0 ? void 0 : kakao_account.email,
|
|
31
37
|
profile_image: properties === null || properties === void 0 ? void 0 : properties.profile_image,
|
|
38
|
+
refresh_token: refreshToken,
|
|
32
39
|
};
|
|
33
40
|
});
|
|
34
41
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comasoft/nestjs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"private": false,
|
|
6
6
|
"exports": {
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
"date-fns-tz": "^3.2.0",
|
|
39
39
|
"express": "4.21.2",
|
|
40
40
|
"ioredis": "^5.6.1",
|
|
41
|
+
"passport-google-oauth20": "^2.0.0",
|
|
41
42
|
"passport-jwt": "4.0.1",
|
|
42
43
|
"passport-kakao": "1.0.1",
|
|
43
44
|
"passport-local": "1.0.0",
|