module-develop-kit 1.2.0 → 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/main.d.ts CHANGED
@@ -2,6 +2,12 @@ import { Ref } from 'vue';
2
2
  import { supportedExtensions } from 'file-type';
3
3
  import { supportedMimeTypes } from 'file-type';
4
4
 
5
+ /**
6
+ * 支持的文件 MIME 类型配置
7
+ * 从 file-type 库导出,可用于UI展示或额外验证
8
+ */
9
+ export declare const ALLOWED_FILE_MIMES: string[];
10
+
5
11
  /**
6
12
  * 支持的文件类型配置
7
13
  * 基于 file-type 库的 supportedMimeTypes 动态生成
@@ -47,7 +53,7 @@ export declare const CallLogger: {
47
53
  * @param options 检测选项
48
54
  * @returns 检测结果
49
55
  */
50
- export declare function detectFileByExtension(file: File, _allowedExtensions: TMaybeArray<string>, options?: FileDetectionOptions): Promise<FileDetectionResult>;
56
+ export declare function detectFileByExtension(file: File, _allowedExtensions: TMaybeArray<string>, options?: IFileDetectionOptions): Promise<IFileDetectionResult>;
51
57
 
52
58
  /**
53
59
  * 检测文件真实类型并验证 MIME 类型
@@ -57,7 +63,7 @@ export declare function detectFileByExtension(file: File, _allowedExtensions: TM
57
63
  * @param options 检测选项
58
64
  * @returns 检测结果
59
65
  */
60
- export declare function detectFileByMime(file: File, _allowedMimes: TMaybeArray<string>, options?: FileDetectionOptions): Promise<FileDetectionResult>;
66
+ export declare function detectFileByMime(file: File, _allowedMimes: TMaybeArray<string>, options?: IFileDetectionOptions): Promise<IFileDetectionResult>;
61
67
 
62
68
  /**
63
69
  * 批量检测文件扩展名
@@ -67,7 +73,7 @@ export declare function detectFileByMime(file: File, _allowedMimes: TMaybeArray<
67
73
  * @param options 检测选项
68
74
  * @returns 检测结果列表
69
75
  */
70
- export declare function detectionFilesByExtension(files: File[], allowedExtensions: TMaybeArray<string>, options?: FileDetectionOptions): Promise<FileDetectionResult[]>;
76
+ export declare function detectionFilesByExtension(files: File[], allowedExtensions: TMaybeArray<string>, options?: IFileDetectionOptions): Promise<IFileDetectionResult[]>;
71
77
 
72
78
  /**
73
79
  * 批量检测文件 MIME 类型
@@ -77,7 +83,7 @@ export declare function detectionFilesByExtension(files: File[], allowedExtensio
77
83
  * @param options 检测选项
78
84
  * @returns 检测结果列表
79
85
  */
80
- export declare function detectionFilesByMime(files: File[], allowedMimes: TMaybeArray<string>, options?: FileDetectionOptions): Promise<FileDetectionResult[]>;
86
+ export declare function detectionFilesByMime(files: File[], allowedMimes: TMaybeArray<string>, options?: IFileDetectionOptions): Promise<IFileDetectionResult[]>;
81
87
 
