@windrun-huaiin/third-ui 7.1.1 → 7.2.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.
Files changed (80) hide show
  1. package/dist/clerk/clerk-page-generator-client.d.ts +10 -0
  2. package/dist/clerk/clerk-page-generator-client.js +28 -0
  3. package/dist/clerk/clerk-page-generator-client.mjs +25 -0
  4. package/dist/clerk/clerk-page-generator.js +1 -0
  5. package/dist/clerk/clerk-page-generator.mjs +1 -0
  6. package/dist/clerk/client-page-generator.d.ts +10 -0
  7. package/dist/clerk/client-page-generator.js +28 -0
  8. package/dist/clerk/client-page-generator.mjs +25 -0
  9. package/dist/clerk/context/FingerprintProvider.d.ts +25 -0
  10. package/dist/clerk/context/FingerprintProvider.js +71 -0
  11. package/dist/clerk/context/FingerprintProvider.mjs +65 -0
  12. package/dist/clerk/fingerprint/fingerprint-client.d.ts +47 -0
  13. package/dist/clerk/fingerprint/fingerprint-client.js +183 -0
  14. package/dist/clerk/fingerprint/fingerprint-client.mjs +174 -0
  15. package/dist/clerk/fingerprint/fingerprint-provider.d.ts +25 -0
  16. package/dist/clerk/fingerprint/fingerprint-provider.js +71 -0
  17. package/dist/clerk/fingerprint/fingerprint-provider.mjs +65 -0
  18. package/dist/clerk/fingerprint/fingerprint-server.d.ts +22 -0
  19. package/dist/clerk/fingerprint/fingerprint-server.js +75 -0
  20. package/dist/clerk/fingerprint/fingerprint-server.mjs +71 -0
  21. package/dist/clerk/fingerprint/fingerprint-shared.d.ts +17 -0
  22. package/dist/clerk/fingerprint/fingerprint-shared.js +35 -0
  23. package/dist/clerk/fingerprint/fingerprint-shared.mjs +29 -0
  24. package/dist/clerk/fingerprint/fingerprint.d.ts +55 -0
  25. package/dist/clerk/fingerprint/fingerprint.js +17 -0
  26. package/dist/clerk/fingerprint/fingerprint.mjs +15 -0
  27. package/dist/clerk/fingerprint/index.d.ts +5 -0
  28. package/dist/clerk/fingerprint/index.js +29 -0
  29. package/dist/clerk/fingerprint/index.mjs +5 -0
  30. package/dist/clerk/fingerprint/server.d.ts +3 -0
  31. package/dist/clerk/fingerprint/server.js +15 -0
  32. package/dist/clerk/fingerprint/server.mjs +2 -0
  33. package/dist/clerk/fingerprint/types.d.ts +42 -0
  34. package/dist/clerk/fingerprint/use-fingerprint.d.ts +6 -0
  35. package/dist/clerk/fingerprint/use-fingerprint.js +182 -0
  36. package/dist/clerk/fingerprint/use-fingerprint.mjs +180 -0
  37. package/dist/clerk/fingerprint.d.ts +55 -0
  38. package/dist/clerk/fingerprint.js +237 -0
  39. package/dist/clerk/fingerprint.mjs +225 -0
  40. package/dist/clerk/hooks/useFingerprint.d.ts +6 -0
  41. package/dist/clerk/hooks/useFingerprint.js +182 -0
  42. package/dist/clerk/hooks/useFingerprint.mjs +180 -0
  43. package/dist/clerk/index.d.ts +3 -0
  44. package/dist/clerk/index.js +7 -0
  45. package/dist/clerk/index.mjs +3 -0
  46. package/dist/clerk/signin-with-fingerprint-client.d.ts +7 -0
  47. package/dist/clerk/signin-with-fingerprint-client.js +52 -0
  48. package/dist/clerk/signin-with-fingerprint-client.mjs +47 -0
  49. package/dist/clerk/signup-with-fingerprint-client.d.ts +7 -0
  50. package/dist/clerk/signup-with-fingerprint-client.js +52 -0
  51. package/dist/clerk/signup-with-fingerprint-client.mjs +47 -0
  52. package/dist/clerk/types.d.ts +42 -0
  53. package/dist/fuma/mdx/mermaid.js +1 -1
  54. package/dist/fuma/mdx/mermaid.mjs +1 -1
  55. package/dist/fuma/mdx/toc-base.js +1 -1
  56. package/dist/fuma/mdx/toc-base.mjs +1 -1
  57. package/dist/node_modules/.pnpm/@fingerprintjs_fingerprintjs@4.6.2/node_modules/@fingerprintjs/fingerprintjs/dist/fp.esm.js +3245 -0
  58. package/dist/node_modules/.pnpm/@fingerprintjs_fingerprintjs@4.6.2/node_modules/@fingerprintjs/fingerprintjs/dist/fp.esm.mjs +3218 -0
  59. package/dist/node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.2/node_modules/tslib/tslib.es6.js +51 -0
  60. package/dist/node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.2/node_modules/tslib/tslib.es6.mjs +50 -1
  61. package/dist/node_modules/.pnpm/cose-base@1.0.3/node_modules/cose-base/cose-base.js +1 -1
  62. package/dist/node_modules/.pnpm/cose-base@2.2.0/node_modules/cose-base/cose-base.js +1 -1
  63. package/dist/node_modules/.pnpm/layout-base@1.0.2/node_modules/layout-base/layout-base.js +1 -1
  64. package/dist/node_modules/.pnpm/layout-base@2.0.1/node_modules/layout-base/layout-base.js +1 -1
  65. package/package.json +14 -3
  66. package/src/clerk/clerk-page-generator-client.tsx +37 -0
  67. package/src/clerk/clerk-page-generator.tsx +5 -1
  68. package/src/clerk/fingerprint/fingerprint-client.ts +202 -0
  69. package/src/clerk/fingerprint/fingerprint-provider.tsx +114 -0
  70. package/src/clerk/fingerprint/fingerprint-server.ts +88 -0
  71. package/src/clerk/fingerprint/fingerprint-shared.ts +29 -0
  72. package/src/clerk/fingerprint/index.ts +15 -0
  73. package/src/clerk/fingerprint/server.ts +9 -0
  74. package/src/clerk/fingerprint/types.ts +48 -0
  75. package/src/clerk/fingerprint/use-fingerprint.ts +208 -0
  76. package/src/clerk/index.ts +9 -2
  77. package/src/clerk/server.ts +1 -0
  78. package/src/clerk/signin-with-fingerprint-client.tsx +57 -0
  79. package/src/clerk/signup-with-fingerprint-client.tsx +57 -0
  80. package/src/fuma/mdx/toc-base.tsx +1 -1
