@akanjs/nest 0.0.34 → 0.0.36

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,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,28 +0,0 @@
1
- import { type TextDoc } from "@akanjs/constant";
2
- import { default as MeiliSearch } from "meilisearch";
3
- export declare class SearchClient {
4
- meili: MeiliSearch;
5
- getIndexNames(): Promise<string[]>;
6
- getSearchResult(indexName: string, option: {
7
- skip?: number;
8
- limit?: number;
9
- sort?: string;
10
- searchString?: string;
11
- }): Promise<{
12
- docs: Record<string, any>[];
13
- skip: number;
14
- limit: number;
15
- sort: string;
16
- total: number;
17
- query?: undefined;
18
- } | {
19
- docs: import("meilisearch").Hits<Record<string, any>>;
20
- skip: number;
21
- limit: number;
22
- sort: string;
23
- total: number;
24
- query: string;
25
- }>;
26
- upsertDocuments(indexName: string, documents: TextDoc[]): Promise<import("meilisearch").EnqueuedTask>;
27
- dropIndex(indexName: string): Promise<import("meilisearch").EnqueuedTask>;
28
- }
@@ -1,67 +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 searchClient_exports = {};
28
- __export(searchClient_exports, {
29
- SearchClient: () => SearchClient
30
- });
31
- module.exports = __toCommonJS(searchClient_exports);
32
- var import_constant = require("@akanjs/constant");
33
- var import_common = require("@nestjs/common");
34
- let SearchClient = class {
35
- meili;
36
- async getIndexNames() {
37
- const { results } = await this.meili.getIndexes({ limit: 1e3 });
38
- return results.map((index) => index.uid);
39
- }
40
- async getSearchResult(indexName, option) {
41
- const { skip = 0, limit = import_constant.DEFAULT_PAGE_SIZE, sort = "", searchString } = option;
42
- if (!searchString) {
43
- const { results, total } = await this.meili.index(indexName).getDocuments({ offset: skip, limit });
44
- return { docs: results, skip, limit, sort, total };
45
- }
46
- const { hits, estimatedTotalHits } = await this.meili.index(indexName).search(searchString, { offset: skip, limit });
47
- return { docs: hits, skip, limit, sort, total: estimatedTotalHits, query: searchString };
48
- }
49
- async upsertDocuments(indexName, documents) {
50
- const task = await this.meili.index(indexName).addDocuments(documents);
51
- return task;
52
- }
53
- async dropIndex(indexName) {
54
- const task = await this.meili.index(indexName).delete();
55
- return task;
56
- }
57
- };
58
- __decorateClass([
59
- (0, import_common.Inject)("MEILI_CLIENT")
60
- ], SearchClient.prototype, "meili", 2);
61
- SearchClient = __decorateClass([
62
- (0, import_common.Injectable)()
63
- ], SearchClient);
64
- // Annotate the CommonJS export names for ESM import in node:
65
- 0 && (module.exports = {
66
- SearchClient
67
- });
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
- }>;
package/src/sso.js DELETED
@@ -1,187 +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 __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
- });
@@ -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 {};
@@ -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"));
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
- });