@pnt-team/pnt-component-frontend 0.0.92 → 0.0.96

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.
Files changed (32) hide show
  1. package/README.md +26 -4
  2. package/lib/cjs/api/cos.d.ts +103 -0
  3. package/lib/cjs/api/cos.js +137 -0
  4. package/lib/cjs/components/PntCosUploader/index.d.ts +135 -0
  5. package/lib/cjs/components/PntCosUploader/index.js +209 -0
  6. package/lib/cjs/components/PntImage/index.d.ts +9 -3
  7. package/lib/cjs/components/PntImage/index.js +9 -1
  8. package/lib/cjs/components/PntSecureBox/index.js +8 -3
  9. package/lib/cjs/components/PntUpload/index.d.ts +149 -0
  10. package/lib/cjs/components/PntUpload/index.js +228 -0
  11. package/lib/cjs/components/PntUpload/index.scss +101 -0
  12. package/lib/cjs/hooks/useHighSecurity.d.ts +55 -15
  13. package/lib/cjs/hooks/useHighSecurity.js +163 -35
  14. package/lib/cjs/index.d.ts +6 -0
  15. package/lib/cjs/index.js +18 -2
  16. package/lib/esm/api/cos.d.ts +103 -0
  17. package/lib/esm/api/cos.js +189 -0
  18. package/lib/esm/components/PntCosUploader/index.d.ts +135 -0
  19. package/lib/esm/components/PntCosUploader/index.js +289 -0
  20. package/lib/esm/components/PntImage/index.d.ts +9 -3
  21. package/lib/esm/components/PntImage/index.js +22 -3
  22. package/lib/esm/components/PntSecureBox/index.js +9 -3
  23. package/lib/esm/components/PntUpload/index.d.ts +149 -0
  24. package/lib/esm/components/PntUpload/index.js +276 -0
  25. package/lib/esm/components/PntUpload/index.scss +101 -0
  26. package/lib/esm/hooks/useHighSecurity.d.ts +55 -15
  27. package/lib/esm/hooks/useHighSecurity.js +174 -32
  28. package/lib/esm/index.d.ts +6 -0
  29. package/lib/esm/index.js +9 -1
  30. package/lib/umd/pnt-component-frontend.min.css +1 -1
  31. package/lib/umd/pnt-component-frontend.min.js +1 -1
  32. package/package.json +1 -1
