@zucker-framework/fe-types 1.0.0 → 1.0.5
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/README.md +7 -0
- package/dist/index.d.mts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +29 -2
- package/dist/index.mjs +24 -1
- package/package.json +3 -2
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Frontend shared contracts
|
|
2
|
+
|
|
3
|
+
This package exports frontend-safe types, runtime schemas and template-variable extraction. `redactFields(value, sensitiveFields, replacement?)` recursively copies JSON-like data, replacing explicitly selected keys without mutating the input. Field matching is case-sensitive; the default replacement is `[Redacted]`. Consumers retain sensitive-field lists and reporter hooks.
|
|
4
|
+
|
|
5
|
+
The redaction primitive has no Node, NestJS or backend dependencies. It expects JSON-like objects and arrays, matching error-report payloads. Its source contracts are in `src/redact-fields.spec.ts`; a new immutable release and consumer validation are required before adopting new exports from the registry.
|
|
6
|
+
|
|
7
|
+
`redactFields` now reuses `@zucker-framework/core/privacy`. `inspectUserAgent(ua)` and `UserAgentDetails` reuse `@zucker-framework/core/user-agent`, exposing nullable browser/OS/device details and desktop/mobile/tablet/bot classification. The application chooses labels, missing-value text and version display. These explicit Core entry points contain no Node dependencies; frontend code does not import the Core root.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod/v4';
|
|
2
|
+
export { redactFields } from '@zucker-framework/core/privacy';
|
|
3
|
+
export { UserAgentDetails, inspectUserAgent } from '@zucker-framework/core/user-agent';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Zod Schemas — 前后端共享的 Single Source of Truth
|
|
@@ -160,6 +162,11 @@ declare const LoginResponseSchema: z.ZodObject<{
|
|
|
160
162
|
}, z.core.$strip>;
|
|
161
163
|
}, z.core.$strip>;
|
|
162
164
|
|
|
165
|
+
/** 匹配 {{variableName}} 占位符(仅 \w:字母数字下划线) */
|
|
166
|
+
declare const TEMPLATE_VARIABLE_REGEX: RegExp;
|
|
167
|
+
/** 从一段或多段 HTML 中提取所有 {{variable}} 名称,去重 */
|
|
168
|
+
declare function extractTemplateVariables(...htmls: Array<string | null | undefined>): string[];
|
|
169
|
+
|
|
163
170
|
/** Represents an authenticated user in the system. */
|
|
164
171
|
interface User {
|
|
165
172
|
/** Unique user identifier. */
|
|
@@ -291,4 +298,4 @@ interface AuthState {
|
|
|
291
298
|
permissions: string[];
|
|
292
299
|
}
|
|
293
300
|
|
|
294
|
-
export { ApiErrorResponseSchema, type ApiResponse, ApiResponseSchema, type AuthState, AuthStateSchema, CreateUserSchema, type DictionaryItem, DictionaryItemSchema, LoginRequestSchema, LoginResponseSchema, type MenuItem, MenuItemSchema, type PaginatedResponse, PaginatedResponseSchema, type SelectOption, SelectOptionSchema, type TreeNode, TreeNodeSchema, UpdateUserSchema, type UploadFile, UploadFileSchema, type User, UserSchema };
|
|
301
|
+
export { ApiErrorResponseSchema, type ApiResponse, ApiResponseSchema, type AuthState, AuthStateSchema, CreateUserSchema, type DictionaryItem, DictionaryItemSchema, LoginRequestSchema, LoginResponseSchema, type MenuItem, MenuItemSchema, type PaginatedResponse, PaginatedResponseSchema, type SelectOption, SelectOptionSchema, TEMPLATE_VARIABLE_REGEX, type TreeNode, TreeNodeSchema, UpdateUserSchema, type UploadFile, UploadFileSchema, type User, UserSchema, extractTemplateVariables };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod/v4';
|
|
2
|
+
export { redactFields } from '@zucker-framework/core/privacy';
|
|
3
|
+
export { UserAgentDetails, inspectUserAgent } from '@zucker-framework/core/user-agent';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Zod Schemas — 前后端共享的 Single Source of Truth
|
|
@@ -160,6 +162,11 @@ declare const LoginResponseSchema: z.ZodObject<{
|
|
|
160
162
|
}, z.core.$strip>;
|
|
161
163
|
}, z.core.$strip>;
|
|
162
164
|
|
|
165
|
+
/** 匹配 {{variableName}} 占位符(仅 \w:字母数字下划线) */
|
|
166
|
+
declare const TEMPLATE_VARIABLE_REGEX: RegExp;
|
|
167
|
+
/** 从一段或多段 HTML 中提取所有 {{variable}} 名称,去重 */
|
|
168
|
+
declare function extractTemplateVariables(...htmls: Array<string | null | undefined>): string[];
|
|
169
|
+
|
|
163
170
|
/** Represents an authenticated user in the system. */
|
|
164
171
|
interface User {
|
|
165
172
|
/** Unique user identifier. */
|
|
@@ -291,4 +298,4 @@ interface AuthState {
|
|
|
291
298
|
permissions: string[];
|
|
292
299
|
}
|
|
293
300
|
|
|
294
|
-
export { ApiErrorResponseSchema, type ApiResponse, ApiResponseSchema, type AuthState, AuthStateSchema, CreateUserSchema, type DictionaryItem, DictionaryItemSchema, LoginRequestSchema, LoginResponseSchema, type MenuItem, MenuItemSchema, type PaginatedResponse, PaginatedResponseSchema, type SelectOption, SelectOptionSchema, type TreeNode, TreeNodeSchema, UpdateUserSchema, type UploadFile, UploadFileSchema, type User, UserSchema };
|
|
301
|
+
export { ApiErrorResponseSchema, type ApiResponse, ApiResponseSchema, type AuthState, AuthStateSchema, CreateUserSchema, type DictionaryItem, DictionaryItemSchema, LoginRequestSchema, LoginResponseSchema, type MenuItem, MenuItemSchema, type PaginatedResponse, PaginatedResponseSchema, type SelectOption, SelectOptionSchema, TEMPLATE_VARIABLE_REGEX, type TreeNode, TreeNodeSchema, UpdateUserSchema, type UploadFile, UploadFileSchema, type User, UserSchema, extractTemplateVariables };
|
package/dist/index.js
CHANGED
|
@@ -30,10 +30,14 @@ __export(index_exports, {
|
|
|
30
30
|
MenuItemSchema: () => MenuItemSchema,
|
|
31
31
|
PaginatedResponseSchema: () => PaginatedResponseSchema,
|
|
32
32
|
SelectOptionSchema: () => SelectOptionSchema,
|
|
33
|
+
TEMPLATE_VARIABLE_REGEX: () => TEMPLATE_VARIABLE_REGEX,
|
|
33
34
|
TreeNodeSchema: () => TreeNodeSchema,
|
|
34
35
|
UpdateUserSchema: () => UpdateUserSchema,
|
|
35
36
|
UploadFileSchema: () => UploadFileSchema,
|
|
36
|
-
UserSchema: () => UserSchema
|
|
37
|
+
UserSchema: () => UserSchema,
|
|
38
|
+
extractTemplateVariables: () => extractTemplateVariables,
|
|
39
|
+
inspectUserAgent: () => import_user_agent.inspectUserAgent,
|
|
40
|
+
redactFields: () => import_privacy.redactFields
|
|
37
41
|
});
|
|
38
42
|
module.exports = __toCommonJS(index_exports);
|
|
39
43
|
|
|
@@ -128,6 +132,25 @@ var LoginResponseSchema = import_v4.z.object({
|
|
|
128
132
|
refreshToken: import_v4.z.string().optional(),
|
|
129
133
|
user: UserSchema
|
|
130
134
|
});
|
|
135
|
+
|
|
136
|
+
// src/template-variables.ts
|
|
137
|
+
var TEMPLATE_VARIABLE_REGEX = /\{\{(\w+)\}\}/g;
|
|
138
|
+
function extractTemplateVariables(...htmls) {
|
|
139
|
+
const found = /* @__PURE__ */ new Set();
|
|
140
|
+
for (const html of htmls) {
|
|
141
|
+
if (!html) continue;
|
|
142
|
+
for (const m of html.matchAll(TEMPLATE_VARIABLE_REGEX)) {
|
|
143
|
+
found.add(m[1]);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return [...found];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// src/redact-fields.ts
|
|
150
|
+
var import_privacy = require("@zucker-framework/core/privacy");
|
|
151
|
+
|
|
152
|
+
// src/index.ts
|
|
153
|
+
var import_user_agent = require("@zucker-framework/core/user-agent");
|
|
131
154
|
// Annotate the CommonJS export names for ESM import in node:
|
|
132
155
|
0 && (module.exports = {
|
|
133
156
|
ApiErrorResponseSchema,
|
|
@@ -140,8 +163,12 @@ var LoginResponseSchema = import_v4.z.object({
|
|
|
140
163
|
MenuItemSchema,
|
|
141
164
|
PaginatedResponseSchema,
|
|
142
165
|
SelectOptionSchema,
|
|
166
|
+
TEMPLATE_VARIABLE_REGEX,
|
|
143
167
|
TreeNodeSchema,
|
|
144
168
|
UpdateUserSchema,
|
|
145
169
|
UploadFileSchema,
|
|
146
|
-
UserSchema
|
|
170
|
+
UserSchema,
|
|
171
|
+
extractTemplateVariables,
|
|
172
|
+
inspectUserAgent,
|
|
173
|
+
redactFields
|
|
147
174
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -89,6 +89,25 @@ var LoginResponseSchema = z.object({
|
|
|
89
89
|
refreshToken: z.string().optional(),
|
|
90
90
|
user: UserSchema
|
|
91
91
|
});
|
|
92
|
+
|
|
93
|
+
// src/template-variables.ts
|
|
94
|
+
var TEMPLATE_VARIABLE_REGEX = /\{\{(\w+)\}\}/g;
|
|
95
|
+
function extractTemplateVariables(...htmls) {
|
|
96
|
+
const found = /* @__PURE__ */ new Set();
|
|
97
|
+
for (const html of htmls) {
|
|
98
|
+
if (!html) continue;
|
|
99
|
+
for (const m of html.matchAll(TEMPLATE_VARIABLE_REGEX)) {
|
|
100
|
+
found.add(m[1]);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return [...found];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/redact-fields.ts
|
|
107
|
+
import { redactFields } from "@zucker-framework/core/privacy";
|
|
108
|
+
|
|
109
|
+
// src/index.ts
|
|
110
|
+
import { inspectUserAgent } from "@zucker-framework/core/user-agent";
|
|
92
111
|
export {
|
|
93
112
|
ApiErrorResponseSchema,
|
|
94
113
|
ApiResponseSchema,
|
|
@@ -100,8 +119,12 @@ export {
|
|
|
100
119
|
MenuItemSchema,
|
|
101
120
|
PaginatedResponseSchema,
|
|
102
121
|
SelectOptionSchema,
|
|
122
|
+
TEMPLATE_VARIABLE_REGEX,
|
|
103
123
|
TreeNodeSchema,
|
|
104
124
|
UpdateUserSchema,
|
|
105
125
|
UploadFileSchema,
|
|
106
|
-
UserSchema
|
|
126
|
+
UserSchema,
|
|
127
|
+
extractTemplateVariables,
|
|
128
|
+
inspectUserAgent,
|
|
129
|
+
redactFields
|
|
107
130
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zucker-framework/fe-types",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"THIRD_PARTY_NOTICES"
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"zod": "^4.5.4"
|
|
27
|
+
"zod": "^4.5.4",
|
|
28
|
+
"@zucker-framework/core": "1.0.5"
|
|
28
29
|
},
|
|
29
30
|
"license": "Apache-2.0",
|
|
30
31
|
"author": "Lind",
|