@@ -0,0 +1,174 @@
1
+ import { __awaiter } from '../../node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.2/node_modules/tslib/tslib.es6.mjs';
2
+ import { FINGERPRINT_STORAGE_KEY, isValidFingerprintId, FINGERPRINT_COOKIE_NAME } from './fingerprint-shared.mjs';
3
+
4
+ /**
5
+ * Fingerprint Client Utilities
6
+ * 客户端专用的指纹生成和管理逻辑
7
+ * 只能在浏览器环境中使用
8
+ */
9
+ // Dynamic import to avoid SSR issues
10
+ let FingerprintJS = null;
11
+ /**
12
+ * 生成基于真实浏览器特征的fingerprint ID
13
+ * 使用FingerprintJS收集浏览器特征并生成唯一标识
14
+ * 只能在客户端使用
15
+ */
16
+ function generateFingerprintId() {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ if (typeof window === 'undefined') {
19
+ throw new Error('generateFingerprintId can only be used in browser environment');
20
+ }
21
+ // 首先检查现有ID
22
+ const existingId = getFingerprintId();
23
+ if (existingId && isValidFingerprintId(existingId)) {
24
+ return existingId;
25
+ }
26
+ // 检查cookie
27
+ const cookieId = getCookieValue(FINGERPRINT_COOKIE_NAME);
28
+ if (cookieId && isValidFingerprintId(cookieId)) {
29
+ // 同步到localStorage
30
+ localStorage.setItem(FINGERPRINT_STORAGE_KEY, cookieId);
31
+ return cookieId;
32
+ }
33
+ try {
34
+ // 等待FingerprintJS加载完成
35
+ if (!FingerprintJS) {
36
+ const module = yield import('../../node_modules/.pnpm/@fingerprintjs_fingerprintjs@4.6.2/node_modules/@fingerprintjs/fingerprintjs/dist/fp.esm.mjs');
37
+ FingerprintJS = module.default;
38
+ }
39
+ // 使用FingerprintJS生成基于浏览器特征的指纹
40
+ const fp = yield FingerprintJS.load();
41
+ const result = yield fp.get();
42
+ const fingerprintId = `fp_${result.visitorId}`;
43
+ // 存储到localStorage和cookie
44
+ localStorage.setItem(FINGERPRINT_STORAGE_KEY, fingerprintId);
45
+ setCookie(FINGERPRINT_COOKIE_NAME, fingerprintId, 365); // 365天过期
46
+ return fingerprintId;
47
+ }
48
+ catch (error) {
49
+ console.warn('Failed to generate fingerprint with FingerprintJS:', error);
50
+ // 降级方案:生成时间戳+随机数
51
+ const fallbackId = `fp_fallback_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`;
52
+ localStorage.setItem(FINGERPRINT_STORAGE_KEY, fallbackId);
53
+ setCookie(FINGERPRINT_COOKIE_NAME, fallbackId, 365);
54
+ return fallbackId;
55
+ }
56
+ });
57
+ }
58
+ /**
59
+ * 获取当前的fingerprint ID
60
+ * 只能在客户端使用
61
+ */
62
+ function getFingerprintId() {
63
+ if (typeof window === 'undefined') {
64
+ return null;
65
+ }
66
+ // 首先检查localStorage
67
+ const localStorageId = localStorage.getItem(FINGERPRINT_STORAGE_KEY);
68
+ if (localStorageId) {
69
+ return localStorageId;
70
+ }
71
+ // 检查cookie
72
+ const cookieId = getCookieValue(FINGERPRINT_COOKIE_NAME);
73
+ if (cookieId) {
74
+ // 同步到localStorage
75
+ localStorage.setItem(FINGERPRINT_STORAGE_KEY, cookieId);
76
+ return cookieId;
77
+ }
78
+ return null;
79
+ }
80
+ /**
81
+ * 设置fingerprint ID到存储
82
+ * 只能在客户端使用
83
+ */
84
+ function setFingerprintId(fingerprintId) {
85
+ if (typeof window === 'undefined') {
86
+ throw new Error('setFingerprintId can only be used in browser environment');
87
+ }
88
+ localStorage.setItem(FINGERPRINT_STORAGE_KEY, fingerprintId);
89
+ setCookie(FINGERPRINT_COOKIE_NAME, fingerprintId, 365);
90
+ }
91
+ /**
92
+ * 清除fingerprint ID
93
+ * 只能在客户端使用
94
+ */
95
+ function clearFingerprintId() {
96
+ if (typeof window === 'undefined') {
97
+ throw new Error('clearFingerprintId can only be used in browser environment');
98
+ }
99
+ localStorage.removeItem(FINGERPRINT_STORAGE_KEY);
100
+ deleteCookie(FINGERPRINT_COOKIE_NAME);
101
+ }
102
+ /**
103
+ * 获取或生成fingerprint ID
104
+ * 如果不存在则自动生成新的
105
+ * 只能在客户端使用
106
+ */
107
+ function getOrGenerateFingerprintId() {
108
+ return __awaiter(this, void 0, void 0, function* () {
109
+ const existingId = getFingerprintId();
110
+ if (existingId) {
111
+ return existingId;
112
+ }
113
+ return yield generateFingerprintId();
114
+ });
115
+ }
116
+ /**
117
+ * 创建包含fingerprint ID的fetch headers
118
+ * 只能在客户端使用
119
+ */
120
+ function createFingerprintHeaders() {
121
+ return __awaiter(this, void 0, void 0, function* () {
122
+ const fingerprintId = yield getOrGenerateFingerprintId();
123
+ return {
124
+ 'x-fingerprint-id': fingerprintId,
125
+ };
126
+ });
127
+ }
128
+ /**
129
+ * Hook for generating fingerprint headers
130
+ * 只能在客户端使用
131
+ */
132
+ function useFingerprintHeaders() {
133
+ return createFingerprintHeaders;
134
+ }
135
+ /**
136
+ * Create a fetch wrapper that automatically includes fingerprint headers
137
+ * 只能在客户端使用
138
+ */
139
+ function createFingerprintFetch() {
140
+ return (url, init) => __awaiter(this, void 0, void 0, function* () {
141
+ const fingerprintHeaders = yield createFingerprintHeaders();
142
+ const headers = Object.assign(Object.assign({}, fingerprintHeaders), ((init === null || init === void 0 ? void 0 : init.headers) || {}));
143
+ return fetch(url, Object.assign(Object.assign({}, init), { headers }));
144
+ });
145
+ }
146
+ // Cookie 辅助函数 (私有)
147
+ function getCookieValue(name) {
148
+ var _a;
149
+ if (typeof document === 'undefined') {
150
+ return null;
151
+ }
152
+ const value = `; ${document.cookie}`;
153
+ const parts = value.split(`; ${name}=`);
154
+ if (parts.length === 2) {
155
+ return ((_a = parts.pop()) === null || _a === void 0 ? void 0 : _a.split(';').shift()) || null;
156
+ }
157
+ return null;
158
+ }
159
+ function setCookie(name, value, days) {
160
+ if (typeof document === 'undefined') {
161
+ return;
162
+ }
163
+ const expires = new Date();
164
+ expires.setTime(expires.getTime() + days * 24 * 60 * 60 * 1000);
165
+ document.cookie = `${name}=${value};expires=${expires.toUTCString()};path=/;SameSite=Lax`;
166
+ }
167
+ function deleteCookie(name) {
168
+ if (typeof document === 'undefined') {
169
+ return;
170
+ }
171
+ document.cookie = `${name}=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/`;
172
+ }
173
+
174
+ export { clearFingerprintId, createFingerprintFetch, createFingerprintHeaders, generateFingerprintId, getFingerprintId, getOrGenerateFingerprintId, setFingerprintId, useFingerprintHeaders };
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ import type { FingerprintContextType, FingerprintProviderProps } from './types';
3
+ /**
4
+ * Fingerprint Provider Component
5
+ * 为应用提供fingerprint和匿名用户管理功能
6
+ */
7
+ export declare function FingerprintProvider({ children, config }: FingerprintProviderProps): import("react/jsx-runtime").JSX.Element;
8
+ /**
9
+ * Hook to use fingerprint context
10
+ */
11
+ export declare function useFingerprintContext(): FingerprintContextType;
12
+ /**
13
+ * Safe hook to use fingerprint context - returns null if no provider
14
+ * 安全版本的fingerprint context hook - 如果没有Provider则返回null
15
+ */
16
+ export declare function useFingerprintContextSafe(): FingerprintContextType | null;
17
+ /**
18
+ * HOC for components that need fingerprint functionality
19
+ * Note: This HOC now requires config to be passed externally
20
+ */
21
+ export declare function withFingerprint<P extends object>(Component: React.ComponentType<P>, config: FingerprintProviderProps['config']): (props: P) => import("react/jsx-runtime").JSX.Element;
22
+ /**
23
+ * 组件:显示用户状态和积分信息(用于调试)
24
+ */
25
+ export declare function FingerprintDebugInfo(): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,71 @@
1
+ "use client";
2
+ 'use strict';
3
+
4
+ var jsxRuntime = require('react/jsx-runtime');
5
+ var React = require('react');
6
+ var useFingerprint = require('./use-fingerprint.js');
7
+
8
+ const FingerprintContext = React.createContext(undefined);
9
+ /**
10
+ * Fingerprint Provider Component
11
+ * 为应用提供fingerprint和匿名用户管理功能
12
+ */
13
+ function FingerprintProvider({ children, config }) {
14
+ const fingerprintData = useFingerprint.useFingerprint(config);
15
+ return (jsxRuntime.jsx(FingerprintContext.Provider, { value: fingerprintData, children: children }));
16
+ }
17
+ /**
18
+ * Hook to use fingerprint context
19
+ */
20
+ function useFingerprintContext() {
21
+ const context = React.useContext(FingerprintContext);
22
+ if (context === undefined) {
23
+ throw new Error('useFingerprintContext must be used within a FingerprintProvider');
24
+ }
25
+ return context;
26
+ }
27
+ /**
28
+ * Safe hook to use fingerprint context - returns null if no provider
29
+ * 安全版本的fingerprint context hook - 如果没有Provider则返回null
30
+ */
31
+ function useFingerprintContextSafe() {
32
+ const context = React.useContext(FingerprintContext);
33
+ return context || null;
34
+ }
35
+ /**
36
+ * HOC for components that need fingerprint functionality
37
+ * Note: This HOC now requires config to be passed externally
38
+ */
39
+ function withFingerprint(Component, config) {
40
+ return function FingerprintWrappedComponent(props) {
41
+ return (jsxRuntime.jsx(FingerprintProvider, { config: config, children: jsxRuntime.jsx(Component, Object.assign({}, props)) }));
42
+ };
43
+ }
44
+ /**
45
+ * 组件:显示用户状态和积分信息(用于调试)
46
+ */
47
+ function FingerprintDebugInfo() {
48
+ const { fingerprintId, anonymousUser, credits, isLoading, isInitialized, error } = useFingerprintContext();
49
+ if (!process.env.NODE_ENV || process.env.NODE_ENV === 'production') {
50
+ return null;
51
+ }
52
+ return (jsxRuntime.jsxs("div", { style: {
53
+ position: 'fixed',
54
+ bottom: '10px',
55
+ right: '10px',
56
+ background: '#f0f0f0',
57
+ padding: '10px',
58
+ borderRadius: '5px',
59
+ fontSize: '12px',
60
+ fontFamily: 'monospace',
61
+ maxWidth: '300px',
62
+ zIndex: 9999,
63
+ border: '1px solid #ccc'
64
+ }, children: [jsxRuntime.jsx("h4", { style: { margin: '0 0 5px 0' }, children: "Fingerprint Debug" }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("strong", { children: "FP ID:" }), " ", fingerprintId || 'None'] }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("strong", { children: "Loading:" }), " ", isLoading ? 'Yes' : 'No'] }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("strong", { children: "Initialized:" }), " ", isInitialized ? 'Yes' : 'No'] }), error && jsxRuntime.jsxs("div", { style: { color: 'red' }, children: [jsxRuntime.jsx("strong", { children: "Error:" }), " ", error] }), anonymousUser && (jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("strong", { children: "User ID:" }), " ", anonymousUser.userId.slice(0, 8), "..."] })), credits && (jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("strong", { children: "Credits:" }), " ", credits.balanceFree, "F + ", credits.balancePaid, "P = ", credits.totalBalance] }))] }));
65
+ }
66
+
67
+ exports.FingerprintDebugInfo = FingerprintDebugInfo;
68
+ exports.FingerprintProvider = FingerprintProvider;
69
+ exports.useFingerprintContext = useFingerprintContext;
70
+ exports.useFingerprintContextSafe = useFingerprintContextSafe;
71
+ exports.withFingerprint = withFingerprint;
@@ -0,0 +1,65 @@
1
+ "use client";
2
+ import { jsx, jsxs } from 'react/jsx-runtime';
3
+ import { createContext, useContext } from 'react';
4
+ import { useFingerprint } from './use-fingerprint.mjs';
5
+
6
+ const FingerprintContext = createContext(undefined);
7
+ /**
8
+ * Fingerprint Provider Component
9
+ * 为应用提供fingerprint和匿名用户管理功能
10
+ */
11
+ function FingerprintProvider({ children, config }) {
12
+ const fingerprintData = useFingerprint(config);
13
+ return (jsx(FingerprintContext.Provider, { value: fingerprintData, children: children }));
14
+ }
15
+ /**
16
+ * Hook to use fingerprint context
17
+ */
18
+ function useFingerprintContext() {
19
+ const context = useContext(FingerprintContext);
20
+ if (context === undefined) {
21
+ throw new Error('useFingerprintContext must be used within a FingerprintProvider');
22
+ }
23
+ return context;
24
+ }
25
+ /**
26
+ * Safe hook to use fingerprint context - returns null if no provider
27
+ * 安全版本的fingerprint context hook - 如果没有Provider则返回null
28
+ */
29
+ function useFingerprintContextSafe() {
30
+ const context = useContext(FingerprintContext);
31
+ return context || null;
32
+ }
33
+ /**
34
+ * HOC for components that need fingerprint functionality
35
+ * Note: This HOC now requires config to be passed externally
36
+ */
37
+ function withFingerprint(Component, config) {
38
+ return function FingerprintWrappedComponent(props) {
39
+ return (jsx(FingerprintProvider, { config: config, children: jsx(Component, Object.assign({}, props)) }));
40
+ };
41
+ }
42
+ /**
43
+ * 组件:显示用户状态和积分信息(用于调试)
44
+ */
45
+ function FingerprintDebugInfo() {
46
+ const { fingerprintId, anonymousUser, credits, isLoading, isInitialized, error } = useFingerprintContext();
47
+ if (!process.env.NODE_ENV || process.env.NODE_ENV === 'production') {
48
+ return null;
49
+ }
50
+ return (jsxs("div", { style: {
51
+ position: 'fixed',
52
+ bottom: '10px',
53
+ right: '10px',
54
+ background: '#f0f0f0',
55
+ padding: '10px',
56
+ borderRadius: '5px',
57
+ fontSize: '12px',
58
+ fontFamily: 'monospace',
59
+ maxWidth: '300px',
60
+ zIndex: 9999,
61
+ border: '1px solid #ccc'
62
+ }, children: [jsx("h4", { style: { margin: '0 0 5px 0' }, children: "Fingerprint Debug" }), jsxs("div", { children: [jsx("strong", { children: "FP ID:" }), " ", fingerprintId || 'None'] }), jsxs("div", { children: [jsx("strong", { children: "Loading:" }), " ", isLoading ? 'Yes' : 'No'] }), jsxs("div", { children: [jsx("strong", { children: "Initialized:" }), " ", isInitialized ? 'Yes' : 'No'] }), error && jsxs("div", { style: { color: 'red' }, children: [jsx("strong", { children: "Error:" }), " ", error] }), anonymousUser && (jsxs("div", { children: [jsx("strong", { children: "User ID:" }), " ", anonymousUser.userId.slice(0, 8), "..."] })), credits && (jsxs("div", { children: [jsx("strong", { children: "Credits:" }), " ", credits.balanceFree, "F + ", credits.balancePaid, "P = ", credits.totalBalance] }))] }));
63
+ }
64
+
65
+ export { FingerprintDebugInfo, FingerprintProvider, useFingerprintContext, useFingerprintContextSafe, withFingerprint };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Fingerprint Server Utilities
3
+ * 服务端专用的指纹ID提取和验证逻辑
4
+ * 可以安全地在服务端使用,不依赖浏览器API或FingerprintJS
5
+ */
6
+ /**
7
+ * 从请求中提取fingerprint ID
8
+ * 优先级:header > cookie > query参数
9
+ * 可以安全地在服务端使用
10
+ */
11
+ export declare function extractFingerprintId(headers: Headers | Record<string, string>, cookies?: Record<string, string>, query?: Record<string, string | undefined>): string | null;
12
+ /**
13
+ * 生成服务端降级fingerprint ID
14
+ * 当客户端无法生成fingerprint时使用
15
+ * 可以安全地在服务端使用
16
+ */
17
+ export declare function generateServerFingerprintId(): string;
18
+ /**
19
+ * 从Next.js Request对象中提取fingerprint ID
20
+ * 便捷方法,适用于Next.js API路由
21
+ */
22
+ export declare function extractFingerprintFromNextRequest(request: Request): string | null;
@@ -0,0 +1,75 @@
1
+ 'use strict';
2
+
3
+ var fingerprintShared = require('./fingerprint-shared.js');
4
+
5
+ /**
6
+ * Fingerprint Server Utilities
7
+ * 服务端专用的指纹ID提取和验证逻辑
8
+ * 可以安全地在服务端使用,不依赖浏览器API或FingerprintJS
9
+ */
10
+ /**
11
+ * 从请求中提取fingerprint ID
12
+ * 优先级:header > cookie > query参数
13
+ * 可以安全地在服务端使用
14
+ */
15
+ function extractFingerprintId(headers, cookies, query) {
16
+ // 1. 从header中获取
17
+ const headerValue = headers instanceof Headers
18
+ ? headers.get(fingerprintShared.FINGERPRINT_HEADER_NAME)
19
+ : headers[fingerprintShared.FINGERPRINT_HEADER_NAME];
20
+ if (headerValue && fingerprintShared.isValidFingerprintId(headerValue)) {
21
+ return headerValue;
22
+ }
23
+ // 2. 从cookie中获取
24
+ if (cookies) {
25
+ const cookieValue = cookies[fingerprintShared.FINGERPRINT_COOKIE_NAME];
26
+ if (cookieValue && fingerprintShared.isValidFingerprintId(cookieValue)) {
27
+ return cookieValue;
28
+ }
29
+ }
30
+ // 3. 从query参数中获取
31
+ if (query) {
32
+ const queryValue = query.fingerprint_id || query.fp_id;
33
+ if (queryValue && fingerprintShared.isValidFingerprintId(queryValue)) {
34
+ return queryValue;
35
+ }
36
+ }
37
+ return null;
38
+ }
39
+ /**
40
+ * 生成服务端降级fingerprint ID
41
+ * 当客户端无法生成fingerprint时使用
42
+ * 可以安全地在服务端使用
43
+ */
44
+ function generateServerFingerprintId() {
45
+ return `fp_server_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`;
46
+ }
47
+ /**
48
+ * 从Next.js Request对象中提取fingerprint ID
49
+ * 便捷方法,适用于Next.js API路由
50
+ */
51
+ function extractFingerprintFromNextRequest(request) {
52
+ const headers = request.headers;
53
+ // 尝试从cookies获取(需要解析cookie header)
54
+ const cookieHeader = headers.get('cookie');
55
+ const cookies = {};
56
+ if (cookieHeader) {
57
+ cookieHeader.split(';').forEach(cookie => {
58
+ const [name, value] = cookie.trim().split('=');
59
+ if (name && value) {
60
+ cookies[name] = value;
61
+ }
62
+ });
63
+ }
64
+ // 尝试从URL query参数获取
65
+ const url = new URL(request.url);
66
+ const query = {};
67
+ url.searchParams.forEach((value, key) => {
68
+ query[key] = value;
69
+ });
70
+ return extractFingerprintId(headers, cookies, query);
71
+ }
72
+
73
+ exports.extractFingerprintFromNextRequest = extractFingerprintFromNextRequest;
74
+ exports.extractFingerprintId = extractFingerprintId;
75
+ exports.generateServerFingerprintId = generateServerFingerprintId;
@@ -0,0 +1,71 @@
1
+ import { FINGERPRINT_HEADER_NAME, isValidFingerprintId, FINGERPRINT_COOKIE_NAME } from './fingerprint-shared.mjs';
2
+
3
+ /**
4
+ * Fingerprint Server Utilities
5
+ * 服务端专用的指纹ID提取和验证逻辑
6
+ * 可以安全地在服务端使用,不依赖浏览器API或FingerprintJS
7
+ */
8
+ /**
9
+ * 从请求中提取fingerprint ID
10
+ * 优先级:header > cookie > query参数
11
+ * 可以安全地在服务端使用
12
+ */
13
+ function extractFingerprintId(headers, cookies, query) {
14
+ // 1. 从header中获取
15
+ const headerValue = headers instanceof Headers
16
+ ? headers.get(FINGERPRINT_HEADER_NAME)
17
+ : headers[FINGERPRINT_HEADER_NAME];
18
+ if (headerValue && isValidFingerprintId(headerValue)) {
19
+ return headerValue;
20
+ }
21
+ // 2. 从cookie中获取
22
+ if (cookies) {
23
+ const cookieValue = cookies[FINGERPRINT_COOKIE_NAME];
24
+ if (cookieValue && isValidFingerprintId(cookieValue)) {
25
+ return cookieValue;
26
+ }
27
+ }
28
+ // 3. 从query参数中获取
29
+ if (query) {
30
+ const queryValue = query.fingerprint_id || query.fp_id;
31
+ if (queryValue && isValidFingerprintId(queryValue)) {
32
+ return queryValue;
33
+ }
34
+ }
35
+ return null;
36
+ }
37
+ /**
38
+ * 生成服务端降级fingerprint ID
39
+ * 当客户端无法生成fingerprint时使用
40
+ * 可以安全地在服务端使用
41
+ */
42
+ function generateServerFingerprintId() {
43
+ return `fp_server_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`;
44
+ }
45
+ /**
46
+ * 从Next.js Request对象中提取fingerprint ID
47
+ * 便捷方法,适用于Next.js API路由
48
+ */
49
+ function extractFingerprintFromNextRequest(request) {
50
+ const headers = request.headers;
51
+ // 尝试从cookies获取(需要解析cookie header)
52
+ const cookieHeader = headers.get('cookie');
53
+ const cookies = {};
54
+ if (cookieHeader) {
55
+ cookieHeader.split(';').forEach(cookie => {
56
+ const [name, value] = cookie.trim().split('=');
57
+ if (name && value) {
58
+ cookies[name] = value;
59
+ }
60
+ });
61
+ }
62
+ // 尝试从URL query参数获取
63
+ const url = new URL(request.url);
64
+ const query = {};
65
+ url.searchParams.forEach((value, key) => {
66
+ query[key] = value;
67
+ });
68
+ return extractFingerprintId(headers, cookies, query);
69
+ }
70
+
71
+ export { extractFingerprintFromNextRequest, extractFingerprintId, generateServerFingerprintId };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Fingerprint Shared Utilities
3
+ * 客户端和服务端共享的常量、类型和验证逻辑
4
+ */
5
+ export declare const FINGERPRINT_STORAGE_KEY = "diaomao_fingerprint_id";
6
+ export declare const FINGERPRINT_HEADER_NAME = "x-fingerprint-id";
7
+ export declare const FINGERPRINT_COOKIE_NAME = "fingerprint_id";
8
+ /**
9
+ * 验证fingerprint ID格式
10
+ * 可以在客户端和服务端使用
11
+ */
12
+ export declare function isValidFingerprintId(fingerprintId: string): boolean;
13
+ export declare const FINGERPRINT_CONSTANTS: {
14
+ readonly STORAGE_KEY: "diaomao_fingerprint_id";
15
+ readonly HEADER_NAME: "x-fingerprint-id";
16
+ readonly COOKIE_NAME: "fingerprint_id";
17
+ };
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Fingerprint Shared Utilities
5
+ * 客户端和服务端共享的常量、类型和验证逻辑
6
+ */
7
+ // Fingerprint ID的存储键和header名
8
+ const FINGERPRINT_STORAGE_KEY = 'diaomao_fingerprint_id';
9
+ const FINGERPRINT_HEADER_NAME = 'x-fingerprint-id';
10
+ const FINGERPRINT_COOKIE_NAME = 'fingerprint_id';
11
+ /**
12
+ * 验证fingerprint ID格式
13
+ * 可以在客户端和服务端使用
14
+ */
15
+ function isValidFingerprintId(fingerprintId) {
16
+ if (!fingerprintId)
17
+ return false;
18
+ // 支持多种格式:
19
+ // - fp_ + FingerprintJS visitorId (变长字符串)
20
+ // - fp_fallback_ + 时间戳_随机字符串 (客户端降级方案)
21
+ // - fp_server_ + 时间戳_随机字符串 (服务端降级)
22
+ return /^fp(_fallback|_server)?_[a-zA-Z0-9_]+$/.test(fingerprintId);
23
+ }
24
+ // 常量导出
25
+ const FINGERPRINT_CONSTANTS = {
26
+ STORAGE_KEY: FINGERPRINT_STORAGE_KEY,
27
+ HEADER_NAME: FINGERPRINT_HEADER_NAME,
28
+ COOKIE_NAME: FINGERPRINT_COOKIE_NAME,
29
+ };
30
+
31
+ exports.FINGERPRINT_CONSTANTS = FINGERPRINT_CONSTANTS;
32
+ exports.FINGERPRINT_COOKIE_NAME = FINGERPRINT_COOKIE_NAME;
33
+ exports.FINGERPRINT_HEADER_NAME = FINGERPRINT_HEADER_NAME;
34
+ exports.FINGERPRINT_STORAGE_KEY = FINGERPRINT_STORAGE_KEY;
35
+ exports.isValidFingerprintId = isValidFingerprintId;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Fingerprint Shared Utilities
3
+ * 客户端和服务端共享的常量、类型和验证逻辑
4
+ */
5
+ // Fingerprint ID的存储键和header名
6
+ const FINGERPRINT_STORAGE_KEY = 'diaomao_fingerprint_id';
7
+ const FINGERPRINT_HEADER_NAME = 'x-fingerprint-id';
8
+ const FINGERPRINT_COOKIE_NAME = 'fingerprint_id';
9
+ /**
10
+ * 验证fingerprint ID格式
11
+ * 可以在客户端和服务端使用
12
+ */
13
+ function isValidFingerprintId(fingerprintId) {
14
+ if (!fingerprintId)
15
+ return false;
16
+ // 支持多种格式:
17
+ // - fp_ + FingerprintJS visitorId (变长字符串)
18
+ // - fp_fallback_ + 时间戳_随机字符串 (客户端降级方案)
19
+ // - fp_server_ + 时间戳_随机字符串 (服务端降级)
20
+ return /^fp(_fallback|_server)?_[a-zA-Z0-9_]+$/.test(fingerprintId);
21
+ }
22
+ // 常量导出
23
+ const FINGERPRINT_CONSTANTS = {
24
+ STORAGE_KEY: FINGERPRINT_STORAGE_KEY,
25
+ HEADER_NAME: FINGERPRINT_HEADER_NAME,
26
+ COOKIE_NAME: FINGERPRINT_COOKIE_NAME,
27
+ };
28
+
29
+ export { FINGERPRINT_CONSTANTS, FINGERPRINT_COOKIE_NAME, FINGERPRINT_HEADER_NAME, FINGERPRINT_STORAGE_KEY, isValidFingerprintId };
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Fingerprint Core Utilities
3
+ * 基于浏览器特征生成唯一的设备指纹ID,用于匿名用户识别
4
+ * Core fingerprint generation logic - completely generic
5
+ *
6
+ * NOTE: This module should only be used on the client-side
7
+ */
8
+ /**
9
+ * 生成基于真实浏览器特征的fingerprint ID
10
+ * 使用FingerprintJS收集浏览器特征并生成唯一标识
11
+ */
12
+ export declare function generateFingerprintId(): Promise<string>;
13
+ /**
14
+ * 获取当前的fingerprint ID
15
+ */
16
+ export declare function getFingerprintId(): string | null;
17
+ /**
18
+ * 设置fingerprint ID到存储
19
+ */
20
+ export declare function setFingerprintId(fingerprintId: string): void;
21
+ /**
22
+ * 清除fingerprint ID
23
+ */
24
+ export declare function clearFingerprintId(): void;
25
+ /**
26
+ * 获取或生成fingerprint ID
27
+ * 如果不存在则自动生成新的
28
+ */
29
+ export declare function getOrGenerateFingerprintId(): Promise<string>;
30
+ /**
31
+ * 验证fingerprint ID格式
32
+ */
33
+ export declare function isValidFingerprintId(fingerprintId: string): boolean;
34
+ /**
35
+ * 创建包含fingerprint ID的fetch headers
36
+ */
37
+ export declare function createFingerprintHeaders(): Promise<Record<string, string>>;
38
+ /**
39
+ * Hook for generating fingerprint headers
40
+ */
41
+ export declare function useFingerprintHeaders(): () => Promise<Record<string, string>>;
42
+ /**
43
+ * Create a fetch wrapper that automatically includes fingerprint headers
44
+ */
45
+ export declare function createFingerprintFetch(): (url: string | URL | Request, init?: RequestInit) => Promise<Response>;
46
+ /**
47
+ * 从请求中提取fingerprint ID
48
+ * 优先级:header > cookie > query参数
49
+ */
50
+ export declare function extractFingerprintId(headers: Headers | Record<string, string>, cookies?: Record<string, string>, query?: Record<string, string | undefined>): string | null;
51
+ export declare const FINGERPRINT_CONSTANTS: {
52
+ readonly STORAGE_KEY: "diaomao_fingerprint_id";
53
+ readonly HEADER_NAME: "x-fingerprint-id";
54
+ readonly COOKIE_NAME: "fingerprint_id";
55
+ };
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ require('../../node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.2/node_modules/tslib/tslib.es6.js');
4
+
5
+ /**
6
+ * Fingerprint Core Utilities
7
+ * 基于浏览器特征生成唯一的设备指纹ID,用于匿名用户识别
8
+ * Core fingerprint generation logic - completely generic
9
+ *
10
+ * NOTE: This module should only be used on the client-side
11
+ */
12
+ // Only import in browser environment
13
+ if (typeof window !== 'undefined') {
14
+ Promise.resolve().then(function () { return require('../../node_modules/.pnpm/@fingerprintjs_fingerprintjs@4.6.2/node_modules/@fingerprintjs/fingerprintjs/dist/fp.esm.js'); }).then((module) => {
15
+ module.default;
16
+ });
17
+ }