@quantabit/level-sdk 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 QuantaBit Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,178 @@
1
+ # @quantabit/level-sdk
2
+
3
+ > QuantaBit Level System SDK - User levels, experience points, and privilege management
4
+
5
+ ## 📦 Installation
6
+
7
+ ```bash
8
+ npm install @quantabit/level-sdk
9
+ # or
10
+ yarn add @quantabit/level-sdk
11
+ ```
12
+
13
+ ## 🚀 Quick Start
14
+
15
+ ### 1. Setup Provider
16
+
17
+ ```jsx
18
+ import { LevelProvider } from "@quantabit/level-sdk";
19
+ import "@quantabit/level-sdk/styles.css";
20
+
21
+ function App() {
22
+ return (
23
+ <LevelProvider
24
+ apiUrl="https://api.example.com/v1"
25
+ token="your-auth-token"
26
+ language="en"
27
+ onLevelUp={(level) => console.log("Leveled up to:", level)}
28
+ >
29
+ <YourComponent />
30
+ </LevelProvider>
31
+ );
32
+ }
33
+ ```
34
+
35
+ ### 2. Using Components
36
+
37
+ ```jsx
38
+ import {
39
+ LevelBadge,
40
+ LevelProgress,
41
+ LevelCard,
42
+ Leaderboard,
43
+ PrivilegeList
44
+ } from '@quantabit/level-sdk';
45
+
46
+ // Level badge
47
+ <LevelBadge level={5} size="medium" showLabel />
48
+
49
+ // Level progress bar
50
+ <LevelProgress showExp showNextLevel animated />
51
+
52
+ // Level info card
53
+ <LevelCard showPrivileges showProgress />
54
+
55
+ // Leaderboard
56
+ <Leaderboard type="exp" limit={20} showCurrentUser />
57
+
58
+ // Privilege list
59
+ <PrivilegeList showUnlocked showLocked grouped />
60
+ ```
61
+
62
+ ### 3. Using Hooks
63
+
64
+ ```jsx
65
+ import { useLevel, useExpHistory, useLeaderboard } from "@quantabit/level-sdk";
66
+
67
+ function MyComponent() {
68
+ const {
69
+ userLevel, // User level info
70
+ privileges, // Privilege list
71
+ loading,
72
+ loadUserLevel, // Load user level
73
+ addExp, // Add experience
74
+ } = useLevel();
75
+
76
+ // Experience history
77
+ const { history, loadHistory } = useExpHistory();
78
+
79
+ // Leaderboard
80
+ const { leaderboard, myRank, loadLeaderboard } = useLeaderboard("exp");
81
+
82
+ return <div>...</div>;
83
+ }
84
+ ```
85
+
86
+ ## 📚 Components
87
+
88
+ | Component | Description |
89
+ | --------------- | ---------------------------------------------------------- |
90
+ | `LevelBadge` | Level badge showing level icon and name |
91
+ | `LevelProgress` | Level progress bar showing current XP and upgrade progress |
92
+ | `LevelCard` | Level info card showing level, progress, privileges |
93
+ | `Leaderboard` | Level/experience leaderboard |
94
+ | `PrivilegeList` | Level privileges list |
95
+
96
+ ## 🪝 Hooks
97
+
98
+ | Hook | Description |
99
+ | ---------------- | ----------------------------- |
100
+ | `useLevel` | Get Level Context |
101
+ | `useExpHistory` | Experience history management |
102
+ | `useLeaderboard` | Leaderboard data management |
103
+
104
+ ## ⚙️ LevelProvider Configuration
105
+
106
+ | Prop | Type | Required | Description |
107
+ | ----------- | ----------------- | -------- | ------------------------------ |
108
+ | `apiUrl` | `string` | Yes | API base URL |
109
+ | `token` | `string` | No | Auth Token |
110
+ | `language` | `'zh' \| 'en'` | No | Language setting, default `zh` |
111
+ | `onLevelUp` | `(level) => void` | No | Level up callback |
112
+ | `onError` | `(error) => void` | No | Error callback |
113
+
114
+ ## 📖 API Types
115
+
116
+ ```typescript
117
+ // Level info
118
+ interface UserLevel {
119
+ level: number;
120
+ level_name: string;
121
+ current_exp: number;
122
+ next_level_exp: number;
123
+ total_exp: number;
124
+ progress: number;
125
+ icon?: string;
126
+ badge_url?: string;
127
+ }
128
+
129
+ // Privilege type
130
+ interface Privilege {
131
+ id: string;
132
+ type: "discount" | "feature" | "badge" | "limit" | "priority" | "gift";
133
+ name: string;
134
+ description: string;
135
+ required_level: number;
136
+ is_unlocked: boolean;
137
+ icon?: string;
138
+ }
139
+
140
+ // Experience sources
141
+ type ExpSource =
142
+ | "daily_login" // Daily login
143
+ | "task_complete" // Task completion
144
+ | "content_create" // Content creation
145
+ | "interaction" // Interaction
146
+ | "purchase" // Purchase
147
+ | "referral" // Referral
148
+ | "achievement" // Achievement
149
+ | "admin_grant"; // Admin grant
150
+ ```
151
+
152
+ ## 🎨 Custom Styling
153
+
154
+ Use CSS variables for custom theming:
155
+
156
+ ```css
157
+ :root {
158
+ --level-primary: #10b981;
159
+ --level-gold: #fbbf24;
160
+ --level-silver: #9ca3af;
161
+ --level-bronze: #d97706;
162
+ }
163
+ ```
164
+
165
+ ## 📄 License
166
+
167
+ MIT License
168
+
169
+
170
+
171
+ ---
172
+
173
+ ## 🌐 Brand & Links
174
+ - Official Mainnet: [QuantaBit Chain](https://qbitchain.io/)
175
+ - Developer Platform: [Developer Platform](https://developer.quantabit.io/)
176
+ - Open Platform: [Open Platform](https://open.quantabit.io/)
177
+ - Payment Platform: [Pay Platform](https://pay.qbitwallet.io/)
178
+ - Feedback: [Feedback](https://xwin.live/qbit)