@akanjs/nest 0.9.56 → 0.9.57

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.
@@ -1,82 +0,0 @@
1
- import { dayjs } from "@akanjs/base";
2
- import { createParamDecorator, UnauthorizedException } from "@nestjs/common";
3
- import UAParser from "ua-parser-js";
4
- import { getRequest, getResponse } from "./authGuards";
5
- const Account = createParamDecorator((option, context) => {
6
- const { account } = getRequest(context);
7
- return account;
8
- });
9
- const Self = createParamDecorator((option, context) => {
10
- const { account } = getRequest(context);
11
- const self = account.self;
12
- if (!self && !option.nullable)
13
- throw new UnauthorizedException("No or Invalid Account in Self (User)");
14
- return self;
15
- });
16
- const Me = createParamDecorator((option, context) => {
17
- const { account } = getRequest(context);
18
- const me = account.me;
19
- if (!me && !option.nullable)
20
- throw new UnauthorizedException("No or Invalid Account in Me (Admin)");
21
- return me;
22
- });
23
- const UserIp = createParamDecorator((option, context) => {
24
- const req = getRequest(context);
25
- const ip = req.ip;
26
- if (!ip && !option.nullable)
27
- throw new UnauthorizedException("Invalid IP");
28
- return { ip };
29
- });
30
- const Access = createParamDecorator((option, context) => {
31
- const req = getRequest(context);
32
- const res = new UAParser(req.userAgent).getResult();
33
- if (!req.userAgent && !option.nullable)
34
- throw new UnauthorizedException("Invalid UserAgent");
35
- return {
36
- ...req.geolocation ? JSON.parse(req.geolocation) : {},
37
- osName: res.os.name,
38
- osVersion: res.os.version,
39
- browserName: res.browser.name,
40
- browserVersion: res.browser.version,
41
- mobileModel: res.device.model,
42
- mobileVendor: res.device.vendor,
43
- deviceType: res.device.type ?? "desktop",
44
- at: dayjs(),
45
- period: 0
46
- };
47
- });
48
- const Req = createParamDecorator((option, context) => {
49
- return getRequest(context);
50
- });
51
- const Res = createParamDecorator((option, context) => {
52
- return getResponse(context);
53
- });
54
- const Ws = createParamDecorator((option, 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
- export {
74
- Access,
75
- Account,
76
- Me,
77
- Req,
78
- Res,
79
- Self,
80
- UserIp,
81
- Ws
82
- };
package/esm/src/sso.js DELETED
@@ -1,155 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __decorateClass = (decorators, target, key, kind) => {
4
- var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
5
- for (var i = decorators.length - 1, decorator; i >= 0; i--)
6
- if (decorator = decorators[i])
7
- result = (kind ? decorator(target, key, result) : decorator(result)) || result;
8
- if (kind && result)
9
- __defProp(target, key, result);
10
- return result;
11
- };
12
- import { Injectable } from "@nestjs/common";
13
- import { PassportStrategy } from "@nestjs/passport";
14
- import * as appleSignin from "apple-signin";
15
- import * as jwt from "jsonwebtoken";
16
- import { Strategy as AppleStrategy } from "passport-apple";
17
- import { Strategy as FacebookStrategy } from "passport-facebook";
18
- import { Strategy as GithubStrategy } from "passport-github";
19
- import { Strategy as GoogleStrategy } from "passport-google-oauth20";
20
- import { Strategy as KakaoStrategy } from "passport-kakao";
21
- import { Strategy as NaverStrategy } from "passport-naver";
22
- const getSsoProviders = (host, ssoOptions) => {
23
- const origin = host === "localhost" ? "http://localhost:8080/backend" : `https://${host}/backend`;
24
- const providers = [];
25
- if (ssoOptions.kakao) {
26
- let KakaoOauthStrategy = class extends PassportStrategy(KakaoStrategy, "kakao") {
27
- constructor() {
28
- super({
29
- ...ssoOptions.kakao,
30
- callbackURL: `${origin}/user/kakao/callback`,
31
- scope: ["account_email", "profile_nickname"]
32
- });
33
- }
34
- validate(jwt2, refreshToken, profile) {
35
- return {
36
- name: profile.displayName,
37
- email: profile._json.kakao_account.email,
38
- password: profile.id
39
- };
40
- }
41
- };
42
- KakaoOauthStrategy = __decorateClass([
43
- Injectable()
44
- ], KakaoOauthStrategy);
45
- providers.push(KakaoOauthStrategy);
46
- }
47
- if (ssoOptions.naver) {
48
- let NaverOauthStrategy = class extends PassportStrategy(NaverStrategy, "naver") {
49
- constructor() {
50
- super({ ...ssoOptions.naver, callbackURL: `${origin}/user/naver/callback` });
51
- }
52
- validate(jwt2, refreshToken, profile) {
53
- return {
54
- name: profile.displayName,
55
- email: profile._json.email,
56
- password: profile.id
57
- };
58
- }
59
- };
60
- NaverOauthStrategy = __decorateClass([
61
- Injectable()
62
- ], NaverOauthStrategy);
63
- providers.push(NaverOauthStrategy);
64
- }
65
- if (ssoOptions.github) {
66
- let GithubOauthStrategy = class extends PassportStrategy(GithubStrategy, "github") {
67
- constructor() {
68
- super({ ...ssoOptions.github, callbackURL: `${origin}/user/github/callback`, scope: ["user"] });
69
- }
70
- validate(accessToken, _refreshToken, profile) {
71
- return profile;
72
- }
73
- };
74
- GithubOauthStrategy = __decorateClass([
75
- Injectable()
76
- ], GithubOauthStrategy);
77
- providers.push(GithubOauthStrategy);
78
- }
79
- if (ssoOptions.google) {
80
- let GoogleOauthStrategy = class extends PassportStrategy(GoogleStrategy, "google") {
81
- constructor() {
82
- super({ ...ssoOptions.google, callbackURL: `${origin}/user/google/callback`, scope: ["email", "profile"] });
83
- }
84
- validate(_accessToken, _refreshToken, profile) {
85
- return profile;
86
- }
87
- };
88
- GoogleOauthStrategy = __decorateClass([
89
- Injectable()
90
- ], GoogleOauthStrategy);
91
- providers.push(GoogleOauthStrategy);
92
- }
93
- if (ssoOptions.facebook) {
94
- let FacebookOauthStrategy = class extends PassportStrategy(FacebookStrategy, "facebook") {
95
- constructor() {
96
- super({
97
- ...ssoOptions.facebook,
98
- callbackURL: `${origin}/user/facebook/callback`,
99
- scope: ["email"],
100
- profileFields: ["emails", "name"]
101
- });
102
- }
103
- validate(_accessToken, _refreshToken, profile) {
104
- return profile;
105
- }
106
- };
107
- FacebookOauthStrategy = __decorateClass([
108
- Injectable()
109
- ], FacebookOauthStrategy);
110
- providers.push(FacebookOauthStrategy);
111
- }
112
- if (ssoOptions.apple) {
113
- let AppleOauthStrategy = class extends PassportStrategy(AppleStrategy, "apple") {
114
- constructor() {
115
- super({
116
- ...ssoOptions.apple,
117
- callbackURL: `${origin}/user/apple/callback`,
118
- passReqToCallback: true,
119
- scope: ["name", "email"]
120
- });
121
- }
122
- validate(req, accessToken, refreshToken, idToken, profile, cb) {
123
- cb(null, idToken);
124
- }
125
- };
126
- AppleOauthStrategy = __decorateClass([
127
- Injectable()
128
- ], AppleOauthStrategy);
129
- providers.push(AppleOauthStrategy);
130
- }
131
- return providers;
132
- };
133
- const verifyAppleUser = async (payload, origin, sso) => {
134
- const signinAgent = appleSignin;
135
- const clientSecret = signinAgent.getClientSecret({
136
- clientID: sso.clientID,
137
- teamId: sso.teamID,
138
- keyIdentifier: sso.keyID,
139
- privateKeyPath: sso.keyFilePath
140
- });
141
- const tokens = await signinAgent.getAuthorizationToken(payload.code, {
142
- clientID: sso.clientID,
143
- clientSecret,
144
- redirectUri: `${origin}/user/apple/callback`
145
- });
146
- if (!tokens.id_token) {
147
- throw new Error("No id_token found in Apple's response");
148
- }
149
- const data = jwt.decode(tokens.id_token);
150
- return { tokens, data };
151
- };
152
- export {
153
- getSsoProviders,
154
- verifyAppleUser
155
- };
@@ -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
- };
@@ -1,51 +0,0 @@
1
- import type { Account as SerAccount } from "@akanjs/signal";
2
- import { CanActivate, ExecutionContext } from "@nestjs/common";
3
- import type { Socket } from "socket.io";
4
- export interface RequestContext {
5
- account: SerAccount;
6
- ip?: string;
7
- userAgent?: string;
8
- geolocation?: string;
9
- headers: Record<string, string | undefined>;
10
- cookies?: Record<string, string>;
11
- }
12
- export interface ReqType {
13
- method: string;
14
- url: string;
15
- params: object;
16
- query: object;
17
- body: object;
18
- }
19
- export interface GqlReqType {
20
- parentType?: {
21
- name?: string;
22
- };
23
- fieldName?: string;
24
- }
25
- export declare const getRequest: (context: ExecutionContext) => unknown;
26
- export declare const getResponse: (context: ExecutionContext) => unknown;
27
- export declare const getArgs: (context: ExecutionContext) => {
28
- [key: string]: any;
29
- };
30
- export declare const getSocket: (context: ExecutionContext) => Socket<import("socket.io").DefaultEventsMap, import("socket.io").DefaultEventsMap, import("socket.io").DefaultEventsMap, any>;
31
- export declare class Public implements CanActivate {
32
- canActivate(context: ExecutionContext): boolean;
33
- }
34
- export declare class None implements CanActivate {
35
- canActivate(): boolean;
36
- }
37
- export declare class Every implements CanActivate {
38
- canActivate(context: ExecutionContext): boolean;
39
- }
40
- export declare class Owner implements CanActivate {
41
- canActivate(context: ExecutionContext): boolean;
42
- }
43
- export declare class Admin implements CanActivate {
44
- canActivate(context: ExecutionContext): boolean;
45
- }
46
- export declare class SuperAdmin implements CanActivate {
47
- canActivate(context: ExecutionContext): boolean;
48
- }
49
- export declare class User implements CanActivate {
50
- canActivate(context: ExecutionContext): boolean;
51
- }
@@ -1,18 +0,0 @@
1
- export declare const Account: (...dataOrPipes: ({
2
- nullable?: boolean;
3
- } | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
4
- export declare const Self: (...dataOrPipes: ({
5
- nullable?: boolean;
6
- } | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
7
- export declare const Me: (...dataOrPipes: ({
8
- nullable?: boolean;
9
- } | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
10
- export declare const UserIp: (...dataOrPipes: ({
11
- nullable?: boolean;
12
- } | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
13
- export declare const Access: (...dataOrPipes: ({
14
- nullable?: boolean;
15
- } | import("@nestjs/common").PipeTransform<any, any> | import("@nestjs/common").Type<import("@nestjs/common").PipeTransform<any, any>>)[]) => ParameterDecorator;
16
- export declare const Req: (...dataOrPipes: unknown[]) => ParameterDecorator;
17
- export declare const Res: (...dataOrPipes: unknown[]) => ParameterDecorator;
18
- export declare const Ws: (...dataOrPipes: unknown[]) => ParameterDecorator;
package/src/sso.d.ts DELETED
@@ -1,75 +0,0 @@
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
- }>;
@@ -1,11 +0,0 @@
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 {};