@dnax/core 0.47.3 → 0.48.0
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/lib/index.ts +3 -0
- package/package.json +2 -3
- package/types/gen.ts +56 -0
- package/types/index.ts +4 -0
- package/types/tsconfig.json +38 -0
- package/utils/index.ts +0 -2
- package/lib/opt.ts +0 -55
package/lib/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { loadSocket } from "../lib/socket";
|
|
|
8
8
|
import { loadAutoRoutes } from "./routes";
|
|
9
9
|
import { initScript } from "../lib/scripts";
|
|
10
10
|
import { syncAdapterFileSystem } from "./media";
|
|
11
|
+
import { runGenTypes } from "../types/gen";
|
|
11
12
|
// load all ressource
|
|
12
13
|
async function init(cf = { app: null }) {
|
|
13
14
|
await loadSocket();
|
|
@@ -36,6 +37,8 @@ async function init(cf = { app: null }) {
|
|
|
36
37
|
|
|
37
38
|
await initCron();
|
|
38
39
|
|
|
40
|
+
runGenTypes();
|
|
41
|
+
|
|
39
42
|
initScript();
|
|
40
43
|
}
|
|
41
44
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dnax/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.48.0",
|
|
4
4
|
"module": "index.ts",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -33,7 +33,6 @@
|
|
|
33
33
|
"cookie": "^0.6.0",
|
|
34
34
|
"croner": "8.1.1",
|
|
35
35
|
"deepcopy": "^2.1.0",
|
|
36
|
-
"docxtemplater": "^3.54.1",
|
|
37
36
|
"dot-object": "2.1.5",
|
|
38
37
|
"find-open-port": "^2.0.3",
|
|
39
38
|
"fs-extra": "^11.2.0",
|
|
@@ -46,7 +45,7 @@
|
|
|
46
45
|
"mime-types": "^2.1.35",
|
|
47
46
|
"mingo": "^6.5.0",
|
|
48
47
|
"moment": "^2.30.1",
|
|
49
|
-
"mongodb": "6.
|
|
48
|
+
"mongodb": "6.15.0",
|
|
50
49
|
"nodemailer": "^6.9.14",
|
|
51
50
|
"pidusage": "^4.0.0",
|
|
52
51
|
"pizzip": "^3.1.8",
|
package/types/gen.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
import { Cfg } from "../config";
|
|
5
|
+
import tsconfig from "./tsconfig.json";
|
|
6
|
+
const TYPE_GEN = path.join(process.cwd(), ".dnax");
|
|
7
|
+
const allDirs = ["types"];
|
|
8
|
+
|
|
9
|
+
async function createDnaxDir() {
|
|
10
|
+
const dnaxDir = path.join(process.cwd(), ".dnax");
|
|
11
|
+
for await (const dir of allDirs) {
|
|
12
|
+
const dirPath = path.join(dnaxDir, dir);
|
|
13
|
+
if (!fs.existsSync(dirPath)) {
|
|
14
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// copy tsconfig coentent to to .dnax/tsconfig.json
|
|
19
|
+
const tsconfigPath = path.join(dnaxDir, "tsconfig.json");
|
|
20
|
+
if (!fs.existsSync(tsconfigPath)) {
|
|
21
|
+
fs.writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2));
|
|
22
|
+
} else {
|
|
23
|
+
const currentContent = fs.readFileSync(tsconfigPath, "utf8");
|
|
24
|
+
if (currentContent !== JSON.stringify(tsconfig, null, 2)) {
|
|
25
|
+
fs.writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 2));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function generateCollectionTypes() {
|
|
31
|
+
let collections = Cfg.collections?.map((f) => f?.slug);
|
|
32
|
+
collections = [...new Set(collections)];
|
|
33
|
+
// export collection type
|
|
34
|
+
let collectionsType = `type CollectionTypeList = ${collections
|
|
35
|
+
.map((c) => `'${c}'`)
|
|
36
|
+
.join(" | ")};\n`;
|
|
37
|
+
|
|
38
|
+
const collectionsTypeFile = path.join(TYPE_GEN, "types", "collections.d.ts");
|
|
39
|
+
|
|
40
|
+
if (!fs?.existsSync(collectionsTypeFile)) {
|
|
41
|
+
fs.writeFileSync(collectionsTypeFile, collectionsType);
|
|
42
|
+
} else {
|
|
43
|
+
const currentContent = fs.readFileSync(collectionsTypeFile, "utf8");
|
|
44
|
+
// console.log("Current content", currentContent);
|
|
45
|
+
if (currentContent !== collectionsType) {
|
|
46
|
+
fs.writeFileSync(collectionsTypeFile, collectionsType);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function runGenTypes() {
|
|
52
|
+
await createDnaxDir();
|
|
53
|
+
await generateCollectionTypes();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { runGenTypes };
|
package/types/index.ts
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"paths": {
|
|
4
|
+
"#/*": [
|
|
5
|
+
"../*"
|
|
6
|
+
]
|
|
7
|
+
},
|
|
8
|
+
// Enable latest features
|
|
9
|
+
"lib": [
|
|
10
|
+
"ESNext",
|
|
11
|
+
"DOM",
|
|
12
|
+
"DOM.Iterable"
|
|
13
|
+
],
|
|
14
|
+
"target": "ESNext",
|
|
15
|
+
"module": "ESNext",
|
|
16
|
+
"moduleDetection": "auto",
|
|
17
|
+
"allowJs": true,
|
|
18
|
+
// Bundler mode
|
|
19
|
+
"moduleResolution": "bundler",
|
|
20
|
+
"allowImportingTsExtensions": true,
|
|
21
|
+
"verbatimModuleSyntax": true,
|
|
22
|
+
"noEmit": true,
|
|
23
|
+
// Best practices
|
|
24
|
+
"strict": true,
|
|
25
|
+
"skipLibCheck": true,
|
|
26
|
+
"noFallthroughCasesInSwitch": true,
|
|
27
|
+
// Some stricter flags (disabled by default)
|
|
28
|
+
"noUnusedLocals": false,
|
|
29
|
+
"noUnusedParameters": false,
|
|
30
|
+
"noPropertyAccessFromIndexSignature": false
|
|
31
|
+
},
|
|
32
|
+
"include": [
|
|
33
|
+
"../node_modules/@dnax/core/types/**/*",
|
|
34
|
+
"./types/**/*.d.ts",
|
|
35
|
+
"../**/*",
|
|
36
|
+
],
|
|
37
|
+
// "exclude": []
|
|
38
|
+
}
|
package/utils/index.ts
CHANGED
|
@@ -8,7 +8,6 @@ import { Cfg } from "../config";
|
|
|
8
8
|
import jwto from "jsonwebtoken";
|
|
9
9
|
import generateUniqueId from "generate-unique-id";
|
|
10
10
|
import dayjs from "dayjs";
|
|
11
|
-
import { Otp } from "../lib/opt";
|
|
12
11
|
import collect from "collect.js";
|
|
13
12
|
import mime from "mime-types";
|
|
14
13
|
import * as uuid from "uuid";
|
|
@@ -562,7 +561,6 @@ export {
|
|
|
562
561
|
generateUniqueId, // Generate unique id
|
|
563
562
|
omit, // Omit utils
|
|
564
563
|
collect, // Collect utils
|
|
565
|
-
Otp, // Otp utils
|
|
566
564
|
urlencode,
|
|
567
565
|
stringToBoolean,
|
|
568
566
|
copy,
|
package/lib/opt.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { parse } from "@lukeed/ms";
|
|
2
|
-
import generateUniqueId from "generate-unique-id";
|
|
3
|
-
type otpOptions = {
|
|
4
|
-
length?: number;
|
|
5
|
-
useLetters?: boolean;
|
|
6
|
-
useNumbers?: boolean;
|
|
7
|
-
includeSymbols?: Array<any>;
|
|
8
|
-
excludeSymbols?: Array<any>;
|
|
9
|
-
expireIn?: string;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
class Otp {
|
|
13
|
-
#otps: Map<string, number> = new Map();
|
|
14
|
-
#options: otpOptions;
|
|
15
|
-
constructor(options: otpOptions) {
|
|
16
|
-
this.#options = options;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
generate(options: { id?: string; data?: any } = {}): string | number {
|
|
20
|
-
setTimeout(() => {}, parse(String(this.#options.expireIn) || "1m"));
|
|
21
|
-
let otpCode = generateUniqueId({
|
|
22
|
-
length: this.#options.length || 6,
|
|
23
|
-
includeSymbols: this.#options.includeSymbols || [],
|
|
24
|
-
useLetters: this.#options.useLetters || true,
|
|
25
|
-
useNumbers: this.#options.useNumbers || true,
|
|
26
|
-
excludeSymbols: this.#options.excludeSymbols || [],
|
|
27
|
-
});
|
|
28
|
-
this.#otps.set(options?.id, {
|
|
29
|
-
otp: otpCode,
|
|
30
|
-
data: options?.data,
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
setTimeout(() => {
|
|
34
|
-
this.#otps.delete(options?.id);
|
|
35
|
-
}, parse(String(this.#options?.expireIn) || "1m"));
|
|
36
|
-
return otpCode;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
delete(id: string): boolean {
|
|
40
|
-
return this.#otps.delete(id) ? true : false;
|
|
41
|
-
}
|
|
42
|
-
verify(id: string, otp: string): { valid: boolean; data: any } {
|
|
43
|
-
// verify otp
|
|
44
|
-
let otpData = this.#otps.get(id);
|
|
45
|
-
if (!otpData) return { valid: false, data: null };
|
|
46
|
-
if (otpData.otp === otp) {
|
|
47
|
-
this.#otps.delete(id);
|
|
48
|
-
return { valid: true, data: otpData?.data };
|
|
49
|
-
} else {
|
|
50
|
-
return { valid: false, data: null };
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export { Otp };
|