@akanjs/nest 0.0.44 → 0.0.46
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 +1223 -2074
- package/package.json +1 -7
package/index.js
CHANGED
|
@@ -1,1258 +1,385 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
56
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
57
|
-
};
|
|
58
|
-
var __privateMethod = (obj, member, method) => {
|
|
59
|
-
__accessCheck(obj, member, "access private method");
|
|
60
|
-
return method;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
// pkgs/@akanjs/base/src/base.ts
|
|
64
|
-
var version = "0.9.0";
|
|
65
|
-
var logo = `
|
|
66
|
-
_ _ _
|
|
67
|
-
/ \\ | | ____ _ _ __ (_)___
|
|
68
|
-
/ _ \\ | |/ / _' | '_ \\ | / __|
|
|
69
|
-
/ ___ \\| < (_| | | | |_ | \\__ \\
|
|
70
|
-
/_/ \\_\\_|\\_\\__,_|_| |_(_)/ |___/
|
|
71
|
-
|__/ ver ${version}
|
|
72
|
-
? See more details on docs https://www.akanjs.com/docs
|
|
73
|
-
\u2605 Star Akanjs on GitHub https://github.com/aka-bassman/akanjs
|
|
74
|
-
|
|
75
|
-
`;
|
|
76
|
-
|
|
77
|
-
// pkgs/@akanjs/base/src/baseEnv.ts
|
|
78
|
-
var appName = process.env.NEXT_PUBLIC_APP_NAME ?? "unknown";
|
|
79
|
-
var repoName = process.env.NEXT_PUBLIC_REPO_NAME ?? "unknown";
|
|
80
|
-
var serveDomain = process.env.NEXT_PUBLIC_SERVE_DOMAIN ?? "unknown";
|
|
81
|
-
if (appName === "unknown")
|
|
82
|
-
throw new Error("environment variable NEXT_PUBLIC_APP_NAME is required");
|
|
83
|
-
if (repoName === "unknown")
|
|
84
|
-
throw new Error("environment variable NEXT_PUBLIC_REPO_NAME is required");
|
|
85
|
-
if (serveDomain === "unknown")
|
|
86
|
-
throw new Error("environment variable NEXT_PUBLIC_SERVE_DOMAIN is required");
|
|
87
|
-
var environment = process.env.NEXT_PUBLIC_ENV ?? "debug";
|
|
88
|
-
var operationType = typeof window !== "undefined" ? "client" : process.env.NEXT_RUNTIME ? "client" : "server";
|
|
89
|
-
var operationMode = process.env.NEXT_PUBLIC_OPERATION_MODE ?? "cloud";
|
|
90
|
-
var networkType = process.env.NEXT_PUBLIC_NETWORK_TYPE ?? (environment === "main" ? "mainnet" : environment === "develop" ? "testnet" : "debugnet");
|
|
91
|
-
var tunnelUsername = process.env.SSU_TUNNEL_USERNAME ?? "root";
|
|
92
|
-
var tunnelPassword = process.env.SSU_TUNNEL_PASSWORD ?? repoName;
|
|
93
|
-
var baseEnv = {
|
|
94
|
-
repoName,
|
|
95
|
-
serveDomain,
|
|
96
|
-
appName,
|
|
97
|
-
environment,
|
|
98
|
-
operationType,
|
|
99
|
-
operationMode,
|
|
100
|
-
networkType,
|
|
101
|
-
tunnelUsername,
|
|
102
|
-
tunnelPassword
|
|
103
|
-
};
|
|
104
|
-
var side = typeof window === "undefined" ? "server" : "client";
|
|
105
|
-
var renderMode = process.env.RENDER_ENV ?? "ssr";
|
|
106
|
-
var clientHost = process.env.NEXT_PUBLIC_CLIENT_HOST ?? (operationMode === "local" || side === "server" ? "localhost" : window.location.hostname);
|
|
107
|
-
var clientPort = parseInt(
|
|
108
|
-
process.env.NEXT_PUBLIC_CLIENT_PORT ?? (operationMode === "local" ? renderMode === "ssr" ? "4200" : "4201" : "443")
|
|
109
|
-
);
|
|
110
|
-
var clientHttpProtocol = side === "client" ? window.location.protocol : clientHost === "localhost" ? "http:" : "https:";
|
|
111
|
-
var clientHttpUri = `${clientHttpProtocol}//${clientHost}${clientPort === 443 ? "" : `:${clientPort}`}`;
|
|
112
|
-
var serverHost = process.env.SERVER_HOST ?? (operationMode === "local" ? typeof window === "undefined" ? "localhost" : window.location.host.split(":")[0] : renderMode === "csr" ? `${appName}-${environment}.${serveDomain}` : side === "client" ? window.location.host.split(":")[0] : operationMode === "cloud" ? `backend-svc.${appName}-${environment}.svc.cluster.local` : "localhost");
|
|
113
|
-
var serverPort = parseInt(
|
|
114
|
-
process.env.SERVER_PORT ?? (operationMode === "local" || side === "server" ? "8080" : "443")
|
|
115
|
-
);
|
|
116
|
-
var serverHttpProtocol = side === "client" ? window.location.protocol : "http:";
|
|
117
|
-
var serverHttpUri = `${serverHttpProtocol}//${serverHost}${serverPort === 443 ? "" : `:${serverPort}`}/backend`;
|
|
118
|
-
var serverGraphqlUri = `${serverHttpUri}/graphql`;
|
|
119
|
-
var serverWsProtocol = serverHttpProtocol === "http:" ? "ws:" : "wss:";
|
|
120
|
-
var serverWsUri = `${serverWsProtocol}//${serverHost}${serverPort === 443 ? "" : `:${serverPort}`}`;
|
|
121
|
-
var baseClientEnv = {
|
|
122
|
-
...baseEnv,
|
|
123
|
-
side,
|
|
124
|
-
renderMode,
|
|
125
|
-
websocket: true,
|
|
126
|
-
clientHost,
|
|
127
|
-
clientPort,
|
|
128
|
-
clientHttpProtocol,
|
|
129
|
-
clientHttpUri,
|
|
130
|
-
serverHost,
|
|
131
|
-
serverPort,
|
|
132
|
-
serverHttpProtocol,
|
|
133
|
-
serverHttpUri,
|
|
134
|
-
serverGraphqlUri,
|
|
135
|
-
serverWsProtocol,
|
|
136
|
-
serverWsUri
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
// pkgs/@akanjs/base/src/scalar.ts
|
|
140
|
-
var import_dayjs = __toESM(__require("dayjs"));
|
|
141
|
-
var dayjs = import_dayjs.default;
|
|
142
|
-
var Int = class {
|
|
143
|
-
__Scalar__;
|
|
144
|
-
};
|
|
145
|
-
var Upload = class {
|
|
146
|
-
__Scalar__;
|
|
147
|
-
filename;
|
|
148
|
-
mimetype;
|
|
149
|
-
encoding;
|
|
150
|
-
createReadStream;
|
|
151
|
-
};
|
|
152
|
-
var Float = class {
|
|
153
|
-
__Scalar__;
|
|
154
|
-
};
|
|
155
|
-
var ID = class {
|
|
156
|
-
__Scalar__;
|
|
157
|
-
};
|
|
158
|
-
var JSON2 = class {
|
|
159
|
-
__Scalar__;
|
|
160
|
-
};
|
|
161
|
-
var getNonArrayModel = (arraiedModel2) => {
|
|
162
|
-
let arrDepth = 0;
|
|
163
|
-
let target = arraiedModel2;
|
|
164
|
-
while (Array.isArray(target)) {
|
|
165
|
-
target = target[0];
|
|
166
|
-
arrDepth++;
|
|
167
|
-
}
|
|
168
|
-
return [target, arrDepth];
|
|
169
|
-
};
|
|
170
|
-
var applyFnToArrayObjects = (arraiedData, fn) => {
|
|
171
|
-
if (Array.isArray(arraiedData))
|
|
172
|
-
return arraiedData.map((data) => applyFnToArrayObjects(data, fn));
|
|
173
|
-
return fn(arraiedData);
|
|
174
|
-
};
|
|
175
|
-
var scalarSet = /* @__PURE__ */ new Set([String, Boolean, Date, ID, Int, Float, Upload, JSON2, Map]);
|
|
176
|
-
var scalarNameMap = /* @__PURE__ */ new Map([
|
|
177
|
-
[ID, "ID"],
|
|
178
|
-
[Int, "Int"],
|
|
179
|
-
[Float, "Float"],
|
|
180
|
-
[String, "String"],
|
|
181
|
-
[Boolean, "Boolean"],
|
|
182
|
-
[Date, "Date"],
|
|
183
|
-
[Upload, "Upload"],
|
|
184
|
-
[JSON2, "JSON"],
|
|
185
|
-
[Map, "Map"]
|
|
186
|
-
]);
|
|
187
|
-
var scalarArgMap = /* @__PURE__ */ new Map([
|
|
188
|
-
[ID, null],
|
|
189
|
-
[String, ""],
|
|
190
|
-
[Boolean, false],
|
|
191
|
-
[Date, dayjs(/* @__PURE__ */ new Date(-1))],
|
|
192
|
-
[Int, 0],
|
|
193
|
-
[Float, 0],
|
|
194
|
-
[JSON2, {}],
|
|
195
|
-
[Map, {}]
|
|
196
|
-
]);
|
|
197
|
-
var scalarDefaultMap = /* @__PURE__ */ new Map([
|
|
198
|
-
[ID, null],
|
|
199
|
-
[String, ""],
|
|
200
|
-
[Boolean, false],
|
|
201
|
-
[Date, dayjs(/* @__PURE__ */ new Date(-1))],
|
|
202
|
-
[Int, 0],
|
|
203
|
-
[Float, 0],
|
|
204
|
-
[JSON2, {}]
|
|
205
|
-
]);
|
|
206
|
-
var isGqlScalar = (modelRef) => scalarSet.has(modelRef);
|
|
207
|
-
var isGqlMap = (modelRef) => modelRef === Map;
|
|
208
|
-
|
|
209
|
-
// pkgs/@akanjs/common/src/isDayjs.ts
|
|
210
|
-
var import_dayjs2 = __require("dayjs");
|
|
211
|
-
|
|
212
|
-
// pkgs/@akanjs/common/src/isQueryEqual.ts
|
|
213
|
-
var import_dayjs3 = __toESM(__require("dayjs"));
|
|
214
|
-
|
|
215
|
-
// pkgs/@akanjs/common/src/isValidDate.ts
|
|
216
|
-
var import_dayjs4 = __toESM(__require("dayjs"));
|
|
217
|
-
var import_customParseFormat = __toESM(__require("dayjs/plugin/customParseFormat"));
|
|
218
|
-
import_dayjs4.default.extend(import_customParseFormat.default);
|
|
219
|
-
|
|
220
|
-
// pkgs/@akanjs/common/src/pluralize.ts
|
|
221
|
-
var import_pluralize = __toESM(__require("pluralize"));
|
|
222
|
-
|
|
223
|
-
// pkgs/@akanjs/common/src/capitalize.ts
|
|
224
|
-
var capitalize = (str) => {
|
|
225
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
// pkgs/@akanjs/common/src/Logger.ts
|
|
229
|
-
var import_dayjs5 = __toESM(__require("dayjs"));
|
|
230
|
-
var logLevels = ["trace", "verbose", "debug", "log", "info", "warn", "error"];
|
|
231
|
-
var clc = {
|
|
232
|
-
bold: (text) => `\x1B[1m${text}\x1B[0m`,
|
|
233
|
-
green: (text) => `\x1B[32m${text}\x1B[39m`,
|
|
234
|
-
yellow: (text) => `\x1B[33m${text}\x1B[39m`,
|
|
235
|
-
red: (text) => `\x1B[31m${text}\x1B[39m`,
|
|
236
|
-
magentaBright: (text) => `\x1B[95m${text}\x1B[39m`,
|
|
237
|
-
cyanBright: (text) => `\x1B[96m${text}\x1B[39m`
|
|
238
|
-
};
|
|
239
|
-
var colorizeMap = {
|
|
240
|
-
trace: clc.bold,
|
|
241
|
-
verbose: clc.cyanBright,
|
|
242
|
-
debug: clc.magentaBright,
|
|
243
|
-
log: clc.green,
|
|
244
|
-
info: clc.green,
|
|
245
|
-
warn: clc.yellow,
|
|
246
|
-
error: clc.red
|
|
247
|
-
};
|
|
248
|
-
var Logger = class _Logger {
|
|
249
|
-
static #ignoreCtxSet = /* @__PURE__ */ new Set([
|
|
250
|
-
"InstanceLoader",
|
|
251
|
-
"RoutesResolver",
|
|
252
|
-
"RouterExplorer",
|
|
253
|
-
"NestFactory",
|
|
254
|
-
"WebSocketsController",
|
|
255
|
-
"GraphQLModule",
|
|
256
|
-
"NestApplication"
|
|
257
|
-
]);
|
|
258
|
-
static level = process.env.NEXT_PUBLIC_LOG_LEVEL ?? "log";
|
|
259
|
-
static #levelIdx = logLevels.findIndex((l) => l === process.env.NEXT_PUBLIC_LOG_LEVEL);
|
|
260
|
-
static #startAt = (0, import_dayjs5.default)();
|
|
261
|
-
static setLevel(level) {
|
|
262
|
-
this.level = level;
|
|
263
|
-
this.#levelIdx = logLevels.findIndex((l) => l === level);
|
|
264
|
-
}
|
|
265
|
-
name;
|
|
266
|
-
constructor(name) {
|
|
267
|
-
this.name = name;
|
|
268
|
-
}
|
|
269
|
-
trace(msg, context = "") {
|
|
270
|
-
if (_Logger.#levelIdx <= 0)
|
|
271
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "trace");
|
|
272
|
-
}
|
|
273
|
-
verbose(msg, context = "") {
|
|
274
|
-
if (_Logger.#levelIdx <= 1)
|
|
275
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "verbose");
|
|
276
|
-
}
|
|
277
|
-
debug(msg, context = "") {
|
|
278
|
-
if (_Logger.#levelIdx <= 2)
|
|
279
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "debug");
|
|
280
|
-
}
|
|
281
|
-
log(msg, context = "") {
|
|
282
|
-
if (_Logger.#levelIdx <= 3)
|
|
283
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "log");
|
|
284
|
-
}
|
|
285
|
-
info(msg, context = "") {
|
|
286
|
-
if (_Logger.#levelIdx <= 4)
|
|
287
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "info");
|
|
288
|
-
}
|
|
289
|
-
warn(msg, context = "") {
|
|
290
|
-
if (_Logger.#levelIdx <= 5)
|
|
291
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "warn");
|
|
292
|
-
}
|
|
293
|
-
error(msg, context = "") {
|
|
294
|
-
if (_Logger.#levelIdx <= 6)
|
|
295
|
-
_Logger.#printMessages(this.name ?? "App", msg, context, "error");
|
|
296
|
-
}
|
|
297
|
-
raw(msg, method) {
|
|
298
|
-
_Logger.rawLog(msg, method);
|
|
299
|
-
}
|
|
300
|
-
rawLog(msg, method) {
|
|
301
|
-
_Logger.rawLog(msg, method);
|
|
302
|
-
}
|
|
303
|
-
static trace(msg, context = "") {
|
|
304
|
-
if (_Logger.#levelIdx <= 0)
|
|
305
|
-
_Logger.#printMessages("App", msg, context, "trace");
|
|
306
|
-
}
|
|
307
|
-
static verbose(msg, context = "") {
|
|
308
|
-
if (_Logger.#levelIdx <= 1)
|
|
309
|
-
_Logger.#printMessages("App", msg, context, "verbose");
|
|
310
|
-
}
|
|
311
|
-
static debug(msg, context = "") {
|
|
312
|
-
if (_Logger.#levelIdx <= 2)
|
|
313
|
-
_Logger.#printMessages("App", msg, context, "debug");
|
|
314
|
-
}
|
|
315
|
-
static log(msg, context = "") {
|
|
316
|
-
if (_Logger.#levelIdx <= 3)
|
|
317
|
-
_Logger.#printMessages("App", msg, context, "log");
|
|
318
|
-
}
|
|
319
|
-
static info(msg, context = "") {
|
|
320
|
-
if (_Logger.#levelIdx <= 4)
|
|
321
|
-
_Logger.#printMessages("App", msg, context, "info");
|
|
322
|
-
}
|
|
323
|
-
static warn(msg, context = "") {
|
|
324
|
-
if (_Logger.#levelIdx <= 5)
|
|
325
|
-
_Logger.#printMessages("App", msg, context, "warn");
|
|
326
|
-
}
|
|
327
|
-
static error(msg, context = "") {
|
|
328
|
-
if (_Logger.#levelIdx <= 6)
|
|
329
|
-
_Logger.#printMessages("App", msg, context, "error");
|
|
330
|
-
}
|
|
331
|
-
static #colorize(msg, logLevel) {
|
|
332
|
-
return colorizeMap[logLevel](msg);
|
|
333
|
-
}
|
|
334
|
-
static #printMessages(name, content, context, logLevel, writeStreamType = logLevel === "error" ? "stderr" : "stdout") {
|
|
335
|
-
if (this.#ignoreCtxSet.has(context))
|
|
336
|
-
return;
|
|
337
|
-
const now = (0, import_dayjs5.default)();
|
|
338
|
-
const processMsg = this.#colorize(
|
|
339
|
-
`[${name ?? "App"}] ${global.process?.pid ?? "window"} -`,
|
|
340
|
-
logLevel
|
|
341
|
-
);
|
|
342
|
-
const timestampMsg = now.format("MM/DD/YYYY, HH:mm:ss A");
|
|
343
|
-
const logLevelMsg = this.#colorize(logLevel.toUpperCase().padStart(7, " "), logLevel);
|
|
344
|
-
const contextMsg = context ? clc.yellow(`[${context}] `) : "";
|
|
345
|
-
const contentMsg = this.#colorize(content, logLevel);
|
|
346
|
-
const timeDiffMsg = clc.yellow(`+${now.diff(_Logger.#startAt, "ms")}ms`);
|
|
347
|
-
if (typeof window === "undefined")
|
|
348
|
-
process[writeStreamType].write(
|
|
349
|
-
`${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
|
|
350
|
-
`
|
|
351
|
-
);
|
|
352
|
-
else
|
|
353
|
-
console.log(`${processMsg} ${timestampMsg} ${logLevelMsg} ${contextMsg} ${contentMsg} ${timeDiffMsg}
|
|
354
|
-
`);
|
|
355
|
-
}
|
|
356
|
-
static rawLog(msg, method) {
|
|
357
|
-
this.raw(`${msg}
|
|
358
|
-
`, method);
|
|
359
|
-
}
|
|
360
|
-
static raw(msg, method) {
|
|
361
|
-
if (typeof window === "undefined" && method !== "console" && global.process)
|
|
362
|
-
global.process.stdout.write(msg);
|
|
363
|
-
else
|
|
364
|
-
console.log(msg);
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
// pkgs/@akanjs/common/src/lowerlize.ts
|
|
369
|
-
var lowerlize = (str) => {
|
|
370
|
-
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
371
|
-
};
|
|
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 __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
38
|
+
var __accessCheck = (obj, member, msg) => {
|
|
39
|
+
if (!member.has(obj))
|
|
40
|
+
throw TypeError("Cannot " + msg);
|
|
41
|
+
};
|
|
42
|
+
var __privateGet = (obj, member, getter) => {
|
|
43
|
+
__accessCheck(obj, member, "read from private field");
|
|
44
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
45
|
+
};
|
|
46
|
+
var __privateAdd = (obj, member, value) => {
|
|
47
|
+
if (member.has(obj))
|
|
48
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
49
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
50
|
+
};
|
|
51
|
+
var __privateMethod = (obj, member, method) => {
|
|
52
|
+
__accessCheck(obj, member, "access private method");
|
|
53
|
+
return method;
|
|
54
|
+
};
|
|
372
55
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
56
|
+
// pkgs/@akanjs/nest/index.ts
|
|
57
|
+
var nest_exports = {};
|
|
58
|
+
__export(nest_exports, {
|
|
59
|
+
Access: () => Access,
|
|
60
|
+
Account: () => Account2,
|
|
61
|
+
Admin: () => Admin,
|
|
62
|
+
AllExceptionsFilter: () => AllExceptionsFilter,
|
|
63
|
+
ArrayifyPipe: () => ArrayifyPipe,
|
|
64
|
+
BooleanPipe: () => BooleanPipe,
|
|
65
|
+
Cache: () => Cache,
|
|
66
|
+
CacheClient: () => CacheClient,
|
|
67
|
+
CacheInterceptor: () => CacheInterceptor,
|
|
68
|
+
Cron: () => Cron,
|
|
69
|
+
DatabaseClient: () => DatabaseClient,
|
|
70
|
+
DayjsPipe: () => DayjsPipe,
|
|
71
|
+
Every: () => Every,
|
|
72
|
+
Exporter: () => exporter_exports,
|
|
73
|
+
FileSystem: () => FileSystem,
|
|
74
|
+
FloatPipe: () => FloatPipe,
|
|
75
|
+
IntPipe: () => IntPipe,
|
|
76
|
+
Interval: () => Interval,
|
|
77
|
+
JSONPipe: () => JSONPipe,
|
|
78
|
+
LoggingInterceptor: () => LoggingInterceptor,
|
|
79
|
+
Me: () => Me,
|
|
80
|
+
MulterToUploadPipe: () => MulterToUploadPipe,
|
|
81
|
+
None: () => None,
|
|
82
|
+
Owner: () => Owner,
|
|
83
|
+
Public: () => Public,
|
|
84
|
+
RedisIoAdapter: () => RedisIoAdapter,
|
|
85
|
+
Req: () => Req,
|
|
86
|
+
Res: () => Res,
|
|
87
|
+
SALT_ROUNDS: () => SALT_ROUNDS,
|
|
88
|
+
SearchClient: () => SearchClient,
|
|
89
|
+
Self: () => Self,
|
|
90
|
+
SuperAdmin: () => SuperAdmin,
|
|
91
|
+
TimeoutInterceptor: () => TimeoutInterceptor,
|
|
92
|
+
Transaction: () => Transaction,
|
|
93
|
+
Try: () => Try,
|
|
94
|
+
User: () => User,
|
|
95
|
+
UserIp: () => UserIp,
|
|
96
|
+
Ws: () => Ws,
|
|
97
|
+
allow: () => allow,
|
|
98
|
+
exportToCsv: () => exportToCsv,
|
|
99
|
+
exportToJson: () => exportToJson,
|
|
100
|
+
generateAeskey: () => generateAeskey,
|
|
101
|
+
generateHost: () => generateHost,
|
|
102
|
+
generateJwtSecret: () => generateJwtSecret,
|
|
103
|
+
generateMeiliKey: () => generateMeiliKey,
|
|
104
|
+
generateMeiliUri: () => generateMeiliUri,
|
|
105
|
+
generateMongoUri: () => generateMongoUri,
|
|
106
|
+
generateRedisUri: () => generateRedisUri,
|
|
107
|
+
getArgs: () => getArgs,
|
|
108
|
+
getBodyPipes: () => getBodyPipes,
|
|
109
|
+
getQueryPipes: () => getQueryPipes,
|
|
110
|
+
getRequest: () => getRequest,
|
|
111
|
+
getResponse: () => getResponse,
|
|
112
|
+
getSocket: () => getSocket,
|
|
113
|
+
getSsoProviders: () => getSsoProviders,
|
|
114
|
+
guards: () => authGuards_exports,
|
|
115
|
+
initMongoDB: () => initMongoDB,
|
|
116
|
+
objPath: () => objPath,
|
|
117
|
+
readJson: () => readJson,
|
|
118
|
+
verifyAppleUser: () => verifyAppleUser,
|
|
119
|
+
verifyPayment: () => verifyPayment,
|
|
120
|
+
verifyToken: () => verifyToken
|
|
121
|
+
});
|
|
122
|
+
module.exports = __toCommonJS(nest_exports);
|
|
381
123
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
}
|
|
402
|
-
removeAllListeners() {
|
|
403
|
-
this.socket.removeAllListeners();
|
|
404
|
-
}
|
|
405
|
-
hasListeners(event) {
|
|
406
|
-
return this.socket.hasListeners(event);
|
|
407
|
-
}
|
|
408
|
-
emit(key, data) {
|
|
409
|
-
this.socket.emit(key, data);
|
|
410
|
-
}
|
|
411
|
-
subscribe(option) {
|
|
412
|
-
if (!this.roomSubscribeMap.has(option.roomId)) {
|
|
413
|
-
this.roomSubscribeMap.set(option.roomId, option);
|
|
414
|
-
this.socket.emit(option.key, { ...option.message, __subscribe__: true });
|
|
415
|
-
}
|
|
416
|
-
this.socket.on(option.roomId, option.handleEvent);
|
|
417
|
-
}
|
|
418
|
-
unsubscribe(roomId, handleEvent) {
|
|
419
|
-
this.socket.removeListener(roomId, handleEvent);
|
|
420
|
-
const option = this.roomSubscribeMap.get(roomId);
|
|
421
|
-
if (this.hasListeners(roomId) || !option)
|
|
422
|
-
return;
|
|
423
|
-
this.roomSubscribeMap.delete(roomId);
|
|
424
|
-
this.socket.emit(option.key, { ...option.message, __subscribe__: false });
|
|
425
|
-
}
|
|
426
|
-
disconnect() {
|
|
427
|
-
this.socket.disconnect();
|
|
428
|
-
return this;
|
|
429
|
-
}
|
|
430
|
-
};
|
|
431
|
-
var Client = class _Client {
|
|
432
|
-
static globalIoMap = /* @__PURE__ */ new Map();
|
|
433
|
-
static tokenStore = /* @__PURE__ */ new Map();
|
|
434
|
-
async waitUntilWebSocketConnected(ws = baseClientEnv.serverWsUri) {
|
|
435
|
-
if (baseClientEnv.side === "server")
|
|
436
|
-
return true;
|
|
437
|
-
while (!this.getIo(ws).socket.connected) {
|
|
438
|
-
Logger.verbose("waiting for websocket to initialize...");
|
|
439
|
-
await sleep(300);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
isInitialized = false;
|
|
443
|
-
uri = baseClientEnv.serverGraphqlUri;
|
|
444
|
-
ws = baseClientEnv.serverWsUri;
|
|
445
|
-
udp = null;
|
|
446
|
-
gql = (0, import_core.createClient)({ url: this.uri, fetch, exchanges: [import_core.cacheExchange, import_core.fetchExchange] });
|
|
447
|
-
jwt = null;
|
|
448
|
-
async getJwt() {
|
|
449
|
-
const isNextServer = baseClientEnv.side === "server" && baseEnv.operationType === "client";
|
|
450
|
-
if (isNextServer) {
|
|
451
|
-
const nextHeaders = __require("next/headers");
|
|
452
|
-
return (await nextHeaders.cookies?.())?.get("jwt")?.value ?? (await nextHeaders.headers?.())?.get("jwt") ?? this.jwt ?? null;
|
|
453
|
-
} else
|
|
454
|
-
return _Client.tokenStore.get(this) ?? null;
|
|
455
|
-
}
|
|
456
|
-
io = null;
|
|
457
|
-
init(data = {}) {
|
|
458
|
-
Object.assign(this, data);
|
|
459
|
-
this.setLink(data.uri);
|
|
460
|
-
this.setIo(data.ws);
|
|
461
|
-
this.isInitialized = true;
|
|
462
|
-
}
|
|
463
|
-
setIo(ws = baseClientEnv.serverWsUri) {
|
|
464
|
-
this.ws = ws;
|
|
465
|
-
const existingIo = _Client.globalIoMap.get(ws);
|
|
466
|
-
if (existingIo) {
|
|
467
|
-
this.io = existingIo;
|
|
468
|
-
return;
|
|
469
|
-
}
|
|
470
|
-
this.io = new SocketIo(ws);
|
|
471
|
-
_Client.globalIoMap.set(ws, this.io);
|
|
472
|
-
}
|
|
473
|
-
getIo(ws = baseClientEnv.serverWsUri) {
|
|
474
|
-
const existingIo = _Client.globalIoMap.get(ws);
|
|
475
|
-
if (existingIo)
|
|
476
|
-
return existingIo;
|
|
477
|
-
const io2 = new SocketIo(ws);
|
|
478
|
-
_Client.globalIoMap.set(ws, io2);
|
|
479
|
-
return io2;
|
|
480
|
-
}
|
|
481
|
-
setLink(uri = baseClientEnv.serverGraphqlUri) {
|
|
482
|
-
this.uri = uri;
|
|
483
|
-
this.gql = (0, import_core.createClient)({
|
|
484
|
-
url: this.uri,
|
|
485
|
-
fetch,
|
|
486
|
-
exchanges: [import_core.cacheExchange, import_core.fetchExchange],
|
|
487
|
-
// requestPolicy: "network-only",
|
|
488
|
-
fetchOptions: () => {
|
|
489
|
-
return {
|
|
490
|
-
headers: {
|
|
491
|
-
"apollo-require-preflight": "true",
|
|
492
|
-
...this.jwt ? { authorization: `Bearer ${this.jwt}` } : {}
|
|
493
|
-
}
|
|
494
|
-
};
|
|
495
|
-
}
|
|
496
|
-
});
|
|
497
|
-
}
|
|
498
|
-
setJwt(jwt3) {
|
|
499
|
-
_Client.tokenStore.set(this, jwt3);
|
|
500
|
-
}
|
|
501
|
-
reset() {
|
|
502
|
-
this.io?.disconnect();
|
|
503
|
-
this.io = null;
|
|
504
|
-
this.jwt = null;
|
|
505
|
-
}
|
|
506
|
-
clone(data = {}) {
|
|
507
|
-
const newClient = new _Client();
|
|
508
|
-
newClient.init({ ...this, ...data });
|
|
509
|
-
if (data.jwt)
|
|
510
|
-
_Client.tokenStore.set(newClient, data.jwt);
|
|
511
|
-
return newClient;
|
|
512
|
-
}
|
|
513
|
-
terminate() {
|
|
514
|
-
this.reset();
|
|
515
|
-
_Client.globalIoMap.forEach((io2) => io2.disconnect());
|
|
516
|
-
this.isInitialized = false;
|
|
517
|
-
}
|
|
518
|
-
setUdp(udp) {
|
|
519
|
-
this.udp = udp;
|
|
520
|
-
}
|
|
521
|
-
};
|
|
522
|
-
var client = new Client();
|
|
523
|
-
|
|
524
|
-
// pkgs/@akanjs/constant/src/types.ts
|
|
525
|
-
var DEFAULT_PAGE_SIZE = 20;
|
|
526
|
-
|
|
527
|
-
// pkgs/@akanjs/constant/src/scalar.ts
|
|
528
|
-
var import_reflect_metadata = __require("reflect-metadata");
|
|
529
|
-
var scalarExampleMap = /* @__PURE__ */ new Map([
|
|
530
|
-
[ID, "1234567890abcdef12345678"],
|
|
531
|
-
[Int, 0],
|
|
532
|
-
[Float, 0],
|
|
533
|
-
[String, "String"],
|
|
534
|
-
[Boolean, true],
|
|
535
|
-
[Date, (/* @__PURE__ */ new Date()).toISOString()],
|
|
536
|
-
[Upload, "FileUpload"],
|
|
537
|
-
[JSON2, {}],
|
|
538
|
-
[Map, {}]
|
|
539
|
-
]);
|
|
540
|
-
var getClassMeta = (modelRef) => {
|
|
541
|
-
const [target] = getNonArrayModel(modelRef);
|
|
542
|
-
const classMeta = Reflect.getMetadata("class", target.prototype);
|
|
543
|
-
if (!classMeta)
|
|
544
|
-
throw new Error(`No ClassMeta for this target ${target.name}`);
|
|
545
|
-
return classMeta;
|
|
546
|
-
};
|
|
547
|
-
var getFieldMetas = (modelRef) => {
|
|
548
|
-
const [target] = getNonArrayModel(modelRef);
|
|
549
|
-
const metadataMap = Reflect.getMetadata("fields", target.prototype) ?? /* @__PURE__ */ new Map();
|
|
550
|
-
const keySortMap = { id: -1, createdAt: 1, updatedAt: 2, removedAt: 3 };
|
|
551
|
-
return [...metadataMap.values()].sort((a, b) => (keySortMap[a.key] ?? 0) - (keySortMap[b.key] ?? 0));
|
|
552
|
-
};
|
|
553
|
-
var getFieldMetaMapOnPrototype = (prototype) => {
|
|
554
|
-
const metadataMap = Reflect.getMetadata("fields", prototype) ?? /* @__PURE__ */ new Map();
|
|
555
|
-
return new Map(metadataMap);
|
|
556
|
-
};
|
|
557
|
-
var setFieldMetaMapOnPrototype = (prototype, metadataMap) => {
|
|
558
|
-
Reflect.defineMetadata("fields", new Map(metadataMap), prototype);
|
|
559
|
-
};
|
|
560
|
-
|
|
561
|
-
// pkgs/@akanjs/constant/src/fieldMeta.ts
|
|
562
|
-
var applyFieldMeta = (modelRef, arrDepth, option, optionArrDepth) => {
|
|
563
|
-
const isArray = arrDepth > 0;
|
|
564
|
-
const isClass = !isGqlScalar(modelRef);
|
|
565
|
-
const isMap = isGqlMap(modelRef);
|
|
566
|
-
const { refName, type } = isClass ? getClassMeta(modelRef) : { refName: "", type: "scalar" };
|
|
567
|
-
const name = isClass ? refName : scalarNameMap.get(modelRef) ?? "Unknown";
|
|
568
|
-
if (isMap && !option.of)
|
|
569
|
-
throw new Error("Map type must have 'of' option");
|
|
570
|
-
return (prototype, key) => {
|
|
571
|
-
const metadata = {
|
|
572
|
-
nullable: option.nullable ?? false,
|
|
573
|
-
ref: option.ref,
|
|
574
|
-
refPath: option.refPath,
|
|
575
|
-
refType: option.refType,
|
|
576
|
-
default: option.default ?? (isArray ? [] : null),
|
|
577
|
-
type: option.type,
|
|
578
|
-
fieldType: option.fieldType ?? "property",
|
|
579
|
-
immutable: option.immutable ?? false,
|
|
580
|
-
min: option.min,
|
|
581
|
-
max: option.max,
|
|
582
|
-
enum: option.enum,
|
|
583
|
-
select: option.select ?? true,
|
|
584
|
-
minlength: option.minlength,
|
|
585
|
-
maxlength: option.maxlength,
|
|
586
|
-
query: option.query,
|
|
587
|
-
accumulate: option.accumulate,
|
|
588
|
-
example: option.example,
|
|
589
|
-
validate: option.validate,
|
|
590
|
-
key,
|
|
591
|
-
name,
|
|
592
|
-
isClass,
|
|
593
|
-
isScalar: type === "scalar",
|
|
594
|
-
modelRef,
|
|
595
|
-
arrDepth,
|
|
596
|
-
isArray,
|
|
597
|
-
optArrDepth: optionArrDepth,
|
|
598
|
-
isMap,
|
|
599
|
-
of: option.of,
|
|
600
|
-
text: option.text
|
|
601
|
-
};
|
|
602
|
-
const metadataMap = getFieldMetaMapOnPrototype(prototype);
|
|
603
|
-
metadataMap.set(key, metadata);
|
|
604
|
-
setFieldMetaMapOnPrototype(prototype, metadataMap);
|
|
605
|
-
};
|
|
606
|
-
};
|
|
607
|
-
var makeField = (customOption) => (returns, fieldOption) => {
|
|
608
|
-
const [modelRef, arrDepth] = getNonArrayModel(returns());
|
|
609
|
-
if (!fieldOption)
|
|
610
|
-
return applyFieldMeta(modelRef, arrDepth, { ...customOption }, arrDepth);
|
|
611
|
-
const [opt, optArrDepth] = getNonArrayModel(fieldOption);
|
|
612
|
-
return applyFieldMeta(modelRef, arrDepth, { ...opt, ...customOption }, optArrDepth);
|
|
613
|
-
};
|
|
614
|
-
var Field = {
|
|
615
|
-
Prop: makeField({ fieldType: "property" }),
|
|
616
|
-
Hidden: makeField({ fieldType: "hidden", nullable: true }),
|
|
617
|
-
Secret: makeField({ fieldType: "hidden", select: false, nullable: true }),
|
|
618
|
-
Resolve: makeField({ fieldType: "resolve" })
|
|
619
|
-
};
|
|
620
|
-
|
|
621
|
-
// pkgs/@akanjs/constant/src/constantDecorator.ts
|
|
622
|
-
var import_reflect_metadata2 = __require("reflect-metadata");
|
|
623
|
-
|
|
624
|
-
// pkgs/@akanjs/constant/src/filterMeta.ts
|
|
625
|
-
var setFilterMeta = (filterRef, filterMeta) => {
|
|
626
|
-
const existingFilterMeta = Reflect.getMetadata("filter", filterRef.prototype);
|
|
627
|
-
if (existingFilterMeta)
|
|
628
|
-
Object.assign(filterMeta.sort, existingFilterMeta.sort);
|
|
629
|
-
Reflect.defineMetadata("filter", filterMeta, filterRef.prototype);
|
|
630
|
-
};
|
|
631
|
-
var getFilterKeyMetaMapOnPrototype = (prototype) => {
|
|
632
|
-
const metadataMap = Reflect.getMetadata("filterKey", prototype) ?? /* @__PURE__ */ new Map();
|
|
633
|
-
return new Map(metadataMap);
|
|
634
|
-
};
|
|
635
|
-
var setFilterKeyMetaMapOnPrototype = (prototype, metadataMap) => {
|
|
636
|
-
Reflect.defineMetadata("filterKey", new Map(metadataMap), prototype);
|
|
637
|
-
};
|
|
638
|
-
var applyFilterKeyMeta = (option) => {
|
|
639
|
-
return (prototype, key, descriptor) => {
|
|
640
|
-
const metadata = { key, ...option, descriptor };
|
|
641
|
-
const metadataMap = getFilterKeyMetaMapOnPrototype(prototype);
|
|
642
|
-
metadataMap.set(key, metadata);
|
|
643
|
-
setFilterKeyMetaMapOnPrototype(prototype, metadataMap);
|
|
644
|
-
};
|
|
645
|
-
};
|
|
646
|
-
var makeFilter = (customOption) => (fieldOption) => {
|
|
647
|
-
return applyFilterKeyMeta({ ...customOption, ...fieldOption });
|
|
648
|
-
};
|
|
649
|
-
var getFilterArgMetasOnPrototype = (prototype, key) => {
|
|
650
|
-
const filterArgMetas = Reflect.getMetadata("filterArg", prototype, key) ?? [];
|
|
651
|
-
return filterArgMetas;
|
|
652
|
-
};
|
|
653
|
-
var setFilterArgMetasOnPrototype = (prototype, key, filterArgMetas) => {
|
|
654
|
-
Reflect.defineMetadata("filterArg", filterArgMetas, prototype, key);
|
|
655
|
-
};
|
|
656
|
-
var applyFilterArgMeta = (name, returns, argOption) => {
|
|
657
|
-
return (prototype, key, idx) => {
|
|
658
|
-
const [modelRef, arrDepth] = getNonArrayModel(returns());
|
|
659
|
-
const [opt, optArrDepth] = getNonArrayModel(argOption ?? {});
|
|
660
|
-
const filterArgMeta = { name, ...opt, modelRef, arrDepth, isArray: arrDepth > 0, optArrDepth };
|
|
661
|
-
const filterArgMetas = getFilterArgMetasOnPrototype(prototype, key);
|
|
662
|
-
filterArgMetas[idx] = filterArgMeta;
|
|
663
|
-
setFilterArgMetasOnPrototype(prototype, key, filterArgMetas);
|
|
664
|
-
};
|
|
665
|
-
};
|
|
666
|
-
var Filter = {
|
|
667
|
-
Mongo: makeFilter({ type: "mongo" }),
|
|
668
|
-
// Meili: makeFilter({ fieldType: "hidden", nullable: true }),
|
|
669
|
-
Arg: applyFilterArgMeta
|
|
670
|
-
};
|
|
671
|
-
|
|
672
|
-
// pkgs/@akanjs/constant/src/baseGql.ts
|
|
673
|
-
var import_reflect_metadata3 = __require("reflect-metadata");
|
|
674
|
-
var defaultFieldMeta = {
|
|
675
|
-
fieldType: "property",
|
|
676
|
-
immutable: false,
|
|
677
|
-
select: true,
|
|
678
|
-
isClass: false,
|
|
679
|
-
isScalar: true,
|
|
680
|
-
nullable: false,
|
|
681
|
-
isArray: false,
|
|
682
|
-
arrDepth: 0,
|
|
683
|
-
optArrDepth: 0,
|
|
684
|
-
default: null,
|
|
685
|
-
isMap: false
|
|
686
|
-
};
|
|
687
|
-
var idFieldMeta = { ...defaultFieldMeta, key: "id", name: "ID", modelRef: ID };
|
|
688
|
-
var createdAtFieldMeta = { ...defaultFieldMeta, key: "createdAt", name: "Date", modelRef: Date };
|
|
689
|
-
var updatedAtFieldMeta = { ...defaultFieldMeta, key: "updatedAt", name: "Date", modelRef: Date };
|
|
690
|
-
var removedAtFieldMeta = {
|
|
691
|
-
...defaultFieldMeta,
|
|
692
|
-
key: "removedAt",
|
|
693
|
-
name: "Date",
|
|
694
|
-
modelRef: Date,
|
|
695
|
-
nullable: true,
|
|
696
|
-
default: null
|
|
697
|
-
};
|
|
698
|
-
|
|
699
|
-
// pkgs/@akanjs/constant/src/classMeta.ts
|
|
700
|
-
var import_reflect_metadata4 = __require("reflect-metadata");
|
|
701
|
-
var InputModelStorage = class {
|
|
702
|
-
};
|
|
703
|
-
var LightModelStorage = class {
|
|
704
|
-
};
|
|
705
|
-
var FullModelStorage = class {
|
|
706
|
-
};
|
|
707
|
-
var ScalarModelStorage = class {
|
|
708
|
-
};
|
|
709
|
-
var FilterModelStorage = class {
|
|
710
|
-
};
|
|
711
|
-
var hasTextField = (modelRef) => {
|
|
712
|
-
const fieldMetas = getFieldMetas(modelRef);
|
|
713
|
-
return fieldMetas.some(
|
|
714
|
-
(fieldMeta) => !!fieldMeta.text || fieldMeta.isScalar && fieldMeta.isClass && fieldMeta.select && hasTextField(fieldMeta.modelRef)
|
|
715
|
-
);
|
|
716
|
-
};
|
|
717
|
-
var applyClassMeta = (type, modelType, storage) => {
|
|
718
|
-
return function(refName) {
|
|
719
|
-
return function(target) {
|
|
720
|
-
const modelRef = target;
|
|
721
|
-
const classMeta = { refName, type, modelType, modelRef, hasTextField: hasTextField(modelRef) };
|
|
722
|
-
Reflect.defineMetadata("class", classMeta, modelRef.prototype);
|
|
723
|
-
Reflect.defineMetadata(refName, modelRef, storage.prototype);
|
|
724
|
-
};
|
|
725
|
-
};
|
|
726
|
-
};
|
|
727
|
-
var applyFilterMeta = (storage) => {
|
|
728
|
-
return function(refName) {
|
|
729
|
-
return function(target) {
|
|
730
|
-
const modelRef = target;
|
|
731
|
-
setFilterMeta(modelRef, { refName, sort: {} });
|
|
732
|
-
Reflect.defineMetadata(refName, modelRef, storage.prototype);
|
|
733
|
-
};
|
|
734
|
-
};
|
|
735
|
-
};
|
|
736
|
-
var Model = {
|
|
737
|
-
Light: applyClassMeta("light", "data", LightModelStorage),
|
|
738
|
-
Object: applyClassMeta("full", "ephemeral", FullModelStorage),
|
|
739
|
-
Full: applyClassMeta("full", "data", FullModelStorage),
|
|
740
|
-
Input: applyClassMeta("input", "data", InputModelStorage),
|
|
741
|
-
Scalar: applyClassMeta("scalar", "data", ScalarModelStorage),
|
|
742
|
-
Summary: applyClassMeta("scalar", "summary", ScalarModelStorage),
|
|
743
|
-
Insight: applyClassMeta("scalar", "insight", ScalarModelStorage),
|
|
744
|
-
Filter: applyFilterMeta(FilterModelStorage)
|
|
745
|
-
};
|
|
746
|
-
|
|
747
|
-
// pkgs/@akanjs/signal/src/immerify.ts
|
|
748
|
-
var import_immer = __require("immer");
|
|
749
|
-
|
|
750
|
-
// pkgs/@akanjs/signal/src/signalDecorators.ts
|
|
751
|
-
var import_reflect_metadata5 = __require("reflect-metadata");
|
|
752
|
-
var createArgMetaDecorator = (type) => {
|
|
753
|
-
return function(option = {}) {
|
|
754
|
-
return function(prototype, key, idx) {
|
|
755
|
-
const argMetas = getArgMetasOnPrototype(prototype, key);
|
|
756
|
-
argMetas[idx] = { key, idx, type, option };
|
|
757
|
-
setArgMetasOnPrototype(prototype, key, argMetas);
|
|
758
|
-
};
|
|
759
|
-
};
|
|
760
|
-
};
|
|
761
|
-
var Account = createArgMetaDecorator("Account");
|
|
762
|
-
var defaultAccount = {
|
|
763
|
-
__InternalArg__: "Account",
|
|
764
|
-
appName: baseEnv.appName,
|
|
765
|
-
environment: baseEnv.environment
|
|
766
|
-
};
|
|
767
|
-
var Self = createArgMetaDecorator("Self");
|
|
768
|
-
var Me = createArgMetaDecorator("Me");
|
|
769
|
-
var UserIp = createArgMetaDecorator("UserIp");
|
|
770
|
-
var Access = createArgMetaDecorator("Access");
|
|
771
|
-
var Req = createArgMetaDecorator("Req");
|
|
772
|
-
var Res = createArgMetaDecorator("Res");
|
|
773
|
-
var Ws = createArgMetaDecorator("Ws");
|
|
774
|
-
var Job = createArgMetaDecorator("Job");
|
|
775
|
-
var getQuery = (allow2) => function(returns, signalOption = {}, guards = []) {
|
|
776
|
-
return (prototype, key, descriptor) => {
|
|
777
|
-
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
778
|
-
metadataMap.set(key, {
|
|
779
|
-
returns,
|
|
780
|
-
signalOption,
|
|
781
|
-
key,
|
|
782
|
-
descriptor,
|
|
783
|
-
guards: [allow2, ...guards],
|
|
784
|
-
type: "Query"
|
|
785
|
-
});
|
|
786
|
-
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
787
|
-
};
|
|
788
|
-
};
|
|
789
|
-
var getMutation = (allow2) => function(returns, signalOption = {}, guards = []) {
|
|
790
|
-
return (prototype, key, descriptor) => {
|
|
791
|
-
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
792
|
-
metadataMap.set(key, {
|
|
793
|
-
returns,
|
|
794
|
-
signalOption,
|
|
795
|
-
key,
|
|
796
|
-
descriptor,
|
|
797
|
-
guards: [allow2, ...guards],
|
|
798
|
-
type: "Mutation"
|
|
799
|
-
});
|
|
800
|
-
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
801
|
-
};
|
|
802
|
-
};
|
|
803
|
-
var getMessage = (allow2) => function(returns, signalOption = {}, guards = []) {
|
|
804
|
-
return (prototype, key, descriptor) => {
|
|
805
|
-
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
806
|
-
metadataMap.set(key, {
|
|
807
|
-
returns,
|
|
808
|
-
signalOption,
|
|
809
|
-
key,
|
|
810
|
-
descriptor,
|
|
811
|
-
guards: [allow2, ...guards],
|
|
812
|
-
type: "Message"
|
|
813
|
-
});
|
|
814
|
-
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
815
|
-
};
|
|
816
|
-
};
|
|
817
|
-
var getPubsub = (allow2) => function(returns, signalOption = {}, guards = []) {
|
|
818
|
-
return (prototype, key, descriptor) => {
|
|
819
|
-
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
820
|
-
metadataMap.set(key, {
|
|
821
|
-
returns,
|
|
822
|
-
signalOption,
|
|
823
|
-
key,
|
|
824
|
-
descriptor,
|
|
825
|
-
guards: [allow2, ...guards],
|
|
826
|
-
type: "Pubsub"
|
|
827
|
-
});
|
|
828
|
-
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
829
|
-
};
|
|
830
|
-
};
|
|
831
|
-
var getProcess = (serverType) => function(returns, signalOption = {}) {
|
|
832
|
-
return (prototype, key, descriptor) => {
|
|
833
|
-
const metadataMap = getGqlMetaMapOnPrototype(prototype);
|
|
834
|
-
metadataMap.set(key, {
|
|
835
|
-
returns,
|
|
836
|
-
signalOption: { ...signalOption, serverType: lowerlize(serverType) },
|
|
837
|
-
key,
|
|
838
|
-
descriptor,
|
|
839
|
-
guards: ["None"],
|
|
840
|
-
type: "Process"
|
|
841
|
-
});
|
|
842
|
-
setGqlMetaMapOnPrototype(prototype, metadataMap);
|
|
843
|
-
};
|
|
844
|
-
};
|
|
845
|
-
var Query = {
|
|
846
|
-
Public: getQuery("Public"),
|
|
847
|
-
Every: getQuery("Every"),
|
|
848
|
-
Admin: getQuery("Admin"),
|
|
849
|
-
User: getQuery("User"),
|
|
850
|
-
SuperAdmin: getQuery("SuperAdmin"),
|
|
851
|
-
None: getQuery("None"),
|
|
852
|
-
Owner: getQuery("Owner")
|
|
853
|
-
};
|
|
854
|
-
var Mutation = {
|
|
855
|
-
Public: getMutation("Public"),
|
|
856
|
-
Every: getMutation("Every"),
|
|
857
|
-
Admin: getMutation("Admin"),
|
|
858
|
-
User: getMutation("User"),
|
|
859
|
-
SuperAdmin: getMutation("SuperAdmin"),
|
|
860
|
-
None: getMutation("None"),
|
|
861
|
-
Owner: getMutation("Owner")
|
|
862
|
-
};
|
|
863
|
-
var Message = {
|
|
864
|
-
Public: getMessage("Public"),
|
|
865
|
-
Every: getMessage("Every"),
|
|
866
|
-
Admin: getMessage("Admin"),
|
|
867
|
-
User: getMessage("User"),
|
|
868
|
-
SuperAdmin: getMessage("SuperAdmin"),
|
|
869
|
-
None: getMessage("None"),
|
|
870
|
-
Owner: getMessage("Owner")
|
|
871
|
-
};
|
|
872
|
-
var Pubsub = {
|
|
873
|
-
Public: getPubsub("Public"),
|
|
874
|
-
Every: getPubsub("Every"),
|
|
875
|
-
Admin: getPubsub("Admin"),
|
|
876
|
-
User: getPubsub("User"),
|
|
877
|
-
SuperAdmin: getPubsub("SuperAdmin"),
|
|
878
|
-
None: getPubsub("None"),
|
|
879
|
-
Owner: getPubsub("Owner")
|
|
880
|
-
};
|
|
881
|
-
var Process = {
|
|
882
|
-
Federation: getProcess("Federation"),
|
|
883
|
-
Batch: getProcess("Batch"),
|
|
884
|
-
All: getProcess("All")
|
|
885
|
-
};
|
|
886
|
-
var getArg = (type) => function(name, returns, argsOption = {}) {
|
|
887
|
-
return function(prototype, key, idx) {
|
|
888
|
-
const argMetas = getArgMetasOnPrototype(prototype, key);
|
|
889
|
-
argMetas[idx] = { name, returns, argsOption, key, idx, type };
|
|
890
|
-
setArgMetasOnPrototype(prototype, key, argMetas);
|
|
124
|
+
// pkgs/@akanjs/nest/src/authorization.ts
|
|
125
|
+
var import_base = require("@akanjs/base");
|
|
126
|
+
var import_signal = require("@akanjs/signal");
|
|
127
|
+
var import_apollo = require("@nestjs/apollo");
|
|
128
|
+
var jwt = __toESM(require("jsonwebtoken"));
|
|
129
|
+
var verifyToken = (secret, authorization) => {
|
|
130
|
+
const [type, token] = authorization?.split(" ") ?? [void 0, void 0];
|
|
131
|
+
if (!token || type !== "Bearer")
|
|
132
|
+
return import_signal.defaultAccount;
|
|
133
|
+
try {
|
|
134
|
+
const account = jwt.verify(token, secret);
|
|
135
|
+
if (account.appName !== import_base.baseEnv.appName || account.environment !== import_base.baseEnv.environment)
|
|
136
|
+
return import_signal.defaultAccount;
|
|
137
|
+
return {
|
|
138
|
+
__InternalArg__: "Account",
|
|
139
|
+
self: account.self && !account.self.removedAt ? account.self : void 0,
|
|
140
|
+
me: account.me && !account.me.removedAt ? account.me : void 0,
|
|
141
|
+
appName: account.appName,
|
|
142
|
+
environment: account.environment
|
|
891
143
|
};
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
var getGqlMeta = (sigRef, key) => {
|
|
902
|
-
const gqlMetaMap = Reflect.getMetadata("gql", sigRef.prototype);
|
|
903
|
-
if (!gqlMetaMap)
|
|
904
|
-
throw new Error(`No GqlMeta found for ${sigRef.name}`);
|
|
905
|
-
const gqlMeta = gqlMetaMap.get(key);
|
|
906
|
-
if (!gqlMeta)
|
|
907
|
-
throw new Error(`No GqlMeta found for ${key}`);
|
|
908
|
-
return gqlMeta;
|
|
909
|
-
};
|
|
910
|
-
var getGqlMetaMapOnPrototype = (prototype) => {
|
|
911
|
-
const gqlMetaMap = Reflect.getMetadata("gql", prototype);
|
|
912
|
-
return gqlMetaMap ?? /* @__PURE__ */ new Map();
|
|
913
|
-
};
|
|
914
|
-
var setGqlMetaMapOnPrototype = (prototype, gqlMetaMap) => {
|
|
915
|
-
Reflect.defineMetadata("gql", gqlMetaMap, prototype);
|
|
916
|
-
};
|
|
917
|
-
var getArgMetasOnPrototype = (prototype, key) => {
|
|
918
|
-
return Reflect.getMetadata("args", prototype, key) ?? [];
|
|
919
|
-
};
|
|
920
|
-
var setArgMetasOnPrototype = (prototype, key, argMetas) => {
|
|
921
|
-
Reflect.defineMetadata("args", argMetas, prototype, key);
|
|
922
|
-
};
|
|
923
|
-
|
|
924
|
-
// pkgs/@akanjs/signal/src/gql.ts
|
|
925
|
-
var scalarDeserializeMap = /* @__PURE__ */ new Map([
|
|
926
|
-
[Date, (value) => dayjs(value)],
|
|
927
|
-
[String, (value) => value],
|
|
928
|
-
[ID, (value) => value],
|
|
929
|
-
[Boolean, (value) => value],
|
|
930
|
-
[Int, (value) => value],
|
|
931
|
-
[Float, (value) => value],
|
|
932
|
-
[JSON2, (value) => value]
|
|
933
|
-
]);
|
|
934
|
-
var getDeserializeFn = (inputRef) => {
|
|
935
|
-
const deserializeFn = scalarDeserializeMap.get(inputRef);
|
|
936
|
-
if (!deserializeFn)
|
|
937
|
-
return (value) => value;
|
|
938
|
-
return deserializeFn;
|
|
939
|
-
};
|
|
940
|
-
var deserializeInput = (value, inputRef, arrDepth) => {
|
|
941
|
-
if (arrDepth && Array.isArray(value))
|
|
942
|
-
return value.map((v) => deserializeInput(v, inputRef, arrDepth - 1));
|
|
943
|
-
else if (inputRef.prototype === Map.prototype) {
|
|
944
|
-
const [valueRef] = getNonArrayModel(inputRef);
|
|
945
|
-
const deserializeFn = getDeserializeFn(valueRef);
|
|
946
|
-
return Object.fromEntries(
|
|
947
|
-
[...value.entries()].map(([key, val]) => [key, applyFnToArrayObjects(val, deserializeFn)])
|
|
948
|
-
);
|
|
949
|
-
} else if (isGqlScalar(inputRef)) {
|
|
950
|
-
const deserializeFn = getDeserializeFn(inputRef);
|
|
951
|
-
return deserializeFn(value);
|
|
952
|
-
}
|
|
953
|
-
const classMeta = getClassMeta(inputRef);
|
|
954
|
-
if (classMeta.type !== "scalar")
|
|
955
|
-
return value;
|
|
956
|
-
else
|
|
957
|
-
return Object.fromEntries(
|
|
958
|
-
getFieldMetas(inputRef).map((fieldMeta) => [
|
|
959
|
-
fieldMeta.key,
|
|
960
|
-
deserializeInput(value[fieldMeta.key], fieldMeta.modelRef, fieldMeta.arrDepth)
|
|
961
|
-
])
|
|
962
|
-
);
|
|
963
|
-
};
|
|
964
|
-
var deserializeArg = (argMeta, value) => {
|
|
965
|
-
const [returnRef, arrDepth] = getNonArrayModel(argMeta.returns());
|
|
966
|
-
if (argMeta.argsOption.nullable && (value === null || value === void 0))
|
|
967
|
-
return null;
|
|
968
|
-
else if (!argMeta.argsOption.nullable && (value === null || value === void 0))
|
|
969
|
-
throw new Error(`Invalid Value (Nullable) in ${argMeta.name} for value ${value}`);
|
|
970
|
-
return deserializeInput(value, returnRef, arrDepth);
|
|
971
|
-
};
|
|
972
|
-
|
|
973
|
-
// pkgs/@akanjs/signal/src/baseFetch.ts
|
|
974
|
-
var nativeFetch = fetch;
|
|
975
|
-
var baseFetch = Object.assign(nativeFetch, {
|
|
976
|
-
client,
|
|
977
|
-
clone: function(option = {}) {
|
|
978
|
-
return {
|
|
979
|
-
...this,
|
|
980
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
981
|
-
client: this.client.clone(option)
|
|
982
|
-
};
|
|
983
|
-
}
|
|
984
|
-
});
|
|
985
|
-
|
|
986
|
-
// pkgs/@akanjs/nest/src/authorization.ts
|
|
987
|
-
var import_apollo = __require("@nestjs/apollo");
|
|
988
|
-
var jwt = __toESM(__require("jsonwebtoken"));
|
|
989
|
-
var verifyToken = (secret, authorization) => {
|
|
990
|
-
const [type, token] = authorization?.split(" ") ?? [void 0, void 0];
|
|
991
|
-
if (!token || type !== "Bearer")
|
|
992
|
-
return defaultAccount;
|
|
993
|
-
try {
|
|
994
|
-
const account = jwt.verify(token, secret);
|
|
995
|
-
if (account.appName !== baseEnv.appName || account.environment !== baseEnv.environment)
|
|
996
|
-
return defaultAccount;
|
|
997
|
-
return {
|
|
998
|
-
__InternalArg__: "Account",
|
|
999
|
-
self: account.self && !account.self.removedAt ? account.self : void 0,
|
|
1000
|
-
me: account.me && !account.me.removedAt ? account.me : void 0,
|
|
1001
|
-
appName: account.appName,
|
|
1002
|
-
environment: account.environment
|
|
1003
|
-
};
|
|
1004
|
-
} catch (e) {
|
|
1005
|
-
return defaultAccount;
|
|
1006
|
-
}
|
|
1007
|
-
};
|
|
1008
|
-
var allow = (account, roles, userId) => {
|
|
1009
|
-
if (!account)
|
|
1010
|
-
throw new import_apollo.AuthenticationError("No Authentication Account");
|
|
1011
|
-
for (const role of roles) {
|
|
1012
|
-
if (role === "user" && account.self?.roles.includes("user"))
|
|
1013
|
-
return true;
|
|
1014
|
-
else if (role === "admin" && account.me?.roles.includes("admin"))
|
|
1015
|
-
return true;
|
|
1016
|
-
else if (role === "superAdmin" && account.me?.roles.includes("superAdmin"))
|
|
1017
|
-
return true;
|
|
1018
|
-
}
|
|
1019
|
-
throw new import_apollo.AuthenticationError(
|
|
1020
|
-
`No Authentication With Roles: ${roles.join(", ")}, Your roles are ${[
|
|
1021
|
-
...account.self?.roles ?? [],
|
|
1022
|
-
...account.me?.roles ?? []
|
|
1023
|
-
].join(", ")}${!account.self?.roles.length && !account.me?.roles.length ? " (No Roles)" : ""}`
|
|
1024
|
-
);
|
|
1025
|
-
};
|
|
1026
|
-
|
|
1027
|
-
// pkgs/@akanjs/nest/src/authGuards.ts
|
|
1028
|
-
var authGuards_exports = {};
|
|
1029
|
-
__export(authGuards_exports, {
|
|
1030
|
-
Admin: () => Admin,
|
|
1031
|
-
Every: () => Every,
|
|
1032
|
-
None: () => None,
|
|
1033
|
-
Owner: () => Owner,
|
|
1034
|
-
Public: () => Public,
|
|
1035
|
-
SuperAdmin: () => SuperAdmin,
|
|
1036
|
-
User: () => User,
|
|
1037
|
-
getArgs: () => getArgs,
|
|
1038
|
-
getRequest: () => getRequest,
|
|
1039
|
-
getResponse: () => getResponse,
|
|
1040
|
-
getSocket: () => getSocket
|
|
1041
|
-
});
|
|
1042
|
-
var import_common6 = __require("@nestjs/common");
|
|
1043
|
-
var import_graphql = __require("@nestjs/graphql");
|
|
1044
|
-
var getRequest = (context) => {
|
|
1045
|
-
const type = context.getType();
|
|
1046
|
-
if (type === "ws")
|
|
1047
|
-
throw new Error("Getting Request in Websocket is not allowed");
|
|
1048
|
-
return type === "http" ? context.switchToHttp().getRequest() : import_graphql.GqlExecutionContext.create(context).getContext().req;
|
|
1049
|
-
};
|
|
1050
|
-
var getResponse = (context) => {
|
|
1051
|
-
const type = context.getType();
|
|
1052
|
-
if (type === "ws")
|
|
1053
|
-
throw new Error("Getting Response in Websocket is not allowed");
|
|
1054
|
-
return type === "http" ? context.switchToHttp().getResponse() : import_graphql.GqlExecutionContext.create(context).getContext().req.res;
|
|
1055
|
-
};
|
|
1056
|
-
var getArgs = (context) => {
|
|
1057
|
-
const type = context.getType();
|
|
1058
|
-
if (type === "ws")
|
|
1059
|
-
throw new Error("Getting Args in Websocket is not allowed");
|
|
1060
|
-
if (type === "graphql")
|
|
1061
|
-
return import_graphql.GqlExecutionContext.create(context).getArgs();
|
|
1062
|
-
else if (type === "http") {
|
|
1063
|
-
const { params, query, body } = context.switchToHttp().getRequest();
|
|
1064
|
-
return { ...params, ...query, ...body };
|
|
1065
|
-
} else
|
|
1066
|
-
throw new Error("Getting Args in Unknown context is not allowed");
|
|
1067
|
-
};
|
|
1068
|
-
var getSocket = (context) => {
|
|
1069
|
-
const type = context.getType();
|
|
1070
|
-
if (type !== "ws")
|
|
1071
|
-
throw new Error("Getting Socket in Http or GraphQL is not allowed");
|
|
1072
|
-
const socket = context.getArgByIndex(0);
|
|
1073
|
-
return socket;
|
|
1074
|
-
};
|
|
1075
|
-
var Public = class {
|
|
1076
|
-
canActivate(context) {
|
|
144
|
+
} catch (e) {
|
|
145
|
+
return import_signal.defaultAccount;
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
var allow = (account, roles, userId) => {
|
|
149
|
+
if (!account)
|
|
150
|
+
throw new import_apollo.AuthenticationError("No Authentication Account");
|
|
151
|
+
for (const role of roles) {
|
|
152
|
+
if (role === "user" && account.self?.roles.includes("user"))
|
|
1077
153
|
return true;
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
], None);
|
|
1091
|
-
var Every = class {
|
|
1092
|
-
canActivate(context) {
|
|
1093
|
-
const { account } = getRequest(context);
|
|
1094
|
-
return allow(account, ["user", "admin", "superAdmin"]);
|
|
1095
|
-
}
|
|
1096
|
-
};
|
|
1097
|
-
Every = __decorateClass([
|
|
1098
|
-
(0, import_common6.Injectable)()
|
|
1099
|
-
], Every);
|
|
1100
|
-
var Owner = class {
|
|
1101
|
-
canActivate(context) {
|
|
1102
|
-
const { account } = getRequest(context);
|
|
1103
|
-
return allow(account, ["user", "admin", "superAdmin"]);
|
|
1104
|
-
}
|
|
1105
|
-
};
|
|
1106
|
-
Owner = __decorateClass([
|
|
1107
|
-
(0, import_common6.Injectable)()
|
|
1108
|
-
], Owner);
|
|
1109
|
-
var Admin = class {
|
|
1110
|
-
canActivate(context) {
|
|
1111
|
-
const { account } = getRequest(context);
|
|
1112
|
-
return allow(account, ["admin", "superAdmin"]);
|
|
1113
|
-
}
|
|
1114
|
-
};
|
|
1115
|
-
Admin = __decorateClass([
|
|
1116
|
-
(0, import_common6.Injectable)()
|
|
1117
|
-
], Admin);
|
|
1118
|
-
var SuperAdmin = class {
|
|
1119
|
-
canActivate(context) {
|
|
1120
|
-
const { account } = getRequest(context);
|
|
1121
|
-
return allow(account, ["superAdmin"]);
|
|
1122
|
-
}
|
|
1123
|
-
};
|
|
1124
|
-
SuperAdmin = __decorateClass([
|
|
1125
|
-
(0, import_common6.Injectable)()
|
|
1126
|
-
], SuperAdmin);
|
|
1127
|
-
var User = class {
|
|
1128
|
-
canActivate(context) {
|
|
1129
|
-
const { account } = getRequest(context);
|
|
1130
|
-
return allow(account, ["user"]);
|
|
1131
|
-
}
|
|
1132
|
-
};
|
|
1133
|
-
User = __decorateClass([
|
|
1134
|
-
(0, import_common6.Injectable)()
|
|
1135
|
-
], User);
|
|
154
|
+
else if (role === "admin" && account.me?.roles.includes("admin"))
|
|
155
|
+
return true;
|
|
156
|
+
else if (role === "superAdmin" && account.me?.roles.includes("superAdmin"))
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
throw new import_apollo.AuthenticationError(
|
|
160
|
+
`No Authentication With Roles: ${roles.join(", ")}, Your roles are ${[
|
|
161
|
+
...account.self?.roles ?? [],
|
|
162
|
+
...account.me?.roles ?? []
|
|
163
|
+
].join(", ")}${!account.self?.roles.length && !account.me?.roles.length ? " (No Roles)" : ""}`
|
|
164
|
+
);
|
|
165
|
+
};
|
|
1136
166
|
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
167
|
+
// pkgs/@akanjs/nest/src/authGuards.ts
|
|
168
|
+
var authGuards_exports = {};
|
|
169
|
+
__export(authGuards_exports, {
|
|
170
|
+
Admin: () => Admin,
|
|
171
|
+
Every: () => Every,
|
|
172
|
+
None: () => None,
|
|
173
|
+
Owner: () => Owner,
|
|
174
|
+
Public: () => Public,
|
|
175
|
+
SuperAdmin: () => SuperAdmin,
|
|
176
|
+
User: () => User,
|
|
177
|
+
getArgs: () => getArgs,
|
|
178
|
+
getRequest: () => getRequest,
|
|
179
|
+
getResponse: () => getResponse,
|
|
180
|
+
getSocket: () => getSocket
|
|
181
|
+
});
|
|
182
|
+
var import_common = require("@nestjs/common");
|
|
183
|
+
var import_graphql = require("@nestjs/graphql");
|
|
184
|
+
var getRequest = (context) => {
|
|
185
|
+
const type = context.getType();
|
|
186
|
+
if (type === "ws")
|
|
187
|
+
throw new Error("Getting Request in Websocket is not allowed");
|
|
188
|
+
return type === "http" ? context.switchToHttp().getRequest() : import_graphql.GqlExecutionContext.create(context).getContext().req;
|
|
189
|
+
};
|
|
190
|
+
var getResponse = (context) => {
|
|
191
|
+
const type = context.getType();
|
|
192
|
+
if (type === "ws")
|
|
193
|
+
throw new Error("Getting Response in Websocket is not allowed");
|
|
194
|
+
return type === "http" ? context.switchToHttp().getResponse() : import_graphql.GqlExecutionContext.create(context).getContext().req.res;
|
|
195
|
+
};
|
|
196
|
+
var getArgs = (context) => {
|
|
197
|
+
const type = context.getType();
|
|
198
|
+
if (type === "ws")
|
|
199
|
+
throw new Error("Getting Args in Websocket is not allowed");
|
|
200
|
+
if (type === "graphql")
|
|
201
|
+
return import_graphql.GqlExecutionContext.create(context).getArgs();
|
|
202
|
+
else if (type === "http") {
|
|
203
|
+
const { params, query, body } = context.switchToHttp().getRequest();
|
|
204
|
+
return { ...params, ...query, ...body };
|
|
205
|
+
} else
|
|
206
|
+
throw new Error("Getting Args in Unknown context is not allowed");
|
|
207
|
+
};
|
|
208
|
+
var getSocket = (context) => {
|
|
209
|
+
const type = context.getType();
|
|
210
|
+
if (type !== "ws")
|
|
211
|
+
throw new Error("Getting Socket in Http or GraphQL is not allowed");
|
|
212
|
+
const socket = context.getArgByIndex(0);
|
|
213
|
+
return socket;
|
|
214
|
+
};
|
|
215
|
+
var Public = class {
|
|
216
|
+
canActivate(context) {
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
Public = __decorateClass([
|
|
221
|
+
(0, import_common.Injectable)()
|
|
222
|
+
], Public);
|
|
223
|
+
var None = class {
|
|
224
|
+
canActivate() {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
None = __decorateClass([
|
|
229
|
+
(0, import_common.Injectable)()
|
|
230
|
+
], None);
|
|
231
|
+
var Every = class {
|
|
232
|
+
canActivate(context) {
|
|
1141
233
|
const { account } = getRequest(context);
|
|
1142
|
-
return account;
|
|
1143
|
-
}
|
|
1144
|
-
|
|
234
|
+
return allow(account, ["user", "admin", "superAdmin"]);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
Every = __decorateClass([
|
|
238
|
+
(0, import_common.Injectable)()
|
|
239
|
+
], Every);
|
|
240
|
+
var Owner = class {
|
|
241
|
+
canActivate(context) {
|
|
1145
242
|
const { account } = getRequest(context);
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
243
|
+
return allow(account, ["user", "admin", "superAdmin"]);
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
Owner = __decorateClass([
|
|
247
|
+
(0, import_common.Injectable)()
|
|
248
|
+
], Owner);
|
|
249
|
+
var Admin = class {
|
|
250
|
+
canActivate(context) {
|
|
1152
251
|
const { account } = getRequest(context);
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
mobileVendor: res.device.vendor,
|
|
1178
|
-
deviceType: res.device.type ?? "desktop",
|
|
1179
|
-
at: dayjs(),
|
|
1180
|
-
period: 0
|
|
1181
|
-
};
|
|
1182
|
-
});
|
|
1183
|
-
var Req2 = (0, import_common7.createParamDecorator)((option, context) => {
|
|
1184
|
-
return getRequest(context);
|
|
1185
|
-
});
|
|
1186
|
-
var Res2 = (0, import_common7.createParamDecorator)((option, context) => {
|
|
1187
|
-
return getResponse(context);
|
|
1188
|
-
});
|
|
1189
|
-
var Ws2 = (0, import_common7.createParamDecorator)((option, context) => {
|
|
1190
|
-
const socket = context.getArgByIndex(0);
|
|
1191
|
-
const { __subscribe__ } = context.getArgByIndex(1);
|
|
1192
|
-
return {
|
|
1193
|
-
socket,
|
|
1194
|
-
subscribe: __subscribe__,
|
|
1195
|
-
onDisconnect: (handler) => {
|
|
1196
|
-
socket.on("disconnect", handler);
|
|
1197
|
-
},
|
|
1198
|
-
onSubscribe: (handler) => {
|
|
1199
|
-
if (__subscribe__)
|
|
1200
|
-
handler();
|
|
1201
|
-
},
|
|
1202
|
-
onUnsubscribe: (handler) => {
|
|
1203
|
-
if (!__subscribe__)
|
|
1204
|
-
handler();
|
|
1205
|
-
}
|
|
1206
|
-
};
|
|
1207
|
-
});
|
|
252
|
+
return allow(account, ["admin", "superAdmin"]);
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
Admin = __decorateClass([
|
|
256
|
+
(0, import_common.Injectable)()
|
|
257
|
+
], Admin);
|
|
258
|
+
var SuperAdmin = class {
|
|
259
|
+
canActivate(context) {
|
|
260
|
+
const { account } = getRequest(context);
|
|
261
|
+
return allow(account, ["superAdmin"]);
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
SuperAdmin = __decorateClass([
|
|
265
|
+
(0, import_common.Injectable)()
|
|
266
|
+
], SuperAdmin);
|
|
267
|
+
var User = class {
|
|
268
|
+
canActivate(context) {
|
|
269
|
+
const { account } = getRequest(context);
|
|
270
|
+
return allow(account, ["user"]);
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
User = __decorateClass([
|
|
274
|
+
(0, import_common.Injectable)()
|
|
275
|
+
], User);
|
|
1208
276
|
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
277
|
+
// pkgs/@akanjs/nest/src/authentication.ts
|
|
278
|
+
var import_base2 = require("@akanjs/base");
|
|
279
|
+
var import_common2 = require("@nestjs/common");
|
|
280
|
+
var import_ua_parser_js = __toESM(require("ua-parser-js"));
|
|
281
|
+
var Account2 = (0, import_common2.createParamDecorator)((option, context) => {
|
|
282
|
+
const { account } = getRequest(context);
|
|
283
|
+
return account;
|
|
284
|
+
});
|
|
285
|
+
var Self = (0, import_common2.createParamDecorator)((option, context) => {
|
|
286
|
+
const { account } = getRequest(context);
|
|
287
|
+
const self = account.self;
|
|
288
|
+
if (!self && !option.nullable)
|
|
289
|
+
throw new import_common2.UnauthorizedException("No or Invalid Account in Self (User)");
|
|
290
|
+
return self;
|
|
291
|
+
});
|
|
292
|
+
var Me = (0, import_common2.createParamDecorator)((option, context) => {
|
|
293
|
+
const { account } = getRequest(context);
|
|
294
|
+
const me = account.me;
|
|
295
|
+
if (!me && !option.nullable)
|
|
296
|
+
throw new import_common2.UnauthorizedException("No or Invalid Account in Me (Admin)");
|
|
297
|
+
return me;
|
|
298
|
+
});
|
|
299
|
+
var UserIp = (0, import_common2.createParamDecorator)((option, context) => {
|
|
300
|
+
const req = getRequest(context);
|
|
301
|
+
const ip = req.ip;
|
|
302
|
+
if (!ip && !option.nullable)
|
|
303
|
+
throw new import_common2.UnauthorizedException("Invalid IP");
|
|
304
|
+
return { ip };
|
|
305
|
+
});
|
|
306
|
+
var Access = (0, import_common2.createParamDecorator)((option, context) => {
|
|
307
|
+
const req = getRequest(context);
|
|
308
|
+
const res = new import_ua_parser_js.default(req.userAgent).getResult();
|
|
309
|
+
if (!req.userAgent && !option.nullable)
|
|
310
|
+
throw new import_common2.UnauthorizedException("Invalid UserAgent");
|
|
311
|
+
return {
|
|
312
|
+
...req.geolocation ? JSON.parse(req.geolocation) : {},
|
|
313
|
+
osName: res.os.name,
|
|
314
|
+
osVersion: res.os.version,
|
|
315
|
+
browserName: res.browser.name,
|
|
316
|
+
browserVersion: res.browser.version,
|
|
317
|
+
mobileModel: res.device.model,
|
|
318
|
+
mobileVendor: res.device.vendor,
|
|
319
|
+
deviceType: res.device.type ?? "desktop",
|
|
320
|
+
at: (0, import_base2.dayjs)(),
|
|
321
|
+
period: 0
|
|
322
|
+
};
|
|
323
|
+
});
|
|
324
|
+
var Req = (0, import_common2.createParamDecorator)((option, context) => {
|
|
325
|
+
return getRequest(context);
|
|
326
|
+
});
|
|
327
|
+
var Res = (0, import_common2.createParamDecorator)((option, context) => {
|
|
328
|
+
return getResponse(context);
|
|
329
|
+
});
|
|
330
|
+
var Ws = (0, import_common2.createParamDecorator)((option, context) => {
|
|
331
|
+
const socket = context.getArgByIndex(0);
|
|
332
|
+
const { __subscribe__ } = context.getArgByIndex(1);
|
|
333
|
+
return {
|
|
334
|
+
socket,
|
|
335
|
+
subscribe: __subscribe__,
|
|
336
|
+
onDisconnect: (handler) => {
|
|
337
|
+
socket.on("disconnect", handler);
|
|
338
|
+
},
|
|
339
|
+
onSubscribe: (handler) => {
|
|
340
|
+
if (__subscribe__)
|
|
341
|
+
handler();
|
|
342
|
+
},
|
|
343
|
+
onUnsubscribe: (handler) => {
|
|
344
|
+
if (!__subscribe__)
|
|
345
|
+
handler();
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
// pkgs/@akanjs/nest/src/interceptors.ts
|
|
351
|
+
var import_common3 = require("@akanjs/common");
|
|
352
|
+
var import_signal2 = require("@akanjs/signal");
|
|
353
|
+
var import_common4 = require("@nestjs/common");
|
|
354
|
+
var import_graphql2 = require("@nestjs/graphql");
|
|
355
|
+
var import_rxjs = require("rxjs");
|
|
356
|
+
var import_operators = require("rxjs/operators");
|
|
357
|
+
var _logger, _CACHE_PREFIX, _generateCacheKey, generateCacheKey_fn, _getCache, getCache_fn, _setCache, setCache_fn;
|
|
358
|
+
var CacheInterceptor = class {
|
|
359
|
+
constructor(redis) {
|
|
360
|
+
this.redis = redis;
|
|
361
|
+
__privateAdd(this, _generateCacheKey);
|
|
362
|
+
__privateAdd(this, _getCache);
|
|
363
|
+
__privateAdd(this, _setCache);
|
|
364
|
+
__privateAdd(this, _logger, new import_common3.Logger("CacheInterceptor"));
|
|
365
|
+
__privateAdd(this, _CACHE_PREFIX, "signal:");
|
|
366
|
+
}
|
|
367
|
+
async intercept(context, next) {
|
|
368
|
+
const handler = context.getHandler();
|
|
369
|
+
const signalKey = handler.name;
|
|
370
|
+
const gqlMeta = (0, import_signal2.getGqlMeta)(context.getClass(), signalKey);
|
|
371
|
+
if (gqlMeta.type !== "Query" || !gqlMeta.signalOption.cache) {
|
|
372
|
+
if (gqlMeta.signalOption.cache)
|
|
373
|
+
__privateGet(this, _logger).warn(`CacheInterceptor: ${signalKey} is not Query endpoint or cache is not set`);
|
|
374
|
+
return next.handle();
|
|
375
|
+
}
|
|
376
|
+
const args = getArgs(context);
|
|
377
|
+
const cacheKey = __privateMethod(this, _generateCacheKey, generateCacheKey_fn).call(this, signalKey, args);
|
|
378
|
+
const cachedData = await __privateMethod(this, _getCache, getCache_fn).call(this, cacheKey);
|
|
379
|
+
if (cachedData) {
|
|
380
|
+
__privateGet(this, _logger).debug(`Cache hit for key: ${cacheKey}`);
|
|
1247
381
|
return next.handle().pipe(
|
|
1248
|
-
(0, import_operators.map)((
|
|
1249
|
-
const cacheDuration = gqlMeta.signalOption.cache;
|
|
1250
|
-
if (typeof cacheDuration === "number") {
|
|
1251
|
-
void __privateMethod(this, _setCache, setCache_fn).call(this, cacheKey, data, cacheDuration);
|
|
1252
|
-
__privateGet(this, _logger).debug(`Cache set for key: ${cacheKey}`);
|
|
1253
|
-
}
|
|
1254
|
-
return data;
|
|
1255
|
-
}),
|
|
382
|
+
(0, import_operators.map)(() => cachedData),
|
|
1256
383
|
(0, import_operators.catchError)((error) => {
|
|
1257
384
|
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
1258
385
|
__privateGet(this, _logger).error(`Error in cache interceptor for ${cacheKey}: ${errorMessage}`);
|
|
@@ -1260,875 +387,897 @@
|
|
|
1260
387
|
})
|
|
1261
388
|
);
|
|
1262
389
|
}
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
return
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
390
|
+
return next.handle().pipe(
|
|
391
|
+
(0, import_operators.map)((data) => {
|
|
392
|
+
const cacheDuration = gqlMeta.signalOption.cache;
|
|
393
|
+
if (typeof cacheDuration === "number") {
|
|
394
|
+
void __privateMethod(this, _setCache, setCache_fn).call(this, cacheKey, data, cacheDuration);
|
|
395
|
+
__privateGet(this, _logger).debug(`Cache set for key: ${cacheKey}`);
|
|
396
|
+
}
|
|
397
|
+
return data;
|
|
398
|
+
}),
|
|
399
|
+
(0, import_operators.catchError)((error) => {
|
|
400
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
401
|
+
__privateGet(this, _logger).error(`Error in cache interceptor for ${cacheKey}: ${errorMessage}`);
|
|
402
|
+
return (0, import_rxjs.throwError)(() => error);
|
|
403
|
+
})
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
_logger = new WeakMap();
|
|
408
|
+
_CACHE_PREFIX = new WeakMap();
|
|
409
|
+
_generateCacheKey = new WeakSet();
|
|
410
|
+
generateCacheKey_fn = function(signalKey, args) {
|
|
411
|
+
return `${__privateGet(this, _CACHE_PREFIX)}${signalKey}:${JSON.stringify(args)}`;
|
|
412
|
+
};
|
|
413
|
+
_getCache = new WeakSet();
|
|
414
|
+
getCache_fn = async function(key) {
|
|
415
|
+
try {
|
|
416
|
+
const cached = await this.redis.get(key);
|
|
417
|
+
if (!cached)
|
|
1281
418
|
return null;
|
|
1282
|
-
}
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
)
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
419
|
+
const { data } = JSON.parse(cached);
|
|
420
|
+
return data;
|
|
421
|
+
} catch (error) {
|
|
422
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
423
|
+
__privateGet(this, _logger).error(`Error retrieving cache for key ${key}: ${errorMessage}`);
|
|
424
|
+
return null;
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
_setCache = new WeakSet();
|
|
428
|
+
setCache_fn = async function(key, data, ttlMs) {
|
|
429
|
+
try {
|
|
430
|
+
const cacheData = { data, timestamp: Date.now() };
|
|
431
|
+
await this.redis.set(key, JSON.stringify(cacheData), { PX: ttlMs });
|
|
432
|
+
} catch (error) {
|
|
433
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
434
|
+
__privateGet(this, _logger).error(`Error setting cache for key ${key}: ${errorMessage}`);
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
CacheInterceptor = __decorateClass([
|
|
438
|
+
(0, import_common4.Injectable)(),
|
|
439
|
+
__decorateParam(0, (0, import_common4.Inject)("REDIS_CLIENT"))
|
|
440
|
+
], CacheInterceptor);
|
|
441
|
+
var TimeoutInterceptor = class {
|
|
442
|
+
intercept(context, next) {
|
|
443
|
+
const gqlMeta = (0, import_signal2.getGqlMeta)(context.getClass(), context.getHandler().name);
|
|
444
|
+
const timeoutMs = gqlMeta.signalOption.timeout ?? 3e4;
|
|
445
|
+
if (timeoutMs === 0)
|
|
446
|
+
return next.handle();
|
|
447
|
+
return next.handle().pipe(
|
|
448
|
+
(0, import_operators.timeout)(timeoutMs),
|
|
449
|
+
(0, import_operators.catchError)((err) => {
|
|
450
|
+
if (err instanceof import_rxjs.TimeoutError)
|
|
451
|
+
return (0, import_rxjs.throwError)(() => new import_common4.RequestTimeoutException());
|
|
452
|
+
return (0, import_rxjs.throwError)(() => err);
|
|
453
|
+
})
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
TimeoutInterceptor = __decorateClass([
|
|
458
|
+
(0, import_common4.Injectable)()
|
|
459
|
+
], TimeoutInterceptor);
|
|
460
|
+
var LoggingInterceptor = class {
|
|
461
|
+
logger = new import_common3.Logger("IO");
|
|
462
|
+
intercept(context, next) {
|
|
463
|
+
const gqlReq = context.getArgByIndex(3);
|
|
464
|
+
const req = getRequest(context);
|
|
465
|
+
const reqType = gqlReq?.parentType?.name ?? req.method;
|
|
466
|
+
const reqName = gqlReq?.fieldName ?? req.url;
|
|
467
|
+
const before = Date.now();
|
|
468
|
+
const ip = import_graphql2.GqlExecutionContext.create(context).getContext().req.ip;
|
|
469
|
+
this.logger.debug(`Before ${reqType}-${reqName} / ${ip} / ${before}`);
|
|
470
|
+
return next.handle().pipe(
|
|
471
|
+
(0, import_operators.tap)(() => {
|
|
472
|
+
const after = Date.now();
|
|
473
|
+
this.logger.debug(`After ${reqType}-${reqName} / ${ip} / ${after} (${after - before}ms)`);
|
|
474
|
+
})
|
|
475
|
+
);
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
LoggingInterceptor = __decorateClass([
|
|
479
|
+
(0, import_common4.Injectable)()
|
|
480
|
+
], LoggingInterceptor);
|
|
1338
481
|
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
}
|
|
482
|
+
// pkgs/@akanjs/nest/src/redis-io.adapter.ts
|
|
483
|
+
var import_common5 = require("@akanjs/common");
|
|
484
|
+
var import_platform_socket = require("@nestjs/platform-socket.io");
|
|
485
|
+
var import_redis_adapter = require("@socket.io/redis-adapter");
|
|
486
|
+
var import_redis = require("redis");
|
|
487
|
+
var RedisIoAdapter = class extends import_platform_socket.IoAdapter {
|
|
488
|
+
adapterConstructor;
|
|
489
|
+
logger = new import_common5.Logger("RedisIoAdapter");
|
|
490
|
+
server;
|
|
491
|
+
pubClient;
|
|
492
|
+
subClient;
|
|
493
|
+
option;
|
|
494
|
+
constructor(appOrHttpServer, option) {
|
|
495
|
+
super(appOrHttpServer);
|
|
496
|
+
this.option = option;
|
|
497
|
+
}
|
|
498
|
+
async connectToRedis(url) {
|
|
499
|
+
this.pubClient = (0, import_redis.createClient)({ url });
|
|
500
|
+
this.subClient = this.pubClient.duplicate();
|
|
501
|
+
this.pubClient.on("disconnect", (err) => {
|
|
502
|
+
this.logger.error(`Redis pub database is disconnected. Error: ${err}`);
|
|
503
|
+
void this.pubClient.connect();
|
|
504
|
+
});
|
|
505
|
+
this.subClient.on("disconnect", (err) => {
|
|
506
|
+
this.logger.error(`Redis sub database is disconnected. Error: ${err}`);
|
|
507
|
+
void this.subClient.connect();
|
|
508
|
+
});
|
|
509
|
+
this.pubClient.on("error", (err) => {
|
|
510
|
+
this.logger.error(`Redis pub database is errored. Error: ${err}`);
|
|
511
|
+
const reconnect = async () => {
|
|
512
|
+
await this.pubClient.quit();
|
|
513
|
+
await (0, import_common5.sleep)(1e3);
|
|
514
|
+
await this.pubClient.connect();
|
|
515
|
+
};
|
|
516
|
+
void reconnect();
|
|
517
|
+
});
|
|
518
|
+
this.subClient.on("error", (err) => {
|
|
519
|
+
this.logger.error(`Redis sub database is errored. Error: ${err}`);
|
|
520
|
+
const reconnect = async () => {
|
|
521
|
+
await this.subClient.quit();
|
|
522
|
+
await (0, import_common5.sleep)(1e3);
|
|
523
|
+
await this.subClient.connect();
|
|
524
|
+
};
|
|
525
|
+
void reconnect();
|
|
526
|
+
});
|
|
527
|
+
await Promise.all([this.pubClient.connect(), this.subClient.connect()]);
|
|
528
|
+
this.adapterConstructor = (0, import_redis_adapter.createAdapter)(this.pubClient, this.subClient);
|
|
529
|
+
}
|
|
530
|
+
createIOServer(port, options) {
|
|
531
|
+
this.server = super.createIOServer(port, options);
|
|
532
|
+
this.server.adapter(this.adapterConstructor);
|
|
533
|
+
return this.server;
|
|
534
|
+
}
|
|
535
|
+
async destroy() {
|
|
536
|
+
await Promise.all([this.pubClient.quit(), this.subClient.quit()]);
|
|
537
|
+
await this.close(this.server);
|
|
538
|
+
this.logger.log("RedisIoAdapter is closed");
|
|
539
|
+
}
|
|
540
|
+
};
|
|
1397
541
|
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
542
|
+
// pkgs/@akanjs/nest/src/pipes.ts
|
|
543
|
+
var import_base3 = require("@akanjs/base");
|
|
544
|
+
var import_signal3 = require("@akanjs/signal");
|
|
545
|
+
var import_common6 = require("@nestjs/common");
|
|
546
|
+
var import_stream = require("stream");
|
|
547
|
+
var ArrayifyPipe = class {
|
|
548
|
+
transform(value, metadata) {
|
|
549
|
+
return Array.isArray(value) ? value : value.split(",");
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
ArrayifyPipe = __decorateClass([
|
|
553
|
+
(0, import_common6.Injectable)()
|
|
554
|
+
], ArrayifyPipe);
|
|
555
|
+
var IntPipe = class {
|
|
556
|
+
transform(value, metadata) {
|
|
557
|
+
return Array.isArray(value) ? value.map(parseInt) : [parseInt(value)];
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
IntPipe = __decorateClass([
|
|
561
|
+
(0, import_common6.Injectable)()
|
|
562
|
+
], IntPipe);
|
|
563
|
+
var FloatPipe = class {
|
|
564
|
+
transform(value, metadata) {
|
|
565
|
+
return Array.isArray(value) ? value.map(parseFloat) : [parseFloat(value)];
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
FloatPipe = __decorateClass([
|
|
569
|
+
(0, import_common6.Injectable)()
|
|
570
|
+
], FloatPipe);
|
|
571
|
+
var BooleanPipe = class {
|
|
572
|
+
transform(value, metadata) {
|
|
573
|
+
return Array.isArray(value) ? value.map((v) => Boolean(v)) : [Boolean(value)];
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
BooleanPipe = __decorateClass([
|
|
577
|
+
(0, import_common6.Injectable)()
|
|
578
|
+
], BooleanPipe);
|
|
579
|
+
var DayjsPipe = class {
|
|
580
|
+
transform(value, metadata) {
|
|
581
|
+
return Array.isArray(value) ? value.map(import_base3.dayjs) : [(0, import_base3.dayjs)(value)];
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
DayjsPipe = __decorateClass([
|
|
585
|
+
(0, import_common6.Injectable)()
|
|
586
|
+
], DayjsPipe);
|
|
587
|
+
var JSONPipe = class {
|
|
588
|
+
transform(value, metadata) {
|
|
589
|
+
const transformable = typeof value === "string" && value.length;
|
|
590
|
+
const obj = transformable ? JSON.parse(atob(value)) : value;
|
|
591
|
+
return obj;
|
|
592
|
+
}
|
|
593
|
+
};
|
|
594
|
+
JSONPipe = __decorateClass([
|
|
595
|
+
(0, import_common6.Injectable)()
|
|
596
|
+
], JSONPipe);
|
|
597
|
+
var convertToFileStream = (value) => ({
|
|
598
|
+
filename: value.originalname,
|
|
599
|
+
mimetype: value.mimetype,
|
|
600
|
+
encoding: value.encoding,
|
|
601
|
+
createReadStream: () => import_stream.Readable.from(value.buffer)
|
|
602
|
+
});
|
|
603
|
+
var MulterToUploadPipe = class {
|
|
604
|
+
transform(value, metadata) {
|
|
605
|
+
return Array.isArray(value) ? value.map(convertToFileStream) : convertToFileStream(value);
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
MulterToUploadPipe = __decorateClass([
|
|
609
|
+
(0, import_common6.Injectable)()
|
|
610
|
+
], MulterToUploadPipe);
|
|
611
|
+
var gqlScalarPipeMap = /* @__PURE__ */ new Map([
|
|
612
|
+
[import_base3.Int, IntPipe],
|
|
613
|
+
[import_base3.Float, FloatPipe],
|
|
614
|
+
[Boolean, BooleanPipe],
|
|
615
|
+
[Date, DayjsPipe],
|
|
616
|
+
[import_base3.JSON, JSONPipe]
|
|
617
|
+
]);
|
|
618
|
+
var getQueryPipes = (modelRef, arrDepth) => {
|
|
619
|
+
const pipes = arrDepth ? [ArrayifyPipe] : [];
|
|
620
|
+
const scalarPipe = gqlScalarPipeMap.get(modelRef);
|
|
621
|
+
if (scalarPipe)
|
|
622
|
+
pipes.push(scalarPipe);
|
|
623
|
+
return pipes;
|
|
624
|
+
};
|
|
625
|
+
var getBodyPipes = (argMeta) => {
|
|
626
|
+
const [returnRef] = (0, import_base3.getNonArrayModel)(argMeta.returns());
|
|
627
|
+
if (returnRef.prototype !== Date.prototype && !(0, import_base3.isGqlScalar)(returnRef))
|
|
628
|
+
return [];
|
|
629
|
+
let BodyPipe = class {
|
|
1426
630
|
transform(value, metadata) {
|
|
1427
|
-
return
|
|
631
|
+
return (0, import_signal3.deserializeArg)(argMeta, value);
|
|
1428
632
|
}
|
|
1429
633
|
};
|
|
1430
|
-
|
|
1431
|
-
(0,
|
|
1432
|
-
],
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
return Array.isArray(value) ? value.map(dayjs) : [dayjs(value)];
|
|
1436
|
-
}
|
|
1437
|
-
};
|
|
1438
|
-
DayjsPipe = __decorateClass([
|
|
1439
|
-
(0, import_common11.Injectable)()
|
|
1440
|
-
], DayjsPipe);
|
|
1441
|
-
var JSONPipe = class {
|
|
1442
|
-
transform(value, metadata) {
|
|
1443
|
-
const transformable = typeof value === "string" && value.length;
|
|
1444
|
-
const obj = transformable ? JSON.parse(atob(value)) : value;
|
|
1445
|
-
return obj;
|
|
1446
|
-
}
|
|
1447
|
-
};
|
|
1448
|
-
JSONPipe = __decorateClass([
|
|
1449
|
-
(0, import_common11.Injectable)()
|
|
1450
|
-
], JSONPipe);
|
|
1451
|
-
var convertToFileStream = (value) => ({
|
|
1452
|
-
filename: value.originalname,
|
|
1453
|
-
mimetype: value.mimetype,
|
|
1454
|
-
encoding: value.encoding,
|
|
1455
|
-
createReadStream: () => import_stream.Readable.from(value.buffer)
|
|
1456
|
-
});
|
|
1457
|
-
var MulterToUploadPipe = class {
|
|
1458
|
-
transform(value, metadata) {
|
|
1459
|
-
return Array.isArray(value) ? value.map(convertToFileStream) : convertToFileStream(value);
|
|
1460
|
-
}
|
|
1461
|
-
};
|
|
1462
|
-
MulterToUploadPipe = __decorateClass([
|
|
1463
|
-
(0, import_common11.Injectable)()
|
|
1464
|
-
], MulterToUploadPipe);
|
|
1465
|
-
var gqlScalarPipeMap = /* @__PURE__ */ new Map([
|
|
1466
|
-
[Int, IntPipe],
|
|
1467
|
-
[Float, FloatPipe],
|
|
1468
|
-
[Boolean, BooleanPipe],
|
|
1469
|
-
[Date, DayjsPipe],
|
|
1470
|
-
[JSON2, JSONPipe]
|
|
1471
|
-
]);
|
|
1472
|
-
var getQueryPipes = (modelRef, arrDepth) => {
|
|
1473
|
-
const pipes = arrDepth ? [ArrayifyPipe] : [];
|
|
1474
|
-
const scalarPipe = gqlScalarPipeMap.get(modelRef);
|
|
1475
|
-
if (scalarPipe)
|
|
1476
|
-
pipes.push(scalarPipe);
|
|
1477
|
-
return pipes;
|
|
1478
|
-
};
|
|
1479
|
-
var getBodyPipes = (argMeta) => {
|
|
1480
|
-
const [returnRef] = getNonArrayModel(argMeta.returns());
|
|
1481
|
-
if (returnRef.prototype !== Date.prototype && !isGqlScalar(returnRef))
|
|
1482
|
-
return [];
|
|
1483
|
-
let BodyPipe = class {
|
|
1484
|
-
transform(value, metadata) {
|
|
1485
|
-
return deserializeArg(argMeta, value);
|
|
1486
|
-
}
|
|
1487
|
-
};
|
|
1488
|
-
BodyPipe = __decorateClass([
|
|
1489
|
-
(0, import_common11.Injectable)()
|
|
1490
|
-
], BodyPipe);
|
|
1491
|
-
return [BodyPipe];
|
|
1492
|
-
};
|
|
634
|
+
BodyPipe = __decorateClass([
|
|
635
|
+
(0, import_common6.Injectable)()
|
|
636
|
+
], BodyPipe);
|
|
637
|
+
return [BodyPipe];
|
|
638
|
+
};
|
|
1493
639
|
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
return new Promise((resolve, reject) => {
|
|
1515
|
-
fs.mkdirSync(this.dirname, { recursive: true });
|
|
1516
|
-
const writeStream = fs.createWriteStream(`${this.dirname}/${this.filename}.csv`);
|
|
1517
|
-
if (!writeStream) {
|
|
1518
|
-
reject(new Error("No WriteStream"));
|
|
1519
|
-
return;
|
|
1520
|
-
}
|
|
1521
|
-
writeStream.once(`open`, () => {
|
|
1522
|
-
this.writeStream = writeStream;
|
|
1523
|
-
resolve(writeStream);
|
|
1524
|
-
});
|
|
1525
|
-
});
|
|
1526
|
-
}
|
|
1527
|
-
write(body) {
|
|
1528
|
-
if (!this.writeStream)
|
|
1529
|
-
throw new Error("no write stream");
|
|
1530
|
-
return this.writeStream.write(`${body.replace(/\n/g, "")}
|
|
1531
|
-
`);
|
|
1532
|
-
}
|
|
1533
|
-
// async finish() {}
|
|
1534
|
-
};
|
|
1535
|
-
var exportToCsv = async ({ items, path, fields, delimiter, options }) => {
|
|
640
|
+
// pkgs/@akanjs/nest/src/exporter.ts
|
|
641
|
+
var exporter_exports = {};
|
|
642
|
+
__export(exporter_exports, {
|
|
643
|
+
FileSystem: () => FileSystem,
|
|
644
|
+
exportToCsv: () => exportToCsv,
|
|
645
|
+
exportToJson: () => exportToJson,
|
|
646
|
+
objPath: () => objPath,
|
|
647
|
+
readJson: () => readJson
|
|
648
|
+
});
|
|
649
|
+
var fs = __toESM(require("fs"));
|
|
650
|
+
var objPath = (o, p) => p.split(".").reduce((a, v) => a[v], o);
|
|
651
|
+
var FileSystem = class {
|
|
652
|
+
filename = "";
|
|
653
|
+
dirname = "./";
|
|
654
|
+
writeStream;
|
|
655
|
+
constructor(dirname = "./", filename = "") {
|
|
656
|
+
this.dirname = dirname;
|
|
657
|
+
this.filename = filename;
|
|
658
|
+
}
|
|
659
|
+
async init() {
|
|
1536
660
|
return new Promise((resolve, reject) => {
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
const dirname = dirs.slice(-1).join("/");
|
|
1540
|
-
if (!fs.existsSync(dirname))
|
|
1541
|
-
fs.mkdirSync(dirname, { recursive: true });
|
|
1542
|
-
}
|
|
1543
|
-
if (!fields)
|
|
1544
|
-
throw new Error("Fields Required");
|
|
1545
|
-
const writeStream = !options?.append && fs.createWriteStream(path);
|
|
1546
|
-
const header = fields.reduce((acc, cur) => acc + (delimiter ?? `,`) + cur) + `
|
|
1547
|
-
`;
|
|
661
|
+
fs.mkdirSync(this.dirname, { recursive: true });
|
|
662
|
+
const writeStream = fs.createWriteStream(`${this.dirname}/${this.filename}.csv`);
|
|
1548
663
|
if (!writeStream) {
|
|
1549
664
|
reject(new Error("No WriteStream"));
|
|
1550
665
|
return;
|
|
1551
666
|
}
|
|
1552
667
|
writeStream.once(`open`, () => {
|
|
1553
|
-
writeStream
|
|
1554
|
-
|
|
1555
|
-
const data = fields.map((field) => objPath(item, field) ?? null).map((field) => String(field).replace(/\n/g, "").replace(/,/g, ""));
|
|
1556
|
-
const body = data.reduce((acc, cur) => acc + (delimiter ?? `,`) + cur) + `
|
|
1557
|
-
`;
|
|
1558
|
-
if (options?.append)
|
|
1559
|
-
fs.appendFileSync(path, body);
|
|
1560
|
-
}
|
|
1561
|
-
resolve();
|
|
668
|
+
this.writeStream = writeStream;
|
|
669
|
+
resolve(writeStream);
|
|
1562
670
|
});
|
|
1563
671
|
});
|
|
1564
|
-
}
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
}
|
|
1571
|
-
|
|
672
|
+
}
|
|
673
|
+
write(body) {
|
|
674
|
+
if (!this.writeStream)
|
|
675
|
+
throw new Error("no write stream");
|
|
676
|
+
return this.writeStream.write(`${body.replace(/\n/g, "")}
|
|
677
|
+
`);
|
|
678
|
+
}
|
|
679
|
+
// async finish() {}
|
|
680
|
+
};
|
|
681
|
+
var exportToCsv = async ({ items, path, fields, delimiter, options }) => {
|
|
682
|
+
return new Promise((resolve, reject) => {
|
|
683
|
+
const dirs = path.split("/");
|
|
684
|
+
if (dirs.length > 1) {
|
|
685
|
+
const dirname = dirs.slice(-1).join("/");
|
|
686
|
+
if (!fs.existsSync(dirname))
|
|
687
|
+
fs.mkdirSync(dirname, { recursive: true });
|
|
688
|
+
}
|
|
689
|
+
if (!fields)
|
|
690
|
+
throw new Error("Fields Required");
|
|
691
|
+
const writeStream = !options?.append && fs.createWriteStream(path);
|
|
692
|
+
const header = fields.reduce((acc, cur) => acc + (delimiter ?? `,`) + cur) + `
|
|
693
|
+
`;
|
|
694
|
+
if (!writeStream) {
|
|
695
|
+
reject(new Error("No WriteStream"));
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
writeStream.once(`open`, () => {
|
|
699
|
+
writeStream.write(header);
|
|
700
|
+
for (const item of items) {
|
|
701
|
+
const data = fields.map((field) => objPath(item, field) ?? null).map((field) => String(field).replace(/\n/g, "").replace(/,/g, ""));
|
|
702
|
+
const body = data.reduce((acc, cur) => acc + (delimiter ?? `,`) + cur) + `
|
|
703
|
+
`;
|
|
704
|
+
if (options?.append)
|
|
705
|
+
fs.appendFileSync(path, body);
|
|
706
|
+
}
|
|
707
|
+
resolve();
|
|
708
|
+
});
|
|
709
|
+
});
|
|
710
|
+
};
|
|
711
|
+
var exportToJson = (items, localPath) => {
|
|
712
|
+
const dirname = localPath.split("/").slice(0, -1).join("/");
|
|
713
|
+
if (!fs.existsSync(dirname))
|
|
714
|
+
fs.mkdirSync(dirname, { recursive: true });
|
|
715
|
+
fs.writeFileSync(localPath, JSON.stringify(items));
|
|
716
|
+
};
|
|
717
|
+
var readJson = (localPath) => JSON.parse(fs.readFileSync(localPath).toString("utf-8"));
|
|
1572
718
|
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
719
|
+
// pkgs/@akanjs/nest/src/verifyPayment.ts
|
|
720
|
+
var import_iap = __toESM(require("iap"));
|
|
721
|
+
var verifyPayment = async (payment) => {
|
|
722
|
+
return new Promise(
|
|
723
|
+
(resolve, reject) => (
|
|
724
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
725
|
+
import_iap.default.verifyPayment(payment.platform, { ...payment }, (error, response) => {
|
|
726
|
+
if (error)
|
|
727
|
+
reject(`App Purchase Verify Failed. ${response}`);
|
|
728
|
+
else
|
|
729
|
+
resolve(response);
|
|
730
|
+
})
|
|
731
|
+
)
|
|
732
|
+
);
|
|
733
|
+
};
|
|
1588
734
|
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
735
|
+
// pkgs/@akanjs/nest/src/sso.ts
|
|
736
|
+
var import_common7 = require("@nestjs/common");
|
|
737
|
+
var import_passport = require("@nestjs/passport");
|
|
738
|
+
var appleSignin = __toESM(require("apple-signin"));
|
|
739
|
+
var jwt2 = __toESM(require("jsonwebtoken"));
|
|
740
|
+
var import_passport_apple = require("passport-apple");
|
|
741
|
+
var import_passport_facebook = require("passport-facebook");
|
|
742
|
+
var import_passport_github = require("passport-github");
|
|
743
|
+
var import_passport_google_oauth20 = require("passport-google-oauth20");
|
|
744
|
+
var import_passport_kakao = require("passport-kakao");
|
|
745
|
+
var import_passport_naver = require("passport-naver");
|
|
746
|
+
var getSsoProviders = (host, ssoOptions) => {
|
|
747
|
+
const origin = host === "localhost" ? "http://localhost:8080/backend" : `https://${host}/backend`;
|
|
748
|
+
const providers = [];
|
|
749
|
+
if (ssoOptions.kakao) {
|
|
750
|
+
let KakaoOauthStrategy = class extends (0, import_passport.PassportStrategy)(import_passport_kakao.Strategy, "kakao") {
|
|
751
|
+
constructor() {
|
|
752
|
+
super({
|
|
753
|
+
...ssoOptions.kakao,
|
|
754
|
+
callbackURL: `${origin}/user/kakao/callback`,
|
|
755
|
+
scope: ["account_email", "profile_nickname"]
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
validate(jwt3, refreshToken, profile) {
|
|
759
|
+
return {
|
|
760
|
+
name: profile.displayName,
|
|
761
|
+
email: profile._json.kakao_account.email,
|
|
762
|
+
password: profile.id
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
};
|
|
766
|
+
KakaoOauthStrategy = __decorateClass([
|
|
767
|
+
(0, import_common7.Injectable)()
|
|
768
|
+
], KakaoOauthStrategy);
|
|
769
|
+
providers.push(KakaoOauthStrategy);
|
|
770
|
+
}
|
|
771
|
+
if (ssoOptions.naver) {
|
|
772
|
+
let NaverOauthStrategy = class extends (0, import_passport.PassportStrategy)(import_passport_naver.Strategy, "naver") {
|
|
773
|
+
constructor() {
|
|
774
|
+
super({ ...ssoOptions.naver, callbackURL: `${origin}/user/naver/callback` });
|
|
775
|
+
}
|
|
776
|
+
validate(jwt3, refreshToken, profile) {
|
|
777
|
+
return {
|
|
778
|
+
name: profile.displayName,
|
|
779
|
+
email: profile._json.email,
|
|
780
|
+
password: profile.id
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
NaverOauthStrategy = __decorateClass([
|
|
785
|
+
(0, import_common7.Injectable)()
|
|
786
|
+
], NaverOauthStrategy);
|
|
787
|
+
providers.push(NaverOauthStrategy);
|
|
788
|
+
}
|
|
789
|
+
if (ssoOptions.github) {
|
|
790
|
+
let GithubOauthStrategy = class extends (0, import_passport.PassportStrategy)(import_passport_github.Strategy, "github") {
|
|
791
|
+
constructor() {
|
|
792
|
+
super({ ...ssoOptions.github, callbackURL: `${origin}/user/github/callback`, scope: ["user"] });
|
|
793
|
+
}
|
|
794
|
+
validate(accessToken, _refreshToken, profile) {
|
|
795
|
+
return profile;
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
GithubOauthStrategy = __decorateClass([
|
|
799
|
+
(0, import_common7.Injectable)()
|
|
800
|
+
], GithubOauthStrategy);
|
|
801
|
+
providers.push(GithubOauthStrategy);
|
|
802
|
+
}
|
|
803
|
+
if (ssoOptions.google) {
|
|
804
|
+
let GoogleOauthStrategy = class extends (0, import_passport.PassportStrategy)(import_passport_google_oauth20.Strategy, "google") {
|
|
805
|
+
constructor() {
|
|
806
|
+
super({ ...ssoOptions.google, callbackURL: `${origin}/user/google/callback`, scope: ["email", "profile"] });
|
|
807
|
+
}
|
|
808
|
+
validate(_accessToken, _refreshToken, profile) {
|
|
809
|
+
return profile;
|
|
810
|
+
}
|
|
811
|
+
};
|
|
812
|
+
GoogleOauthStrategy = __decorateClass([
|
|
813
|
+
(0, import_common7.Injectable)()
|
|
814
|
+
], GoogleOauthStrategy);
|
|
815
|
+
providers.push(GoogleOauthStrategy);
|
|
816
|
+
}
|
|
817
|
+
if (ssoOptions.facebook) {
|
|
818
|
+
let FacebookOauthStrategy = class extends (0, import_passport.PassportStrategy)(import_passport_facebook.Strategy, "facebook") {
|
|
819
|
+
constructor() {
|
|
820
|
+
super({
|
|
821
|
+
...ssoOptions.facebook,
|
|
822
|
+
callbackURL: `${origin}/user/facebook/callback`,
|
|
823
|
+
scope: ["email"],
|
|
824
|
+
profileFields: ["emails", "name"]
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
validate(_accessToken, _refreshToken, profile) {
|
|
828
|
+
return profile;
|
|
829
|
+
}
|
|
830
|
+
};
|
|
831
|
+
FacebookOauthStrategy = __decorateClass([
|
|
832
|
+
(0, import_common7.Injectable)()
|
|
833
|
+
], FacebookOauthStrategy);
|
|
834
|
+
providers.push(FacebookOauthStrategy);
|
|
835
|
+
}
|
|
836
|
+
if (ssoOptions.apple) {
|
|
837
|
+
let AppleOauthStrategy = class extends (0, import_passport.PassportStrategy)(import_passport_apple.Strategy, "apple") {
|
|
838
|
+
constructor() {
|
|
839
|
+
super({
|
|
840
|
+
...ssoOptions.apple,
|
|
841
|
+
callbackURL: `${origin}/user/apple/callback`,
|
|
842
|
+
passReqToCallback: true,
|
|
843
|
+
scope: ["name", "email"]
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
validate(req, accessToken, refreshToken, idToken, profile, cb) {
|
|
847
|
+
cb(null, idToken);
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
AppleOauthStrategy = __decorateClass([
|
|
851
|
+
(0, import_common7.Injectable)()
|
|
852
|
+
], AppleOauthStrategy);
|
|
853
|
+
providers.push(AppleOauthStrategy);
|
|
854
|
+
}
|
|
855
|
+
return providers;
|
|
856
|
+
};
|
|
857
|
+
var verifyAppleUser = async (payload, origin, sso) => {
|
|
858
|
+
const signinAgent = appleSignin;
|
|
859
|
+
const clientSecret = signinAgent.getClientSecret({
|
|
860
|
+
clientID: sso.clientID,
|
|
861
|
+
teamId: sso.teamID,
|
|
862
|
+
keyIdentifier: sso.keyID,
|
|
863
|
+
privateKeyPath: sso.keyFilePath
|
|
864
|
+
});
|
|
865
|
+
const tokens = await signinAgent.getAuthorizationToken(payload.code, {
|
|
866
|
+
clientID: sso.clientID,
|
|
867
|
+
clientSecret,
|
|
868
|
+
redirectUri: `${origin}/user/apple/callback`
|
|
869
|
+
});
|
|
870
|
+
if (!tokens.id_token) {
|
|
871
|
+
throw new Error("No id_token found in Apple's response");
|
|
872
|
+
}
|
|
873
|
+
const data = jwt2.decode(tokens.id_token);
|
|
874
|
+
return { tokens, data };
|
|
875
|
+
};
|
|
1730
876
|
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
877
|
+
// pkgs/@akanjs/nest/src/exceptions.ts
|
|
878
|
+
var import_common8 = require("@akanjs/common");
|
|
879
|
+
var import_common9 = require("@nestjs/common");
|
|
880
|
+
var AllExceptionsFilter = class {
|
|
881
|
+
logger = new import_common8.Logger("Exception Filter");
|
|
882
|
+
catch(exception, host) {
|
|
883
|
+
if (host.getType() !== "http") {
|
|
884
|
+
const gqlArgs = host.getArgByIndex(1);
|
|
885
|
+
const gqlReq = host.getArgByIndex(3);
|
|
886
|
+
const reqType2 = gqlReq?.parentType?.name ?? "unknown";
|
|
887
|
+
const reqName2 = gqlReq?.fieldName ?? "unknown";
|
|
888
|
+
this.logger.error(
|
|
889
|
+
`GraphQL Error
|
|
1743
890
|
Request: ${reqType2}-${reqName2}
|
|
1744
891
|
Args: ${JSON.stringify(gqlArgs, null, 2)}
|
|
1745
892
|
${exception.stack}`
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
893
|
+
);
|
|
894
|
+
throw exception;
|
|
895
|
+
}
|
|
896
|
+
const ctx = host.switchToHttp();
|
|
897
|
+
const res = ctx.getResponse();
|
|
898
|
+
const req = ctx.getRequest();
|
|
899
|
+
const reqType = req.method;
|
|
900
|
+
const reqName = req.url;
|
|
901
|
+
const status = exception instanceof import_common9.HttpException ? exception.getStatus() : null;
|
|
902
|
+
if (status) {
|
|
903
|
+
res.status(status).json({
|
|
904
|
+
statusCode: status,
|
|
905
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
906
|
+
path: req.url,
|
|
907
|
+
message: exception instanceof import_common9.HttpException ? exception.getResponse() : exception.message
|
|
908
|
+
});
|
|
909
|
+
this.logger.error(
|
|
910
|
+
`Http Error: ${status}
|
|
1764
911
|
Request: ${reqType}-${reqName}
|
|
1765
912
|
Body: ${JSON.stringify(req.body, null, 2)}
|
|
1766
913
|
${exception.stack}`
|
|
1767
|
-
|
|
1768
|
-
}
|
|
914
|
+
);
|
|
1769
915
|
}
|
|
1770
|
-
}
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
916
|
+
}
|
|
917
|
+
};
|
|
918
|
+
AllExceptionsFilter = __decorateClass([
|
|
919
|
+
(0, import_common9.Catch)()
|
|
920
|
+
], AllExceptionsFilter);
|
|
1774
921
|
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
}
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
}
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
}
|
|
922
|
+
// pkgs/@akanjs/nest/src/generateSecrets.ts
|
|
923
|
+
var import_base4 = require("@akanjs/base");
|
|
924
|
+
var import_crypto = require("crypto");
|
|
925
|
+
var import_tunnel_ssh = require("tunnel-ssh");
|
|
926
|
+
var generateHexStringFromSeed = (seed, length = 256) => {
|
|
927
|
+
let hexString = "";
|
|
928
|
+
let currentSeed = seed;
|
|
929
|
+
while (hexString.length < length * 2) {
|
|
930
|
+
const hash = (0, import_crypto.createHash)("sha256").update(currentSeed).digest("hex");
|
|
931
|
+
hexString += hash;
|
|
932
|
+
currentSeed = hash;
|
|
933
|
+
}
|
|
934
|
+
return hexString.substring(0, length * 2);
|
|
935
|
+
};
|
|
936
|
+
var generateJwtSecret = (appName, environment) => {
|
|
937
|
+
const seed = `${appName}-${environment}-jwt-secret`;
|
|
938
|
+
return generateHexStringFromSeed(seed);
|
|
939
|
+
};
|
|
940
|
+
var generateAeskey = (appName, environment) => {
|
|
941
|
+
const seed = `${appName}-${environment}-aes-key`;
|
|
942
|
+
return (0, import_crypto.createHash)("sha256").update(seed).digest("hex");
|
|
943
|
+
};
|
|
944
|
+
var DEFAULT_CLOUD_PORT = 3e4;
|
|
945
|
+
var getEnvironmentPort = (environment) => environment === "main" ? 2e3 : environment === "develop" ? 1e3 : environment === "debug" ? 0 : 0;
|
|
946
|
+
var getServicePort = (appCode, service) => (service === "redis" ? 300 : service === "mongo" ? 400 : 500) + appCode % 10 * 10 + (appCode >= 10 ? 5 : 0);
|
|
947
|
+
var createDatabaseTunnel = async ({
|
|
948
|
+
appName,
|
|
949
|
+
environment,
|
|
950
|
+
type,
|
|
951
|
+
port,
|
|
952
|
+
sshOptions = {
|
|
953
|
+
host: `${appName}-${environment}.${import_base4.baseEnv.serveDomain}`,
|
|
954
|
+
port: 32767,
|
|
955
|
+
username: import_base4.baseEnv.tunnelUsername,
|
|
956
|
+
password: import_base4.baseEnv.tunnelPassword
|
|
957
|
+
}
|
|
958
|
+
}) => {
|
|
959
|
+
const tunnelOptions = { autoClose: true, reconnectOnError: false };
|
|
960
|
+
const serverOptions = { port };
|
|
961
|
+
const forwardOptions = {
|
|
962
|
+
srcAddr: "0.0.0.0",
|
|
963
|
+
srcPort: port,
|
|
964
|
+
dstAddr: `${type}-0.${type}-svc.${appName}-${environment}`,
|
|
965
|
+
dstPort: type === "mongo" ? 27017 : type === "redis" ? 6379 : 7700
|
|
966
|
+
};
|
|
967
|
+
const [server, client] = await (0, import_tunnel_ssh.createTunnel)(tunnelOptions, serverOptions, sshOptions, forwardOptions);
|
|
968
|
+
return `localhost:${port}`;
|
|
969
|
+
};
|
|
970
|
+
var generateRedisUri = async ({ appName, appCode, environment, operationMode, sshOptions }) => {
|
|
971
|
+
if (process.env.REDIS_URI)
|
|
972
|
+
return process.env.REDIS_URI;
|
|
973
|
+
const port = operationMode === "local" ? DEFAULT_CLOUD_PORT + getEnvironmentPort(environment) + getServicePort(appCode, "redis") : 6379;
|
|
974
|
+
const url = operationMode === "cloud" ? `redis-svc.${appName}-${environment}.svc.cluster.local` : operationMode === "local" ? await createDatabaseTunnel({ appName, environment, type: "redis", port, sshOptions }) : "localhost:6379";
|
|
975
|
+
const uri = `redis://${url}`;
|
|
976
|
+
return uri;
|
|
977
|
+
};
|
|
978
|
+
var generateMongoUri = async ({
|
|
979
|
+
appName,
|
|
980
|
+
appCode,
|
|
981
|
+
environment,
|
|
982
|
+
operationMode,
|
|
983
|
+
username = `${appName}-${environment}-mongo-user`,
|
|
984
|
+
password,
|
|
985
|
+
sshOptions
|
|
986
|
+
}) => {
|
|
987
|
+
if (process.env.MONGO_URI)
|
|
988
|
+
return process.env.MONGO_URI;
|
|
989
|
+
const record = operationMode === "cloud" ? "mongodb+srv" : "mongodb";
|
|
990
|
+
const port = operationMode === "local" ? DEFAULT_CLOUD_PORT + getEnvironmentPort(environment) + getServicePort(appCode, "mongo") : 27017;
|
|
991
|
+
const url = operationMode === "cloud" ? `mongo-svc.${appName}-${environment}.svc.cluster.local` : operationMode === "local" ? await createDatabaseTunnel({ appName, environment, type: "mongo", port, sshOptions }) : "localhost:27017";
|
|
992
|
+
const usernameEncoded = password ? encodeURIComponent(username) : null;
|
|
993
|
+
const passwordEncoded = password ? encodeURIComponent(password) : null;
|
|
994
|
+
const dbName = `${appName}-${environment}`;
|
|
995
|
+
const directConnection = operationMode === "cloud" ? false : true;
|
|
996
|
+
const authInfo = usernameEncoded ? `${usernameEncoded}:${passwordEncoded}@` : "";
|
|
997
|
+
const uri = `${record}://${authInfo}${url}/${dbName}?authSource=${dbName}&readPreference=primary&ssl=false&retryWrites=true&directConnection=${directConnection}`;
|
|
998
|
+
return uri;
|
|
999
|
+
};
|
|
1000
|
+
var generateMeiliUri = ({ appName, appCode, environment, operationMode }) => {
|
|
1001
|
+
if (process.env.MEILI_URI)
|
|
1002
|
+
return process.env.MEILI_URI;
|
|
1003
|
+
const protocol = operationMode === "local" ? "https" : "http";
|
|
1004
|
+
const url = operationMode === "cloud" ? `meili-0.meili-svc.${appName}-${environment}.svc.cluster.local:7700` : operationMode === "local" ? `${appName}-${environment}.${import_base4.baseEnv.serveDomain}/search` : "localhost:7700";
|
|
1005
|
+
const uri = `${protocol}://${url}`;
|
|
1006
|
+
return uri;
|
|
1007
|
+
};
|
|
1008
|
+
var SALT_ROUNDS = 11;
|
|
1009
|
+
var generateHost = (env) => {
|
|
1010
|
+
if (process.env.HOST_NAME)
|
|
1011
|
+
return process.env.HOST_NAME;
|
|
1012
|
+
else if (env.hostname)
|
|
1013
|
+
return env.hostname;
|
|
1014
|
+
else if (env.operationMode === "local")
|
|
1015
|
+
return "localhost";
|
|
1016
|
+
else
|
|
1017
|
+
return `${env.appName}-${env.environment}.${import_base4.baseEnv.serveDomain}`;
|
|
1018
|
+
};
|
|
1019
|
+
var generateMeiliKey = ({ appName, environment }) => {
|
|
1020
|
+
return `meilisearch-key-${appName}-${environment}`;
|
|
1021
|
+
};
|
|
1874
1022
|
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1023
|
+
// pkgs/@akanjs/nest/src/mongoose.ts
|
|
1024
|
+
var import_common10 = require("@akanjs/common");
|
|
1025
|
+
var import_mongoose = __toESM(require("mongoose"));
|
|
1026
|
+
var initMongoDB = ({
|
|
1027
|
+
logging,
|
|
1028
|
+
threshold = 5e3,
|
|
1029
|
+
sendReport = false
|
|
1030
|
+
}) => {
|
|
1031
|
+
const mongoDBLogger = new import_common10.Logger("MongoDB");
|
|
1032
|
+
if (logging)
|
|
1033
|
+
import_mongoose.default.set("debug", function(collection, method, ...methodArgs) {
|
|
1034
|
+
mongoDBLogger.verbose(
|
|
1035
|
+
`${collection}.${method}(${methodArgs.slice(0, -1).map((arg) => JSON.stringify(arg)).join(", ")})`
|
|
1036
|
+
);
|
|
1037
|
+
});
|
|
1038
|
+
const originalExec = import_mongoose.default.Query.prototype.exec;
|
|
1039
|
+
const getQueryInfo = (queryAgent) => {
|
|
1040
|
+
const model = queryAgent.model;
|
|
1041
|
+
const collectionName = model.collection.collectionName;
|
|
1042
|
+
const dbName = model.db.name;
|
|
1043
|
+
const query = queryAgent.getQuery();
|
|
1044
|
+
const queryOptions = queryAgent.getOptions();
|
|
1045
|
+
return { dbName, collectionName, query, queryOptions };
|
|
1046
|
+
};
|
|
1047
|
+
import_mongoose.default.Query.prototype.exec = function(...args) {
|
|
1048
|
+
const start = Date.now();
|
|
1049
|
+
return originalExec.apply(this, args).then((result) => {
|
|
1050
|
+
const duration = Date.now() - start;
|
|
1051
|
+
const { dbName, collectionName, query, queryOptions } = getQueryInfo(this);
|
|
1052
|
+
if (logging)
|
|
1885
1053
|
mongoDBLogger.verbose(
|
|
1886
|
-
|
|
1054
|
+
`Queried ${dbName}.${collectionName}.query(${JSON.stringify(query)}, ${JSON.stringify(
|
|
1055
|
+
queryOptions
|
|
1056
|
+
)}) - ${duration}ms`
|
|
1887
1057
|
);
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
const getQueryInfo = (queryAgent) => {
|
|
1891
|
-
const model = queryAgent.model;
|
|
1892
|
-
const collectionName = model.collection.collectionName;
|
|
1893
|
-
const dbName = model.db.name;
|
|
1894
|
-
const query = queryAgent.getQuery();
|
|
1895
|
-
const queryOptions = queryAgent.getOptions();
|
|
1896
|
-
return { dbName, collectionName, query, queryOptions };
|
|
1897
|
-
};
|
|
1898
|
-
import_mongoose.default.Query.prototype.exec = function(...args) {
|
|
1899
|
-
const start = Date.now();
|
|
1900
|
-
return originalExec.apply(this, args).then((result) => {
|
|
1901
|
-
const duration = Date.now() - start;
|
|
1902
|
-
const { dbName, collectionName, query, queryOptions } = getQueryInfo(this);
|
|
1903
|
-
if (logging)
|
|
1904
|
-
mongoDBLogger.verbose(
|
|
1905
|
-
`Queried ${dbName}.${collectionName}.query(${JSON.stringify(query)}, ${JSON.stringify(
|
|
1906
|
-
queryOptions
|
|
1907
|
-
)}) - ${duration}ms`
|
|
1908
|
-
);
|
|
1909
|
-
return result;
|
|
1910
|
-
});
|
|
1911
|
-
};
|
|
1912
|
-
const originalAggregate = import_mongoose.default.Model.aggregate;
|
|
1913
|
-
const getAggregateInfo = (aggregateModel) => {
|
|
1914
|
-
const dbName = aggregateModel.db.db?.databaseName ?? "unknown";
|
|
1915
|
-
const collectionName = aggregateModel.collection.collectionName;
|
|
1916
|
-
return { dbName, collectionName };
|
|
1917
|
-
};
|
|
1918
|
-
import_mongoose.default.Model.aggregate = function(...args) {
|
|
1919
|
-
const startTime = Date.now();
|
|
1920
|
-
return originalAggregate.apply(this, args).then((result) => {
|
|
1921
|
-
const duration = Date.now() - startTime;
|
|
1922
|
-
const { dbName, collectionName } = getAggregateInfo(this);
|
|
1923
|
-
if (logging)
|
|
1924
|
-
mongoDBLogger.verbose(
|
|
1925
|
-
`Aggregated ${dbName}.${collectionName}.aggregate(${args.map((arg) => JSON.stringify(arg)).join(", ")}) - ${duration}ms`
|
|
1926
|
-
);
|
|
1927
|
-
return result;
|
|
1928
|
-
});
|
|
1929
|
-
};
|
|
1930
|
-
import_mongoose.default.set("transactionAsyncLocalStorage", true);
|
|
1058
|
+
return result;
|
|
1059
|
+
});
|
|
1931
1060
|
};
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
const {
|
|
1943
|
-
if (
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
}
|
|
1950
|
-
async upsertDocuments(indexName, documents) {
|
|
1951
|
-
const task = await this.meili.index(indexName).addDocuments(documents);
|
|
1952
|
-
return task;
|
|
1953
|
-
}
|
|
1954
|
-
async dropIndex(indexName) {
|
|
1955
|
-
const task = await this.meili.index(indexName).delete();
|
|
1956
|
-
return task;
|
|
1957
|
-
}
|
|
1061
|
+
const originalAggregate = import_mongoose.default.Model.aggregate;
|
|
1062
|
+
const getAggregateInfo = (aggregateModel) => {
|
|
1063
|
+
const dbName = aggregateModel.db.db?.databaseName ?? "unknown";
|
|
1064
|
+
const collectionName = aggregateModel.collection.collectionName;
|
|
1065
|
+
return { dbName, collectionName };
|
|
1066
|
+
};
|
|
1067
|
+
import_mongoose.default.Model.aggregate = function(...args) {
|
|
1068
|
+
const startTime = Date.now();
|
|
1069
|
+
return originalAggregate.apply(this, args).then((result) => {
|
|
1070
|
+
const duration = Date.now() - startTime;
|
|
1071
|
+
const { dbName, collectionName } = getAggregateInfo(this);
|
|
1072
|
+
if (logging)
|
|
1073
|
+
mongoDBLogger.verbose(
|
|
1074
|
+
`Aggregated ${dbName}.${collectionName}.aggregate(${args.map((arg) => JSON.stringify(arg)).join(", ")}) - ${duration}ms`
|
|
1075
|
+
);
|
|
1076
|
+
return result;
|
|
1077
|
+
});
|
|
1958
1078
|
};
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
], SearchClient.prototype, "meili", 2);
|
|
1962
|
-
SearchClient = __decorateClass([
|
|
1963
|
-
(0, import_common16.Injectable)()
|
|
1964
|
-
], SearchClient);
|
|
1079
|
+
import_mongoose.default.set("transactionAsyncLocalStorage", true);
|
|
1080
|
+
};
|
|
1965
1081
|
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1082
|
+
// pkgs/@akanjs/nest/src/searchClient.ts
|
|
1083
|
+
var import_constant = require("@akanjs/constant");
|
|
1084
|
+
var import_common11 = require("@nestjs/common");
|
|
1085
|
+
var SearchClient = class {
|
|
1086
|
+
meili;
|
|
1087
|
+
async getIndexNames() {
|
|
1088
|
+
const { results } = await this.meili.getIndexes({ limit: 1e3 });
|
|
1089
|
+
return results.map((index) => index.uid);
|
|
1090
|
+
}
|
|
1091
|
+
async getSearchResult(indexName, option) {
|
|
1092
|
+
const { skip = 0, limit = import_constant.DEFAULT_PAGE_SIZE, sort = "", searchString } = option;
|
|
1093
|
+
if (!searchString) {
|
|
1094
|
+
const { results, total } = await this.meili.index(indexName).getDocuments({ offset: skip, limit });
|
|
1095
|
+
return { docs: results, skip, limit, sort, total };
|
|
1096
|
+
}
|
|
1097
|
+
const { hits, estimatedTotalHits } = await this.meili.index(indexName).search(searchString, { offset: skip, limit });
|
|
1098
|
+
return { docs: hits, skip, limit, sort, total: estimatedTotalHits, query: searchString };
|
|
1099
|
+
}
|
|
1100
|
+
async upsertDocuments(indexName, documents) {
|
|
1101
|
+
const task = await this.meili.index(indexName).addDocuments(documents);
|
|
1102
|
+
return task;
|
|
1103
|
+
}
|
|
1104
|
+
async dropIndex(indexName) {
|
|
1105
|
+
const task = await this.meili.index(indexName).delete();
|
|
1106
|
+
return task;
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1109
|
+
__decorateClass([
|
|
1110
|
+
(0, import_common11.Inject)("MEILI_CLIENT")
|
|
1111
|
+
], SearchClient.prototype, "meili", 2);
|
|
1112
|
+
SearchClient = __decorateClass([
|
|
1113
|
+
(0, import_common11.Injectable)()
|
|
1114
|
+
], SearchClient);
|
|
1977
1115
|
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
(0, import_mongoose2.InjectConnection)()
|
|
1990
|
-
], DatabaseClient.prototype, "connection", 2);
|
|
1991
|
-
DatabaseClient = __decorateClass([
|
|
1992
|
-
(0, import_common19.Injectable)()
|
|
1993
|
-
], DatabaseClient);
|
|
1116
|
+
// pkgs/@akanjs/nest/src/cacheClient.ts
|
|
1117
|
+
var import_common12 = require("@nestjs/common");
|
|
1118
|
+
var CacheClient = class {
|
|
1119
|
+
redis;
|
|
1120
|
+
};
|
|
1121
|
+
__decorateClass([
|
|
1122
|
+
(0, import_common12.Inject)("REDIS_CLIENT")
|
|
1123
|
+
], CacheClient.prototype, "redis", 2);
|
|
1124
|
+
CacheClient = __decorateClass([
|
|
1125
|
+
(0, import_common12.Injectable)()
|
|
1126
|
+
], CacheClient);
|
|
1994
1127
|
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
1128
|
+
// pkgs/@akanjs/nest/src/databaseClient.ts
|
|
1129
|
+
var import_common13 = require("@akanjs/common");
|
|
1130
|
+
var import_common14 = require("@nestjs/common");
|
|
1131
|
+
var import_mongoose2 = require("@nestjs/mongoose");
|
|
1132
|
+
var DatabaseClient = class {
|
|
1133
|
+
connection;
|
|
1134
|
+
getModel(modelName) {
|
|
1135
|
+
const model = this.connection.models[(0, import_common13.capitalize)(modelName)];
|
|
1136
|
+
return model;
|
|
1137
|
+
}
|
|
1138
|
+
};
|
|
1139
|
+
__decorateClass([
|
|
1140
|
+
(0, import_mongoose2.InjectConnection)()
|
|
1141
|
+
], DatabaseClient.prototype, "connection", 2);
|
|
1142
|
+
DatabaseClient = __decorateClass([
|
|
1143
|
+
(0, import_common14.Injectable)()
|
|
1144
|
+
], DatabaseClient);
|
|
1145
|
+
|
|
1146
|
+
// pkgs/@akanjs/nest/src/decorators.ts
|
|
1147
|
+
var import_reflect_metadata = require("reflect-metadata");
|
|
1148
|
+
var import_schedule = require("@nestjs/schedule");
|
|
1149
|
+
var Try = () => {
|
|
1150
|
+
return function(target, key, descriptor) {
|
|
1151
|
+
const originMethod = descriptor.value;
|
|
1152
|
+
descriptor.value = async function(...args) {
|
|
1153
|
+
try {
|
|
1154
|
+
const result = await originMethod.apply(this, args);
|
|
1155
|
+
return result;
|
|
1156
|
+
} catch (e) {
|
|
1157
|
+
this.logger?.warn(`${key} action error return: ${e}`);
|
|
1158
|
+
}
|
|
2009
1159
|
};
|
|
2010
1160
|
};
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
}
|
|
2030
|
-
if (!enabled)
|
|
2031
|
-
return;
|
|
2032
|
-
if (!serverMode || process.env.SERVER_MODE === "all" || serverMode === process.env.SERVER_MODE)
|
|
2033
|
-
(0, import_schedule.Cron)(cronTime)(target, key, descriptor);
|
|
1161
|
+
};
|
|
1162
|
+
var Cron = (cronTime, { lock = true, serverMode, enabled = true } = {}) => {
|
|
1163
|
+
return function(target, key, descriptor) {
|
|
1164
|
+
const originMethod = descriptor.value;
|
|
1165
|
+
let isRunning = false;
|
|
1166
|
+
descriptor.value = async function(...args) {
|
|
1167
|
+
if (lock && isRunning)
|
|
1168
|
+
return this.logger?.warn(`Cronjob-${key} is already running, skipped`);
|
|
1169
|
+
try {
|
|
1170
|
+
isRunning = true;
|
|
1171
|
+
this.logger?.verbose(`Cron Job-${key} started`);
|
|
1172
|
+
const res = await originMethod.apply(this, args);
|
|
1173
|
+
this.logger?.verbose(`Cron Job-${key} finished`);
|
|
1174
|
+
isRunning = false;
|
|
1175
|
+
return res;
|
|
1176
|
+
} catch (e) {
|
|
1177
|
+
this.logger?.error(`Cron Job-${key} error return: ${e}`);
|
|
1178
|
+
isRunning = false;
|
|
1179
|
+
}
|
|
2034
1180
|
};
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
descriptor
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
1181
|
+
if (!enabled)
|
|
1182
|
+
return;
|
|
1183
|
+
if (!serverMode || process.env.SERVER_MODE === "all" || serverMode === process.env.SERVER_MODE)
|
|
1184
|
+
(0, import_schedule.Cron)(cronTime)(target, key, descriptor);
|
|
1185
|
+
};
|
|
1186
|
+
};
|
|
1187
|
+
var getIntervalMetaMap = (prototype) => {
|
|
1188
|
+
return Reflect.getMetadata("serviceInterval", prototype) ?? /* @__PURE__ */ new Map();
|
|
1189
|
+
};
|
|
1190
|
+
var setIntervalMetaMap = (prototype, intervalMetaMap) => {
|
|
1191
|
+
Reflect.defineMetadata("serviceInterval", intervalMetaMap, prototype);
|
|
1192
|
+
};
|
|
1193
|
+
var Interval = (ms, { lock = true, serverMode, enabled = true } = {}) => {
|
|
1194
|
+
return function(target, key, descriptor) {
|
|
1195
|
+
const intervalMetaMap = getIntervalMetaMap(target);
|
|
1196
|
+
if (intervalMetaMap.has(key))
|
|
1197
|
+
return descriptor;
|
|
1198
|
+
intervalMetaMap.set(key, descriptor.value);
|
|
1199
|
+
setIntervalMetaMap(target, intervalMetaMap);
|
|
1200
|
+
const originMethod = descriptor.value;
|
|
1201
|
+
let isRunning = false;
|
|
1202
|
+
descriptor.value = async function(...args) {
|
|
1203
|
+
if (lock && isRunning)
|
|
1204
|
+
return this.logger?.warn(`Cronjob-${key} is already running, skipped`);
|
|
1205
|
+
try {
|
|
1206
|
+
isRunning = true;
|
|
1207
|
+
this.logger?.verbose(`Interval Job-${key} started`);
|
|
1208
|
+
const res = await originMethod.apply(this, args);
|
|
1209
|
+
this.logger?.verbose(`Interval Job-${key} finished`);
|
|
1210
|
+
isRunning = false;
|
|
1211
|
+
return res;
|
|
1212
|
+
} catch (e) {
|
|
1213
|
+
this.logger?.error(`Cronjob-${key} error return: ${e}`);
|
|
1214
|
+
isRunning = false;
|
|
1215
|
+
}
|
|
1216
|
+
};
|
|
1217
|
+
if (!enabled)
|
|
1218
|
+
return;
|
|
1219
|
+
if (!serverMode || process.env.SERVER_MODE === "all" || serverMode === process.env.SERVER_MODE)
|
|
1220
|
+
(0, import_schedule.Interval)(ms)(target, key, descriptor);
|
|
1221
|
+
};
|
|
1222
|
+
};
|
|
1223
|
+
var Transaction = () => {
|
|
1224
|
+
return function(target, key, descriptor) {
|
|
1225
|
+
const originMethod = descriptor.value;
|
|
1226
|
+
descriptor.value = function(...args) {
|
|
1227
|
+
if (!this.connection)
|
|
1228
|
+
throw new Error(`No Connection in function ${key}`);
|
|
1229
|
+
return new Promise((resolve, reject) => {
|
|
1230
|
+
this.connection.transaction(async () => {
|
|
2057
1231
|
const res = await originMethod.apply(this, args);
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
} catch (e) {
|
|
2062
|
-
this.logger?.error(`Cronjob-${key} error return: ${e}`);
|
|
2063
|
-
isRunning = false;
|
|
2064
|
-
}
|
|
2065
|
-
};
|
|
2066
|
-
if (!enabled)
|
|
2067
|
-
return;
|
|
2068
|
-
if (!serverMode || process.env.SERVER_MODE === "all" || serverMode === process.env.SERVER_MODE)
|
|
2069
|
-
(0, import_schedule.Interval)(ms)(target, key, descriptor);
|
|
1232
|
+
resolve(res);
|
|
1233
|
+
}).catch(reject);
|
|
1234
|
+
});
|
|
2070
1235
|
};
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
1236
|
+
return descriptor;
|
|
1237
|
+
};
|
|
1238
|
+
};
|
|
1239
|
+
var Cache = (timeout2 = 1e3, getCacheKey) => {
|
|
1240
|
+
return function(target, key, descriptor) {
|
|
1241
|
+
const originMethod = descriptor.value;
|
|
1242
|
+
const cacheMap = /* @__PURE__ */ new Map();
|
|
1243
|
+
const timerMap = /* @__PURE__ */ new Map();
|
|
1244
|
+
descriptor.value = async function(...args) {
|
|
1245
|
+
const classType = this.__model ? "doc" : this.__databaseModel ? "service" : "class";
|
|
1246
|
+
const model = this.__model ?? this.__databaseModel?.__model;
|
|
1247
|
+
const cache = this.__cache ?? this.__databaseModel?.__cache;
|
|
1248
|
+
const getCacheKeyFn = getCacheKey ?? JSON.stringify;
|
|
1249
|
+
const cacheKey = `${classType}:${model.modelName}:${key}:${getCacheKeyFn(...args)}`;
|
|
1250
|
+
const getCache = async (cacheKey2) => {
|
|
1251
|
+
if (classType === "class")
|
|
1252
|
+
return cacheMap.get(cacheKey2);
|
|
1253
|
+
const cached = await cache.get(cacheKey2);
|
|
1254
|
+
if (cached)
|
|
1255
|
+
return JSON.parse(cached);
|
|
1256
|
+
return null;
|
|
2084
1257
|
};
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
const cacheKey = `${classType}:${model.modelName}:${key}:${getCacheKeyFn(...args)}`;
|
|
2099
|
-
const getCache = async (cacheKey2) => {
|
|
2100
|
-
if (classType === "class")
|
|
2101
|
-
return cacheMap.get(cacheKey2);
|
|
2102
|
-
const cached = await cache.get(cacheKey2);
|
|
2103
|
-
if (cached)
|
|
2104
|
-
return JSON.parse(cached);
|
|
2105
|
-
return null;
|
|
2106
|
-
};
|
|
2107
|
-
const setCache = async (cacheKey2, value) => {
|
|
2108
|
-
if (classType === "class") {
|
|
2109
|
-
const existingTimer = timerMap.get(cacheKey2);
|
|
2110
|
-
if (existingTimer)
|
|
2111
|
-
clearTimeout(existingTimer);
|
|
2112
|
-
cacheMap.set(cacheKey2, value);
|
|
2113
|
-
const timer = setTimeout(() => {
|
|
2114
|
-
cacheMap.delete(cacheKey2);
|
|
2115
|
-
timerMap.delete(cacheKey2);
|
|
2116
|
-
}, timeout2);
|
|
2117
|
-
timerMap.set(cacheKey2, timer);
|
|
2118
|
-
} else
|
|
2119
|
-
await cache.set(cacheKey2, JSON.stringify(value), { PX: timeout2 });
|
|
2120
|
-
};
|
|
2121
|
-
const cachedData = await getCache(cacheKey);
|
|
2122
|
-
if (cachedData) {
|
|
2123
|
-
this.logger?.trace(`${model.modelName} cache hit: ${cacheKey}`);
|
|
2124
|
-
return cachedData;
|
|
2125
|
-
}
|
|
2126
|
-
const result = await originMethod.apply(this, args);
|
|
2127
|
-
await setCache(cacheKey, result);
|
|
2128
|
-
this.logger?.trace(`${model.modelName} cache set: ${cacheKey}`);
|
|
2129
|
-
return result;
|
|
1258
|
+
const setCache = async (cacheKey2, value) => {
|
|
1259
|
+
if (classType === "class") {
|
|
1260
|
+
const existingTimer = timerMap.get(cacheKey2);
|
|
1261
|
+
if (existingTimer)
|
|
1262
|
+
clearTimeout(existingTimer);
|
|
1263
|
+
cacheMap.set(cacheKey2, value);
|
|
1264
|
+
const timer = setTimeout(() => {
|
|
1265
|
+
cacheMap.delete(cacheKey2);
|
|
1266
|
+
timerMap.delete(cacheKey2);
|
|
1267
|
+
}, timeout2);
|
|
1268
|
+
timerMap.set(cacheKey2, timer);
|
|
1269
|
+
} else
|
|
1270
|
+
await cache.set(cacheKey2, JSON.stringify(value), { PX: timeout2 });
|
|
2130
1271
|
};
|
|
1272
|
+
const cachedData = await getCache(cacheKey);
|
|
1273
|
+
if (cachedData) {
|
|
1274
|
+
this.logger?.trace(`${model.modelName} cache hit: ${cacheKey}`);
|
|
1275
|
+
return cachedData;
|
|
1276
|
+
}
|
|
1277
|
+
const result = await originMethod.apply(this, args);
|
|
1278
|
+
await setCache(cacheKey, result);
|
|
1279
|
+
this.logger?.trace(`${model.modelName} cache set: ${cacheKey}`);
|
|
1280
|
+
return result;
|
|
2131
1281
|
};
|
|
2132
1282
|
};
|
|
2133
|
-
}
|
|
2134
|
-
//! Nextjs는 환경변수를 build time에 그냥 하드코딩으로 값을 넣어버림. operationMode같은것들 잘 동작안할 수 있음. 추후 수정 필요.
|
|
1283
|
+
};
|