82
88
  export declare enum ECallStatus {
83
89
  /**
@@ -162,40 +168,6 @@ export declare interface EventBusProps {
162
168
 
163
169
  declare type EventFnc = (...args: any) => void;
164
170
 
165
- export declare interface FileDetectionOptions {
166
- /**
167
- * 最大文件大小(字节)
168
- */
169
- maxSize?: number;
170
- }
171
-
172
- export declare interface FileDetectionResult {
173
- /**
174
- * 是否通过检测
175
- */
176
- valid: boolean;
177
- /**
178
- * 检测到的真实MIME类型
179
- */
180
- detectedMime?: string;
181
- /**
182
- * 检测到的文件扩展名
183
- */
184
- detectedExt?: string;
185
- /**
186
- * 错误信息
187
- */
188
- error?: string;
189
- /**
190
- * 文件声称的MIME类型(来自File对象)
191
- */
192
- claimedMime?: string;
193
- /**
194
- * MIME类型是否匹配(真实vs声称)
195
- */
196
- mimeMatches?: boolean;
197
- }
198
-
199
171
  /**
200
172
  * 安全的解析html内容 防止xss攻击
201
173
  * @param input 输入的html内容
@@ -305,6 +277,40 @@ export declare interface ICallOptions {
305
277
  call: string;
306
278
  }
307
279
 
280
+ export declare interface IFileDetectionOptions {
281
+ /**
282
+ * 最大文件大小(字节)
283
+ */
284
+ maxSize?: number;
285
+ }
286
+
287
+ export declare interface IFileDetectionResult {
288
+ /**
289
+ * 是否通过检测
290
+ */
291
+ valid: boolean;
292
+ /**
293
+ * 检测到的真实MIME类型
294
+ */
295
+ detectedMime?: string;
296
+ /**
297
+ * 检测到的文件扩展名
298
+ */
299
+ detectedExt?: string;
300
+ /**
301
+ * 错误信息
302
+ */
303
+ error?: string;
304
+ /**
305
+ * 文件声称的MIME类型(来自File对象)
306
+ */
307
+ claimedMime?: string;
308
+ /**
309
+ * MIME类型是否匹配(真实vs声称)
310
+ */
311
+ mimeMatches?: boolean;
312
+ }
313
+
308
314
  export declare interface IResponseDataEncryptionStep {
309
315
  data: string;
310
316
  headers: Record<EHeaderKey, string>;
@@ -327,22 +333,53 @@ export declare interface ISm4Params {
327
333
  * @param options - 配置选项
328
334
  * @returns 是否安全
329
335
  */
330
- export declare function isUrlSafe(url: unknown, options?: UrlSanitizeOptions): boolean;
336
+ export declare function isUrlSafe(url: unknown, options?: IUrlSanitizeOptions): boolean;
331
337
 
332
338
  /**
333
339
  * 便捷方法: 检测是否为文档文件(基于 MIME 类型)
334
340
  */
335
- export declare function isValidDocument(file: File, maxSize?: number): Promise<FileDetectionResult>;
341
+ export declare function isValidDocument(file: File, maxSize?: number): Promise<IFileDetectionResult>;
342
+
343
+ /**
344
+ * 便捷方法: 检测是否为常规支持的文件类型(基于 MIME 类型)
345
+ */
346
+ export declare function isValidFile(file: File, maxSize?: number): Promise<IFileDetectionResult>;
336
347
 
337
348
  /**
338
349
  * 便捷方法: 检测是否为图片文件(基于 MIME 类型)
339
350
  */
340
- export declare function isValidImage(file: File, maxSize?: number): Promise<FileDetectionResult>;
351
+ export declare function isValidImage(file: File, maxSize?: number): Promise<IFileDetectionResult>;
341
352
 
342
353
  /**
343
354
  * 便捷方法: 检测是否为视频文件(基于 MIME 类型)
344
355
  */
345
- export declare function isValidVideo(file: File, maxSize?: number): Promise<FileDetectionResult>;
356
+ export declare function isValidVideo(file: File, maxSize?: number): Promise<IFileDetectionResult>;
357
+
358
+ /**
359
+ * URL XSS 防护工具
360
+ * 用于检测和拦截包含 XSS 攻击的 URL
361
+ */
362
+ /**
363
+ * URL 消毒选项
364
+ */
365
+ export declare interface IUrlSanitizeOptions {
366
+ /**
367
+ * 是否允许相对路径 URL,默认 true
368
+ */
369
+ allowRelative?: boolean;
370
+ /**
371
+ * 额外的安全协议
372
+ */
373
+ extraSafeProtocols?: string[];
374
+ /**
375
+ * 当检测到 XSS 时的替代 URL,默认 '#'
376
+ */
377
+ fallbackUrl?: string;
378
+ /**
379
+ * 是否严格模式,严格模式下只允许 http/https,默认 false
380
+ */
381
+ strictMode?: boolean;
382
+ }
346
383
 
347
384
  /**
348
385
  * 请求数据加密
@@ -373,7 +410,7 @@ export declare function responseDataEncryption<T>(stepCb: (_headers: {
373
410
  * @param options - 配置选项
374
411
  * @returns 安全的 URL
375
412
  */
376
- export declare function sanitizeUrl(url: unknown, options?: UrlSanitizeOptions): string;
413
+ export declare function sanitizeUrl(url: unknown, options?: IUrlSanitizeOptions): string;
377
414
 
378
415
  /**
379
416
  * 批量消毒 URL 列表
@@ -381,7 +418,7 @@ export declare function sanitizeUrl(url: unknown, options?: UrlSanitizeOptions):
381
418
  * @param options - 配置选项
382
419
  * @returns 消毒后的 URL 列表
383
420
  */
384
- export declare function sanitizeUrls(urls: string[], options?: UrlSanitizeOptions): string[];
421
+ export declare function sanitizeUrls(urls: string[], options?: IUrlSanitizeOptions): string[];
385
422
 
386
423
  /**
387
424
  * sip code对应的的状态,优先处理 code 对应的提示文案,如果不存在则按照 causes 状态去处理
@@ -459,32 +496,6 @@ export declare type TObj<K extends keyof any = string, T = any> = Record<K, T>;
459
496
 
460
497
  export declare type TUndefinable<T> = T | undefined;
461
498
 
462
- /**
463
- * URL XSS 防护工具
464
- * 用于检测和拦截包含 XSS 攻击的 URL
465
- */
466
- /**
467
- * URL 消毒选项
468
- */
469
- export declare interface UrlSanitizeOptions {
470
- /**
471
- * 是否允许相对路径 URL,默认 true
472
- */
473
- allowRelative?: boolean;
474
- /**
475
- * 额外的安全协议
476
- */
477
- extraSafeProtocols?: string[];
478
- /**
479
- * 当检测到 XSS 时的替代 URL,默认 '#'
480
- */
481
- fallbackUrl?: string;
482
- /**
483
- * 是否严格模式,严格模式下只允许 http/https,默认 false
484
- */
485
- strictMode?: boolean;
486
- }
487
-
488
499
  /**
489
500
  * 打电话
490
501
  * FIXME: callBack 为什么存在?zyy 中通过 useCall 拿到的变量无法实现响应式,所以通过 callback 的方式更新外部依赖。
package/dist/main.js CHANGED
@@ -1,37 +1,39 @@
1
1
  import { useCall as o } from "./src/outside-call/index.js";
2
- import { antiReplyAttackStrategy as i, requestDataEncryption as s, responseDataEncryption as a } from "./src/shield/crypto/index.js";
3
- import { ALLOWED_FILE_TYPES as p, detectFileByExtension as E, detectFileByMime as l, detectionFilesByExtension as m, detectionFilesByMime as x, isValidDocument as f, isValidImage as S, isValidVideo as d } from "./src/shield/file-detection.js";
4
- import { htmlSanitize as c } from "./src/shield/html-sanitize.js";
5
- import { startNoDebugger as _ } from "./src/shield/no-debugger.js";
6
- import { isUrlSafe as D, sanitizeUrl as M, sanitizeUrls as A } from "./src/shield/url-sanitize.js";
7
- import { EventBus as C } from "./src/utils/eventBus.js";
8
- import { CallLogger as I } from "./src/outside-call/utils.js";
9
- import { ECallStatus as L, EMIT_EVENT_NAME as R, SIP_CODE_MESSAGE as T, SIP_ERROR_CAUSES as U } from "./src/outside-call/constants.js";
10
- import { supportedExtensions as N, supportedMimeTypes as O } from "./vendor/file-type/source/index.js";
2
+ import { antiReplyAttackStrategy as i, requestDataEncryption as s, responseDataEncryption as E } from "./src/shield/crypto/index.js";
3
+ import { ALLOWED_FILE_MIMES as l, ALLOWED_FILE_TYPES as n, detectFileByExtension as p, detectFileByMime as m, detectionFilesByExtension as x, detectionFilesByMime as S, isValidDocument as d, isValidFile as f, isValidImage as _, isValidVideo as y } from "./src/shield/file-detection.js";
4
+ import { htmlSanitize as u } from "./src/shield/html-sanitize.js";
5
+ import { startNoDebugger as D } from "./src/shield/no-debugger.js";
6
+ import { isUrlSafe as I, sanitizeUrl as L, sanitizeUrls as g } from "./src/shield/url-sanitize.js";
7
+ import { EventBus as V } from "./src/utils/eventBus.js";
8
+ import { CallLogger as C } from "./src/outside-call/utils.js";
9
+ import { ECallStatus as R, EMIT_EVENT_NAME as T, SIP_CODE_MESSAGE as U, SIP_ERROR_CAUSES as z } from "./src/outside-call/constants.js";
10
+ import { supportedExtensions as P, supportedMimeTypes as W } from "./vendor/file-type/source/index.js";
11
11
  export {
12
- p as ALLOWED_FILE_TYPES,
13
- I as CallLogger,
14
- L as ECallStatus,
15
- R as EMIT_EVENT_NAME,
16
- C as EventBus,
17
- T as SIP_CODE_MESSAGE,
18
- U as SIP_ERROR_CAUSES,
12
+ l as ALLOWED_FILE_MIMES,
13
+ n as ALLOWED_FILE_TYPES,
14
+ C as CallLogger,
15
+ R as ECallStatus,
16
+ T as EMIT_EVENT_NAME,
17
+ V as EventBus,
18
+ U as SIP_CODE_MESSAGE,
19
+ z as SIP_ERROR_CAUSES,
19
20
  i as antiReplyAttackStrategy,
20
- E as detectFileByExtension,
21
- l as detectFileByMime,
22
- m as detectionFilesByExtension,
23
- x as detectionFilesByMime,
24
- c as htmlSanitize,
25
- D as isUrlSafe,
26
- f as isValidDocument,
27
- S as isValidImage,
28
- d as isValidVideo,
21
+ p as detectFileByExtension,
22
+ m as detectFileByMime,
23
+ x as detectionFilesByExtension,
24
+ S as detectionFilesByMime,
25
+ u as htmlSanitize,
26
+ I as isUrlSafe,
27
+ d as isValidDocument,
28
+ f as isValidFile,
29
+ _ as isValidImage,
30
+ y as isValidVideo,
29
31
  s as requestDataEncryption,
30
- a as responseDataEncryption,
31
- M as sanitizeUrl,
32
- A as sanitizeUrls,
33
- _ as startNoDebugger,
34
- N as supportedExtensions,
35
- O as supportedMimeTypes,
32
+ E as responseDataEncryption,
33
+ L as sanitizeUrl,
34
+ g as sanitizeUrls,
35
+ D as startNoDebugger,
36
+ P as supportedExtensions,
37
+ W as supportedMimeTypes,
36
38
  o as useCall
37
39
  };
@@ -1,19 +1,20 @@
1
- import { supportedMimeTypes as l, fileTypeFromStream as y } from "../../vendor/file-type/source/index.js";
2
- import { supportedExtensions as z } from "../../vendor/file-type/source/index.js";
1
+ import { supportedMimeTypes as f, fileTypeFromStream as y } from "../../vendor/file-type/source/index.js";
2
+ import { supportedExtensions as L } from "../../vendor/file-type/source/index.js";
3
3
  function d(e) {
4
4
  const t = /* @__PURE__ */ new Set();
5
- for (const r of l)
6
- r.startsWith(`${e}/`) && t.add(r);
5
+ for (const i of f)
6
+ i.startsWith(`${e}/`) && t.add(i);
7
7
  return t;
8
8
  }
9
- const f = {
9
+ const l = {
10
10
  // 图片类型 - 从 supportedMimeTypes 中过滤 image/*
11
11
  image: d("image"),
12
12
  // 文档类型 - 包含常见办公文档
13
13
  document: /* @__PURE__ */ new Set([
14
- ...Array.from(l).filter(
15
- (e) => e.includes("pdf") || e.includes("msword") || e.includes("officedocument") || e.includes("ms-excel") || e.includes("ms-powerpoint") || e.includes("opendocument") || e === "text/plain"
16
- )
14
+ ...Array.from(f).filter((e) => {
15
+ const t = e.includes("pdf") || e.includes("msword") || e.includes("officedocument") || e.includes("ms-excel") || e.includes("ms-powerpoint") || e.includes("opendocument") || e === "text/plain", i = e.includes("macroenabled");
16
+ return t && !i;
17
+ })
17
18
  ]),
18
19
  // 视频类型 - 从 supportedMimeTypes 中过滤 video/*
19
20
  video: d("video"),
@@ -21,7 +22,7 @@ const f = {
21
22
  audio: d("audio"),
22
23
  // 压缩文件
23
24
  archive: /* @__PURE__ */ new Set([
24
- ...Array.from(l).filter(
25
+ ...Array.from(f).filter(
25
26
  (e) => e.includes("zip") || e.includes("rar") || e.includes("7z") || e.includes("tar") || e.includes("gzip") || e.includes("compress")
26
27
  )
27
28
  ]),
@@ -29,37 +30,37 @@ const f = {
29
30
  font: d("font"),
30
31
  // 模型文件
31
32
  model: d("model")
32
- };
33
- function M(e, t) {
34
- return t.some((r) => {
35
- const i = r.trim();
36
- if (!i)
33
+ }, M = Object.values(l).reduce((e, t) => (e.push(...Array.from(t)), e), []);
34
+ function v(e, t) {
35
+ return t.some((i) => {
36
+ const r = i.trim();
37
+ if (!r)
37
38
  return !1;
38
- if (i === e)
39
+ if (r === e)
39
40
  return !0;
40
- if (i.endsWith("/*")) {
41
- const n = i.slice(0, i.indexOf("/"));
41
+ if (r.endsWith("/*")) {
42
+ const n = r.slice(0, r.indexOf("/"));
42
43
  return e.startsWith(`${n}/`);
43
44
  }
44
45
  return !1;
45
46
  });
46
47
  }
47
48
  async function p(e, t) {
48
- const { maxSize: r } = t;
49
- if (r && e.size > r)
49
+ const { maxSize: i } = t;
50
+ if (i && e.size > i)
50
51
  return {
51
52
  valid: !1,
52
- error: `上传文件大小不能超过 ${(r / 1024 / 1024).toFixed(2)}MB`,
53
+ error: `上传文件大小不能超过 ${(i / 1024 / 1024).toFixed(2)}MB`,
53
54
  claimedMime: e.type
54
55
  };
55
- const i = await y(e.stream());
56
- if (!i)
56
+ const r = await y(e.stream());
57
+ if (!r)
57
58
  return {
58
59
  valid: !1,
59
60
  error: "无法检测文件类型,可能是不支持的格式或文件已损坏",
60
61
  claimedMime: e.type
61
62
  };
62
- const n = i.mime, o = i.ext, c = e.type, s = n === c;
63
+ const n = r.mime, o = r.ext, c = e.type, s = n === c;
63
64
  return !s && c && console.warn("文件MIME类型不匹配", {
64
65
  claimed: c,
65
66
  detected: n,
@@ -71,12 +72,12 @@ async function p(e, t) {
71
72
  mimeMatches: s
72
73
  };
73
74
  }
74
- async function u(e, t, r = {}) {
75
- const i = await p(e, r);
76
- if ("valid" in i && !i.valid)
77
- return i;
78
- const { detectedMime: n, detectedExt: o, claimedMime: c, mimeMatches: s } = i, m = Array.isArray(t) ? t : t.split(",");
79
- return !n || !M(n, m) ? {
75
+ async function a(e, t, i = {}) {
76
+ const r = await p(e, i);
77
+ if ("valid" in r && !r.valid)
78
+ return r;
79
+ const { detectedMime: n, detectedExt: o, claimedMime: c, mimeMatches: s } = r, m = Array.isArray(t) ? t : t.split(",");
80
+ return !n || !v(n, m) ? {
80
81
  valid: !1,
81
82
  error: `不支持的文件类型: ${n || "未知"}`,
82
83
  detectedMime: n,
@@ -91,12 +92,12 @@ async function u(e, t, r = {}) {
91
92
  mimeMatches: s
92
93
  };
93
94
  }
94
- async function v(e, t, r = {}) {
95
- const i = await p(e, r);
96
- if ("valid" in i && !i.valid)
97
- return i;
98
- const { detectedMime: n, detectedExt: o, claimedMime: c, mimeMatches: s } = i, m = Array.isArray(t) ? t : t.split(",").map((a) => a.trim());
99
- return !o || !m.some((a) => o === a || `.${o}` === a) ? {
95
+ async function A(e, t, i = {}) {
96
+ const r = await p(e, i);
97
+ if ("valid" in r && !r.valid)
98
+ return r;
99
+ const { detectedMime: n, detectedExt: o, claimedMime: c, mimeMatches: s } = r, m = Array.isArray(t) ? t : t.split(",").map((u) => u.trim());
100
+ return !o || !m.some((u) => o === u || `.${o}` === u) ? {
100
101
  valid: !1,
101
102
  error: `不支持的文件扩展名: .${o || "未知"}`,
102
103
  detectedMime: n,
@@ -111,33 +112,38 @@ async function v(e, t, r = {}) {
111
112
  mimeMatches: s
112
113
  };
113
114
  }
114
- function A(e, t, r = {}) {
115
- return Promise.all(e.map((i) => u(i, t, r)));
115
+ function x(e, t, i = {}) {
116
+ return Promise.all(e.map((r) => a(r, t, i)));
116
117
  }
117
- function g(e, t, r = {}) {
118
- return Promise.all(e.map((i) => v(i, t, r)));
118
+ function F(e, t, i = {}) {
119
+ return Promise.all(e.map((r) => A(r, t, i)));
119
120
  }
120
- function E(e, t) {
121
- const r = Array.from(f.image);
122
- return u(e, r, { maxSize: t });
121
+ function g(e, t) {
122
+ const i = Array.from(l.image);
123
+ return a(e, i, { maxSize: t });
123
124
  }
124
125
  function w(e, t) {
125
- const r = Array.from(f.document);
126
- return u(e, r, { maxSize: t });
126
+ const i = Array.from(l.document);
127
+ return a(e, i, { maxSize: t });
128
+ }
129
+ function h(e, t) {
130
+ const i = Array.from(l.video);
131
+ return a(e, i, { maxSize: t });
127
132
  }
128
- function F(e, t) {
129
- const r = Array.from(f.video);
130
- return u(e, r, { maxSize: t });
133
+ function S(e, t) {
134
+ return a(e, M, { maxSize: t });
131
135
  }
132
136
  export {
133
- f as ALLOWED_FILE_TYPES,
134
- v as detectFileByExtension,
135
- u as detectFileByMime,
136
- g as detectionFilesByExtension,
137
- A as detectionFilesByMime,
137
+ M as ALLOWED_FILE_MIMES,
138
+ l as ALLOWED_FILE_TYPES,
139
+ A as detectFileByExtension,
140
+ a as detectFileByMime,
141
+ F as detectionFilesByExtension,
142
+ x as detectionFilesByMime,
138
143
  w as isValidDocument,
139
- E as isValidImage,
140
- F as isValidVideo,
141
- z as supportedExtensions,
142
- l as supportedMimeTypes
144
+ S as isValidFile,
145
+ g as isValidImage,
146
+ h as isValidVideo,
147
+ L as supportedExtensions,
148
+ f as supportedMimeTypes
143
149
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "module-develop-kit",
3
3
  "author": "Front-End team",
4
- "version": "1.2.0",
4
+ "version": "1.2.2",
5
5
  "type": "module",
6
6
  "description": "前端项目通用工具包",
7
7
  "module": "dist/main.js",