befly-shared 1.2.1 → 1.2.2
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/dist/hashPassword.js +22 -0
- package/dist/index.js +0 -2
- package/dist/scanConfig.js +3 -2
- package/package.json +2 -2
- package/types/configTypes.d.ts +3 -3
- package/types/hashPassword.d.ts +11 -0
- package/dist/defineAddonConfig.js +0 -21
- package/dist/defineBeflyConfig.js +0 -28
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 密码哈希工具
|
|
3
|
+
* 使用 SHA-256 + 盐值对密码进行单向哈希
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 使用 SHA-256 对密码进行哈希
|
|
7
|
+
* @param password - 原始密码
|
|
8
|
+
* @param salt - 盐值,默认为 befly
|
|
9
|
+
* @returns 哈希后的密码(十六进制字符串)
|
|
10
|
+
*/
|
|
11
|
+
export async function hashPassword(password, salt = 'befly') {
|
|
12
|
+
const data = password + salt;
|
|
13
|
+
// 将字符串转换为 Uint8Array
|
|
14
|
+
const encoder = new TextEncoder();
|
|
15
|
+
const dataBuffer = encoder.encode(data);
|
|
16
|
+
// 使用 Web Crypto API 进行 SHA-256 哈希
|
|
17
|
+
const hashBuffer = await crypto.subtle.digest('SHA-256', dataBuffer);
|
|
18
|
+
// 将 ArrayBuffer 转换为十六进制字符串
|
|
19
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
20
|
+
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
21
|
+
return hashHex;
|
|
22
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -8,8 +8,6 @@ export * from './constants.js';
|
|
|
8
8
|
export * from './redisKeys.js';
|
|
9
9
|
export * from './regex.js';
|
|
10
10
|
// 工具函数
|
|
11
|
-
export * from './defineAddonConfig.js';
|
|
12
|
-
export * from './defineBeflyConfig.js';
|
|
13
11
|
export * from './addonHelper.js';
|
|
14
12
|
export * from './arrayKeysToCamel.js';
|
|
15
13
|
export * from './arrayToTree.js';
|
package/dist/scanConfig.js
CHANGED
|
@@ -11,7 +11,7 @@ import { get, set } from 'es-toolkit/compat';
|
|
|
11
11
|
export async function scanConfig(options) {
|
|
12
12
|
const {
|
|
13
13
|
//
|
|
14
|
-
cwd = process.cwd(), dirs, files, extensions = ['.js', '.ts', '.json'], mode = 'first', paths } = options;
|
|
14
|
+
cwd = process.cwd(), dirs, files, extensions = ['.js', '.ts', '.json'], mode = 'first', paths, defaults = {} } = options;
|
|
15
15
|
// 参数验证
|
|
16
16
|
if (!Array.isArray(dirs) || dirs.length === 0) {
|
|
17
17
|
throw new Error('dirs 必须是非空数组');
|
|
@@ -66,7 +66,8 @@ export async function scanConfig(options) {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
// 合并配置(使用 mergeAndConcat 深度合并)
|
|
69
|
-
|
|
69
|
+
// 合并顺序:defaults ← configs[0] ← configs[1] ← ...
|
|
70
|
+
const finalConfig = mergeAndConcat(defaults, ...configs);
|
|
70
71
|
// 如果指定了 paths,则只返回指定路径的字段
|
|
71
72
|
if (paths && paths.length > 0) {
|
|
72
73
|
const result = {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly-shared",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"merge-anything": "^6.0.6",
|
|
37
37
|
"pathe": "^2.0.3"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "91c93d26c964f8390258a2ff770f533f2c6debfc"
|
|
40
40
|
}
|
package/types/configTypes.d.ts
CHANGED
|
@@ -10,11 +10,11 @@ export interface LoadConfigOptions {
|
|
|
10
10
|
files: string[];
|
|
11
11
|
/** 文件扩展名,默认 ['.js', '.ts', '.json'] */
|
|
12
12
|
extensions?: string[];
|
|
13
|
-
/** 加载模式:'first' = 返回第一个找到的配置(默认),'
|
|
14
|
-
mode?: '
|
|
13
|
+
/** 加载模式:'first' = 返回第一个找到的配置(默认),'merge' = 合并所有配置 */
|
|
14
|
+
mode?: 'merge' | 'first';
|
|
15
15
|
/** 指定要提取的字段路径数组,如 ['menus', 'database.host'],为空则返回完整对象 */
|
|
16
16
|
paths?: string[];
|
|
17
|
-
/**
|
|
17
|
+
/** 默认配置,会与找到的配置合并(优先级最低) */
|
|
18
18
|
defaults?: Record<string, any>;
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 密码哈希工具
|
|
3
|
+
* 使用 SHA-256 + 盐值对密码进行单向哈希
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 使用 SHA-256 对密码进行哈希
|
|
7
|
+
* @param password - 原始密码
|
|
8
|
+
* @param salt - 盐值,默认为 befly
|
|
9
|
+
* @returns 哈希后的密码(十六进制字符串)
|
|
10
|
+
*/
|
|
11
|
+
export declare function hashPassword(password: string, salt?: string): Promise<string>;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Addon 配置定义函数
|
|
3
|
-
* 用于定义 addon 的静态配置(如菜单)
|
|
4
|
-
* 只能在 addon.config.js 文件中使用
|
|
5
|
-
*
|
|
6
|
-
* @param _metaDirname - import.meta.dirname(保留参数,便于未来扩展)
|
|
7
|
-
* @param addonConfig - addon 配置对象
|
|
8
|
-
* @returns addon 配置对象
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* // 在 packages/addonAdmin/addon.config.js 中
|
|
12
|
-
* import { defineAddonConfig } from 'befly-shared/defineAddonConfig';
|
|
13
|
-
*
|
|
14
|
-
* export default defineAddonConfig(import.meta.dirname, {
|
|
15
|
-
* menus: [...]
|
|
16
|
-
* });
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export function defineAddonConfig(_metaDirname, addonConfig = {}) {
|
|
20
|
-
return addonConfig;
|
|
21
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Befly 配置定义函数
|
|
3
|
-
* 提供类型提示,不做任何处理,直接返回配置对象
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* 定义 Befly 配置
|
|
7
|
-
* 提供类型提示,不做任何处理,直接返回配置对象
|
|
8
|
-
* @param config 配置对象
|
|
9
|
-
* @returns 配置对象
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* // app.config.ts
|
|
13
|
-
* import { defineBeflyConfig } from 'befly-shared/defineBeflyConfig';
|
|
14
|
-
*
|
|
15
|
-
* export default defineBeflyConfig({
|
|
16
|
-
* appName: '我的应用',
|
|
17
|
-
* appPort: 3000,
|
|
18
|
-
* addons: {
|
|
19
|
-
* admin: {
|
|
20
|
-
* email: { host: 'smtp.qq.com' }
|
|
21
|
-
* }
|
|
22
|
-
* }
|
|
23
|
-
* });
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export function defineBeflyConfig(config) {
|
|
27
|
-
return config;
|
|
28
|
-
}
|