@akanjs/nest 0.0.45 → 0.0.47
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/index.js +2 -2179
- package/package.json +1 -7
- package/src/authGuards.js +146 -0
- package/src/authentication.js +111 -0
- package/src/authorization.js +74 -0
- package/src/cacheClient.js +41 -0
- package/src/databaseClient.js +47 -0
- package/src/decorators.js +163 -0
- package/src/exceptions.js +74 -0
- package/src/exporter.js +105 -0
- package/src/generateSecrets.js +128 -0
- package/src/index.js +52 -0
- package/src/interceptors.js +182 -0
- package/src/mongoose.js +89 -0
- package/src/pipes.js +135 -0
- package/src/redis-io.adapter.js +80 -0
- package/src/searchClient.js +63 -0
- package/src/sso.js +182 -0
- package/src/verifyPayment.js +46 -0
package/src/pipes.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
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);
|
package/src/sso.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
};
|