@@ -46,6 +46,7 @@ var PntImage = ({
46
46
  src,
47
47
  alt = "",
48
48
  defaultImg,
49
+ size,
49
50
  style,
50
51
  loading = false,
51
52
  onRemove,
@@ -54,6 +55,13 @@ var PntImage = ({
54
55
  }) => {
55
56
  const isUploadMode = typeof onRemove === "function";
56
57
  const finalSrc = (src == null ? void 0 : src.length) ? src : defaultImg || import_uploadImg.default;
58
+ const SIZE_MAP = { small: 36, medium: 60, large: 136 };
59
+ const sizeValue = SIZE_MAP[size != null ? size : "large"];
60
+ const sizeStyle = {
61
+ width: `${sizeValue}px`,
62
+ height: `${sizeValue}px`
63
+ };
64
+ const mergedStyle = { ...sizeStyle, ...style };
57
65
  const attach = container ? typeof container === "function" ? container : () => container : void 0;
58
66
  const finalTexts = { ...DEFAULT_TEXTS, ...texts };
59
67
  const UploadLoadingContent = (isImageLoading) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -125,7 +133,7 @@ var PntImage = ({
125
133
  overlayTrigger: "hover",
126
134
  fit: "contain",
127
135
  className: "pnt-image",
128
- style
136
+ style: mergedStyle
129
137
  }
130
138
  );
131
139
  }
@@ -28,12 +28,17 @@ var import_index = require("./index.scss");
28
28
  var import_jsx_runtime = require("react/jsx-runtime");
29
29
  var PntSecureBox = (prop) => {
30
30
  const { dataKey, dataValue, env, gameId, renderDom, viewText, pageId } = prop;
31
- const { securityData, requestSecurityData } = (0, import_useHighSecurity.useHighSecurity)();
31
+ const { securityData, isUnlocked, requestSecurityData } = (0, import_useHighSecurity.useHighSecurity)({
32
+ gameId,
33
+ env
34
+ });
35
+ const isSecurity = (0, import_utils.isSecurityData)(dataValue);
36
+ const unlocked = isSecurity && isUnlocked(dataKey);
32
37
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pnt-secure-box", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
33
38
  renderDom(
34
- (0, import_utils.isSecurityData)(dataValue) ? securityData[dataKey] || "******" : dataValue
39
+ unlocked ? securityData[dataKey] || "******" : isSecurity ? "******" : dataValue
35
40
  ),
36
- (0, import_utils.isSecurityData)(dataValue) && !securityData.hasOwnProperty(dataKey) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
41
+ isSecurity && !isUnlocked(dataKey) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
37
42
  "span",
38
43
  {
39
44
  className: "view-icon",
@@ -0,0 +1,149 @@
1
+ import type { CosScene } from "../../api/cos";
2
+ import type { FileNameStrategy, PntCosUploadOptions } from "../PntCosUploader";
3
+ import React, { FC } from 'react';
4
+ import './index.scss';
5
+ /**
6
+ * PntUpload 文案集合
7
+ * @description 所有内部展示文案均可通过 texts prop 自定义,用于多语言场景
8
+ */
9
+ export interface PntUploadTexts {
10
+ /** 上传中文案 */
11
+ uploading?: string;
12
+ /** 上传失败文案 */
13
+ uploadFailed?: string;
14
+ /** 文件大小超出限制文案 */
15
+ sizeInvalid?: string;
16
+ /** 文件类型不支持文案 */
17
+ typeInvalid?: string;
18
+ /** 选择文件文案(无文件时) */
19
+ selectFile?: string;
20
+ /** 重新选择文案(已有文件时,非图片模式) */
21
+ reselect?: string;
22
+ }
23
+ /**
24
+ * 校验/上传失败阶段
25
+ */
26
+ export type PntUploadErrorPhase = 'validate' | 'upload';
27
+ export interface PntUploadProps {
28
+ /**
29
+ * 当前已上传文件 URL(受控)
30
+ */
31
+ value?: string;
32
+ /**
33
+ * 上传成功回调
34
+ * @param fileUrl 上传后的可访问 URL
35
+ * @param cosKey COS 对象 Key
36
+ * @param file 原始文件
37
+ */
38
+ onChange?: (fileUrl: string, cosKey: string, file: File) => void;
39
+ /**
40
+ * 删除回调
41
+ * @description 由消费方清空 value
42
+ */
43
+ onRemove?: () => void;
44
+ /**
45
+ * 异常回调(校验失败 / 上传失败)
46
+ * @param err 错误对象(校验失败时 message 为对应文案)
47
+ * @param phase 失败阶段:validate=本地校验,upload=凭证获取或 COS 上传
48
+ * @param file 原始文件
49
+ */
50
+ onError?: (err: Error, phase: PntUploadErrorPhase, file: File) => void;
51
+ /**
52
+ * 业务场景(透传给 PntCosUploader)
53
+ */
54
+ scene: CosScene;
55
+ /**
56
+ * 业务类型路径 key(透传给 PntCosUploader)
57
+ */
58
+ pathKey?: string;
59
+ /**
60
+ * 业务上下文(透传给 PntCosUploader)
61
+ */
62
+ context?: Record<string, string | number>;
63
+ /**
64
+ * 网关 audience(透传给 PntCosUploader)
65
+ * @default '/player-network'
66
+ */
67
+ audience?: string;
68
+ /**
69
+ * 文件类型限制
70
+ * @description 支持 MIME('image/png')、通配('image/*')、扩展名('.zip'),可传数组
71
+ */
72
+ accept?: string | string[];
73
+ /**
74
+ * 文件大小限制(字节)
75
+ */
76
+ sizeLimit?: number;
77
+ /**
78
+ * 是否为图片预览模式
79
+ * @description true 使用 PntImage 预览;false 使用文件名 + 选择区域
80
+ * @default true
81
+ */
82
+ imagePreview?: boolean;
83
+ /**
84
+ * 图片预览区样式(imagePreview=true 生效,一般控制宽高)
85
+ */
86
+ previewStyle?: React.CSSProperties;
87
+ /**
88
+ * 默认占位图(imagePreview=true 生效)
89
+ */
90
+ defaultImg?: string;
91
+ /**
92
+ * 文件名生成策略(透传给 PntCosUploader)
93
+ * @default 'uuid'
94
+ */
95
+ fileNameStrategy?: FileNameStrategy;
96
+ /**
97
+ * 是否走 CDN 域名拼接(透传给 PntCosUploader)
98
+ * @default true
99
+ */
100
+ useCdn?: boolean;
101
+ /**
102
+ * 自定义凭证获取函数(透传给 PntCosUploader)
103
+ */
104
+ getCredential?: PntCosUploadOptions['getCredential'];
105
+ /**
106
+ * 自定义凭证响应归一化(透传给 PntCosUploader)
107
+ */
108
+ normalizeCredential?: PntCosUploadOptions['normalizeCredential'];
109
+ /**
110
+ * 多语言文案
111
+ * @description 传入即覆盖默认中文文案;仅对应字段会覆盖,未传字段仍用默认值
112
+ */
113
+ texts?: PntUploadTexts;
114
+ /**
115
+ * 禁用上传与删除
116
+ * @default false
117
+ */
118
+ disabled?: boolean;
119
+ /**
120
+ * 自定义样式
121
+ */
122
+ style?: React.CSSProperties;
123
+ /**
124
+ * 自定义类名
125
+ */
126
+ className?: string;
127
+ }
128
+ /**
129
+ * PntUpload 业务上传组件
130
+ * @description 基于 TDesign Upload + PntImage + usePntCosUploader,
131
+ * 内置 COS 凭证获取、直传、进度、校验、错误处理;支持图片预览 / 文件两种模式
132
+ *
133
+ * @example
134
+ * ```tsx
135
+ * <PntUpload
136
+ * scene="default"
137
+ * pathKey="marketing_icon"
138
+ * context={{ gameId }}
139
+ * accept="image/png"
140
+ * sizeLimit={500 * 1024}
141
+ * imagePreview
142
+ * value={iconUrl}
143
+ * onChange={(url) => setIconUrl(url)}
144
+ * onRemove={() => setIconUrl('')}
145
+ * />
146
+ * ```
147
+ */
148
+ declare const PntUpload: FC<PntUploadProps>;
149
+ export default PntUpload;
@@ -0,0 +1,228 @@
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
+
29
+ // src/components/PntUpload/index.tsx
30
+ var PntUpload_exports = {};
31
+ __export(PntUpload_exports, {
32
+ default: () => PntUpload_default
33
+ });
34
+ module.exports = __toCommonJS(PntUpload_exports);
35
+ var import_PntCosUploader = __toESM(require("../PntCosUploader"));
36
+ var import_PntImage = __toESM(require("../PntImage"));
37
+ var import_react = require("react");
38
+ var import_tdesign_icons_react = require("tdesign-icons-react");
39
+ var import_tdesign_react = require("tdesign-react");
40
+ var import_index = require("./index.scss");
41
+ var import_jsx_runtime = require("react/jsx-runtime");
42
+ var DEFAULT_TEXTS = {
43
+ uploading: "上传中",
44
+ uploadFailed: "上传失败,请重试",
45
+ sizeInvalid: "文件大小超出限制",
46
+ typeInvalid: "文件类型不支持",
47
+ selectFile: "选择文件",
48
+ reselect: "重新选择"
49
+ };
50
+ var toAcceptList = (accept) => {
51
+ const raw = Array.isArray(accept) ? accept : accept ? accept.split(",") : [];
52
+ return raw.map((item) => item.trim().toLowerCase()).filter(Boolean);
53
+ };
54
+ var matchAccept = (file, acceptList) => {
55
+ if (!acceptList.length) {
56
+ return true;
57
+ }
58
+ const name = file.name.toLowerCase();
59
+ const type = file.type.toLowerCase();
60
+ return acceptList.some((token) => {
61
+ if (token.startsWith(".")) {
62
+ return name.endsWith(token);
63
+ }
64
+ if (token.endsWith("/*")) {
65
+ return !!type && type.startsWith(token.slice(0, -1));
66
+ }
67
+ return type === token;
68
+ });
69
+ };
70
+ var getFileNameFromUrl = (url) => {
71
+ if (!url) {
72
+ return "";
73
+ }
74
+ const lastSeg = url.split("?")[0].split("/").pop() || "";
75
+ try {
76
+ return decodeURIComponent(lastSeg);
77
+ } catch {
78
+ return lastSeg;
79
+ }
80
+ };
81
+ var PntUpload = ({
82
+ value,
83
+ onChange,
84
+ onRemove,
85
+ onError,
86
+ scene,
87
+ pathKey,
88
+ context,
89
+ audience,
90
+ accept,
91
+ sizeLimit,
92
+ imagePreview = true,
93
+ previewStyle,
94
+ defaultImg,
95
+ fileNameStrategy,
96
+ useCdn,
97
+ getCredential,
98
+ normalizeCredential,
99
+ texts,
100
+ disabled = false,
101
+ style,
102
+ className
103
+ }) => {
104
+ const [uploading, setUploading] = (0, import_react.useState)(false);
105
+ const [percent, setPercent] = (0, import_react.useState)(0);
106
+ const [errorText, setErrorText] = (0, import_react.useState)("");
107
+ const [lastFile, setLastFile] = (0, import_react.useState)(null);
108
+ const finalTexts = (0, import_react.useMemo)(() => ({ ...DEFAULT_TEXTS, ...texts }), [texts]);
109
+ const acceptList = (0, import_react.useMemo)(() => toAcceptList(accept), [accept]);
110
+ const acceptString = (0, import_react.useMemo)(() => acceptList.join(", "), [acceptList]);
111
+ const uploader = (0, import_PntCosUploader.default)({
112
+ scene,
113
+ pathKey,
114
+ context,
115
+ audience,
116
+ fileNameStrategy,
117
+ useCdn,
118
+ getCredential,
119
+ normalizeCredential
120
+ });
121
+ const reportError = (message, phase, file) => {
122
+ setErrorText(message);
123
+ onError == null ? void 0 : onError(new Error(message), phase, file);
124
+ };
125
+ const requestMethod = async (files) => {
126
+ const tdFile = Array.isArray(files) ? files[0] : files;
127
+ const file = tdFile == null ? void 0 : tdFile.raw;
128
+ if (!file) {
129
+ return { status: "fail", error: "no file", response: {} };
130
+ }
131
+ if (!matchAccept(file, acceptList)) {
132
+ reportError(finalTexts.typeInvalid, "validate", file);
133
+ return { status: "fail", error: finalTexts.typeInvalid, response: {} };
134
+ }
135
+ if (typeof sizeLimit === "number" && file.size > sizeLimit) {
136
+ reportError(finalTexts.sizeInvalid, "validate", file);
137
+ return { status: "fail", error: finalTexts.sizeInvalid, response: {} };
138
+ }
139
+ setUploading(true);
140
+ setPercent(0);
141
+ setErrorText("");
142
+ try {
143
+ const result = await uploader.upload(file, setPercent);
144
+ setLastFile(file);
145
+ onChange == null ? void 0 : onChange(result.fileUrl, result.cosKey, file);
146
+ return {
147
+ status: "success",
148
+ response: { url: result.fileUrl }
149
+ };
150
+ } catch (e) {
151
+ const err = e instanceof Error ? e : new Error(String(e));
152
+ setErrorText(finalTexts.uploadFailed);
153
+ onError == null ? void 0 : onError(err, "upload", file);
154
+ return { status: "fail", error: err.message, response: {} };
155
+ } finally {
156
+ setUploading(false);
157
+ }
158
+ };
159
+ const handleRemove = (e) => {
160
+ e.stopPropagation();
161
+ if (disabled || uploading) {
162
+ return;
163
+ }
164
+ setLastFile(null);
165
+ setErrorText("");
166
+ onRemove == null ? void 0 : onRemove();
167
+ };
168
+ const wrapperClassName = [
169
+ "pnt-upload",
170
+ imagePreview ? "pnt-upload--image" : "pnt-upload--file",
171
+ disabled ? "pnt-upload--disabled" : "",
172
+ className || ""
173
+ ].filter(Boolean).join(" ");
174
+ const displayName = (lastFile == null ? void 0 : lastFile.name) || getFileNameFromUrl(value);
175
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: wrapperClassName, style, children: [
176
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
177
+ import_tdesign_react.Upload,
178
+ {
179
+ theme: "custom",
180
+ requestMethod,
181
+ accept: acceptString || void 0,
182
+ allowUploadDuplicateFile: true,
183
+ disabled: disabled || uploading,
184
+ className: "pnt-upload__trigger",
185
+ children: imagePreview ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
186
+ import_PntImage.default,
187
+ {
188
+ src: value,
189
+ loading: uploading,
190
+ defaultImg,
191
+ style: previewStyle,
192
+ texts: { uploading: finalTexts.uploading },
193
+ onRemove: disabled ? void 0 : handleRemove
194
+ }
195
+ ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "pnt-upload-file", children: value && !uploading ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pnt-upload-file__row", children: [
196
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tdesign_icons_react.FileIcon, { className: "pnt-upload-file__icon" }),
197
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "pnt-upload-file__name", title: displayName, children: displayName }),
198
+ !disabled && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
199
+ import_tdesign_icons_react.DeleteIcon,
200
+ {
201
+ className: "pnt-upload-file__delete",
202
+ onClick: handleRemove
203
+ }
204
+ )
205
+ ] }) : uploading ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pnt-upload-file__row pnt-upload-file__row--progress", children: [
206
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
207
+ import_tdesign_react.Progress,
208
+ {
209
+ percentage: percent,
210
+ className: "pnt-upload-file__progress"
211
+ }
212
+ ),
213
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "pnt-upload-file__percent", children: [
214
+ finalTexts.uploading,
215
+ " ",
216
+ percent,
217
+ "%"
218
+ ] })
219
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "pnt-upload-file__row pnt-upload-file__row--empty", children: [
220
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tdesign_icons_react.UploadIcon, { className: "pnt-upload-file__icon" }),
221
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: value ? finalTexts.reselect : finalTexts.selectFile })
222
+ ] }) })
223
+ }
224
+ ),
225
+ errorText && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "pnt-upload__error", children: errorText })
226
+ ] });
227
+ };
228
+ var PntUpload_default = PntUpload;
@@ -0,0 +1,101 @@
1
+ .pnt-upload {
2
+ display: inline-block;
3
+
4
+ // TDesign Upload custom 触发器外层
5
+ .pnt-upload__trigger {
6
+ display: inline-block;
7
+ cursor: pointer;
8
+ }
9
+
10
+ // 错误文案(图片 / 文件模式共用)
11
+ .pnt-upload__error {
12
+ margin: 4px 0 0;
13
+ color: var(--td-error-color, #d54941);
14
+ font-size: 12px;
15
+ line-height: 20px;
16
+ }
17
+
18
+ &--disabled {
19
+ .pnt-upload__trigger {
20
+ cursor: not-allowed;
21
+ }
22
+ }
23
+
24
+ // ========== 文件模式 ==========
25
+ .pnt-upload-file {
26
+ box-sizing: border-box;
27
+ min-width: 320px;
28
+ padding: 12px 16px;
29
+ border: 1px dashed var(--td-component-border, #dcdcdc);
30
+ border-radius: var(--td-radius-default, 6px);
31
+ background-color: var(--td-bg-color-container, #fff);
32
+ transition: border-color 0.2s;
33
+
34
+ &:hover {
35
+ border-color: var(--td-brand-color, #165dff);
36
+ }
37
+
38
+ &__row {
39
+ display: flex;
40
+ align-items: center;
41
+ gap: 8px;
42
+ color: var(--td-text-color-primary, #1f2329);
43
+ font-size: 14px;
44
+ line-height: 22px;
45
+
46
+ &--empty {
47
+ justify-content: flex-start;
48
+ color: var(--td-text-color-secondary, #6b7280);
49
+ }
50
+
51
+ &--progress {
52
+ align-items: center;
53
+ }
54
+ }
55
+
56
+ &__icon {
57
+ flex: none;
58
+ font-size: 20px;
59
+ color: var(--td-text-color-secondary, #6b7280);
60
+ }
61
+
62
+ &__name {
63
+ flex: 1;
64
+ overflow: hidden;
65
+ white-space: nowrap;
66
+ text-overflow: ellipsis;
67
+ }
68
+
69
+ &__delete {
70
+ flex: none;
71
+ font-size: 18px;
72
+ color: var(--td-text-color-secondary, #6b7280);
73
+ cursor: pointer;
74
+
75
+ &:hover {
76
+ color: var(--td-error-color, #d54941);
77
+ }
78
+ }
79
+
80
+ &__progress {
81
+ flex: 1;
82
+ min-width: 0;
83
+ }
84
+
85
+ &__percent {
86
+ flex: none;
87
+ color: var(--td-text-color-secondary, #6b7280);
88
+ font-size: 12px;
89
+ }
90
+ }
91
+
92
+ &--disabled {
93
+ .pnt-upload-file {
94
+ background-color: var(--td-bg-color-component-disabled, #f3f3f3);
95
+
96
+ &:hover {
97
+ border-color: var(--td-component-border, #dcdcdc);
98
+ }
99
+ }
100
+ }
101
+ }
@@ -1,22 +1,62 @@
1
- /** 高敏数据请求参数(组件层友好命名) */
1
+ /** 单个解锁项 */
2
+ export interface HighSecurityParamItem {
3
+ /** 字段标识(与后端约定) */
4
+ key: string;
5
+ /** 参数密文(_high_security_: 前缀) */
6
+ value: string;
7
+ }
8
+ /** 高敏数据解锁请求参数(组件层友好命名,库内部转换为后端 snake_case) */
2
9
  export interface HighSecurityRequestParams {
3
- /** 游戏 ID */
10
+ /** 业务 ID */
4
11
  gameId: string | number;
5
- /** 环境标识 */
12
+ /** 环境标识(1=dev 2=test 3=prod,以各业务现有约定为准) */
6
13
  env: string | number;
7
- /** 页面 ID(不传则默认取 location.pathname) */
14
+ /** 页面 ID(不传则默认取 location.pathname),用于操作日志和权限校验 */
8
15
  pageId?: string;
9
- /** 需要解锁的参数列表 */
10
- param: Array<{
11
- key: string;
12
- value: string;
13
- }>;
16
+ /** 需要解锁的参数列表,支持批量 */
17
+ param: HighSecurityParamItem[];
18
+ }
19
+ /** hook 初始化 scope:传入后 securityData/isUnlocked 自动按该业务+环境过滤 */
20
+ export interface UseHighSecurityOptions {
21
+ /** 当前业务 ID */
22
+ gameId?: string | number;
23
+ /** 当前环境 */
24
+ env?: string | number;
25
+ }
26
+ /** 清缓存过滤条件 */
27
+ export interface ClearSecurityDataFilter {
28
+ gameId?: string | number;
29
+ env?: string | number;
30
+ }
31
+ export interface UseHighSecurityResult {
32
+ /** 当前 scope 下已解锁的明文(key 为纯字段名);未传 scope 时为空对象 */
33
+ securityData: Record<string, string>;
34
+ /**
35
+ * 发起解锁
36
+ * @description
37
+ * - 已缓存的 key 直接返回缓存值,不再请求
38
+ * - 同一参数的在途请求自动去重
39
+ * - 成功:写入模块缓存并返回当次解密数组(含已缓存项)
40
+ * - 失败/部分失败:仅返回拿到的项(可能为空数组),不抛错
41
+ */
42
+ requestSecurityData: (params: HighSecurityRequestParams) => Promise<HighSecurityParamItem[]>;
43
+ /**
44
+ * 清缓存:不传参清空全部;传 gameId 清空该业务所有环境;
45
+ * 同时传 gameId+env 只清空该业务指定环境;仅传 env 清空所有业务该环境
46
+ */
47
+ clearSecurityData: (filter?: ClearSecurityDataFilter) => void;
48
+ /** 当前 scope 下某字段是否已解锁(两步式"查看 → 复制"UI 用) */
49
+ isUnlocked: (key: string) => boolean;
14
50
  }
15
51
  /**
16
- * 高敏数据解锁 Hook(PntSecureBox 内部依赖)
17
- * @internal 不对外导出,归 PntSecureBox 组件内部使用
52
+ * 高敏数据解锁 Hook(PntSecureBox 内部依赖,同时对外导出供"复制"等非展示场景使用)
53
+ *
54
+ * @example
55
+ * ```tsx
56
+ * // 展示场景请直接用 PntSecureBox;两步式"查看 → 复制":
57
+ * const { isUnlocked, requestSecurityData, securityData } = useHighSecurity({ gameId, env });
58
+ * const res = await requestSecurityData({ gameId, env, param: [{ key: 'SDK_KEY', value }] });
59
+ * if (res.length) copy(securityData.SDK_KEY);
60
+ * ```
18
61
  */
19
- export declare const useHighSecurity: () => {
20
- securityData: Record<string, string>;
21
- requestSecurityData: ({ gameId, param, env, pageId, }: HighSecurityRequestParams) => Promise<void>;
22
- };
62
+ export declare const useHighSecurity: (options?: UseHighSecurityOptions) => UseHighSecurityResult;