react-achievements 4.4.1 → 5.0.1
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 +5 -73
- package/README.md +51 -44
- package/dist/headless.cjs +300 -12
- package/dist/headless.cjs.map +1 -1
- package/dist/headless.d.ts +109 -17
- package/dist/headless.esm.js +299 -13
- package/dist/headless.esm.js.map +1 -1
- package/dist/index.cjs +348 -65
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +109 -17
- package/dist/index.esm.js +347 -66
- package/dist/index.esm.js.map +1 -1
- package/dist/web.cjs +348 -65
- package/dist/web.cjs.map +1 -1
- package/dist/web.d.ts +109 -17
- package/dist/web.esm.js +347 -66
- package/dist/web.esm.js.map +1 -1
- package/package.json +4 -4
package/LICENSE
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
React Achievements is dual-licensed under the MIT License for non-commercial use and a Commercial License for commercial use.
|
|
4
|
-
|
|
5
|
-
## MIT License (Non-Commercial Use)
|
|
1
|
+
MIT License
|
|
6
2
|
|
|
7
3
|
Copyright (c) 2025 Dave B
|
|
8
4
|
|
|
9
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
-
in the Software without restriction
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
the following conditions:
|
|
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:
|
|
16
11
|
|
|
17
12
|
The above copyright notice and this permission notice shall be included in all
|
|
18
13
|
copies or substantial portions of the Software.
|
|
@@ -24,66 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
24
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
21
|
SOFTWARE.
|
|
27
|
-
|
|
28
|
-
### Non-Commercial Use Includes:
|
|
29
|
-
|
|
30
|
-
- Personal projects (no revenue generation)
|
|
31
|
-
- Educational and academic institutions
|
|
32
|
-
- Non-profit organizations with 501(c)(3) or equivalent status
|
|
33
|
-
- Open source projects (with OSI-approved license)
|
|
34
|
-
- Evaluation, development, and testing purposes
|
|
35
|
-
- Government agencies and public sector organizations
|
|
36
|
-
|
|
37
|
-
---
|
|
38
|
-
|
|
39
|
-
## Commercial License
|
|
40
|
-
|
|
41
|
-
**Commercial use requires a paid license via GitHub Sponsors.**
|
|
42
|
-
|
|
43
|
-
### What Constitutes Commercial Use:
|
|
44
|
-
|
|
45
|
-
Commercial use includes, but is not limited to:
|
|
46
|
-
|
|
47
|
-
- Companies or organizations using this library in products/services that generate revenue
|
|
48
|
-
- SaaS (Software as a Service) applications
|
|
49
|
-
- Commercial websites, web applications, or mobile apps
|
|
50
|
-
- Enterprise software or internal business applications
|
|
51
|
-
- Freelancers or contractors building paid projects for clients
|
|
52
|
-
- Any use where the library contributes to revenue-generating activities
|
|
53
|
-
|
|
54
|
-
### How to Obtain a Commercial License:
|
|
55
|
-
|
|
56
|
-
Visit our **[GitHub Sponsors page](https://github.com/sponsors/dave-b-b)** to select a tier that matches your organization's size and revenue.
|
|
57
|
-
|
|
58
|
-
**Pricing Tiers:**
|
|
59
|
-
|
|
60
|
-
- **Indie Developer** ($19/month): For small businesses, freelancers, and startups with annual revenue < $100,000
|
|
61
|
-
- **Professional** ($49/month): For growing companies with annual revenue < $1,000,000, includes priority support
|
|
62
|
-
- **Enterprise** ($199/month): For large companies with unlimited revenue, includes private support channel and feature requests
|
|
63
|
-
|
|
64
|
-
For custom licensing arrangements or questions, please contact: dave.b.business@gmail.com
|
|
65
|
-
|
|
66
|
-
See [COMMERCIAL-LICENSE.md](./COMMERCIAL-LICENSE.md) for detailed commercial licensing terms.
|
|
67
|
-
|
|
68
|
-
---
|
|
69
|
-
|
|
70
|
-
## Frequently Asked Questions
|
|
71
|
-
|
|
72
|
-
**Q: I'm a freelancer building a website for a client. Do I need a commercial license?**
|
|
73
|
-
A: Yes, if the client is paying you or if the website generates revenue, you need a commercial license.
|
|
74
|
-
|
|
75
|
-
**Q: I'm using this in an open-source project. Do I need a commercial license?**
|
|
76
|
-
A: No, open-source projects with an OSI-approved license can use the MIT license.
|
|
77
|
-
|
|
78
|
-
**Q: Can I try the library before committing to a commercial license?**
|
|
79
|
-
A: Yes, evaluation and testing fall under non-commercial use.
|
|
80
|
-
|
|
81
|
-
**Q: What if my startup grows and exceeds the Indie Developer tier revenue?**
|
|
82
|
-
A: Please upgrade to the appropriate tier when your revenue grows. We operate on an honor system and trust our users.
|
|
83
|
-
|
|
84
|
-
**Q: Do non-profits need a commercial license?**
|
|
85
|
-
A: No, registered non-profit organizations (501(c)(3) or equivalent) can use the MIT license for free.
|
|
86
|
-
|
|
87
|
-
---
|
|
88
|
-
|
|
89
|
-
For questions about licensing, please email dave.b.business@gmail.com or open a discussion on GitHub.
|
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# React Achievements
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**Display server-backed achievements in React** - fetch achievement state from your app server, track progress through REST calls, show badges, and celebrate unlocks.
|
|
4
4
|
|
|
5
5
|
[📚 Documentation](https://dave-b-b.github.io/react-achievements/) | [📦 npm Package](https://www.npmjs.com/package/react-achievements)
|
|
6
6
|
|
|
7
|
-
[](https://www.npmjs.com/package/react-achievements) [](https://www.npmjs.com/package/react-achievements) [](./LICENSE) [](https://www.typescriptlang.org/)
|
|
8
8
|
|
|
9
9
|
<p align="center">
|
|
10
10
|
<img
|
|
@@ -22,34 +22,38 @@ npm install react-achievements
|
|
|
22
22
|
|
|
23
23
|
**Requirements:** React 16.8+, Node.js 16+
|
|
24
24
|
|
|
25
|
+
If you want the official JavaScript backend engine, install `achievements-engine` in your server package. React Achievements can also display achievement data from Rails Merit or any backend that implements the same REST contract.
|
|
26
|
+
|
|
25
27
|
## Start Here
|
|
26
28
|
|
|
27
29
|
```tsx
|
|
28
30
|
import {
|
|
29
31
|
AchievementProvider,
|
|
30
32
|
AchievementsWidget,
|
|
33
|
+
createRestAchievementClient,
|
|
31
34
|
useSimpleAchievements,
|
|
32
35
|
} from 'react-achievements';
|
|
33
36
|
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
},
|
|
38
|
-
};
|
|
37
|
+
const achievementsClient = createRestAchievementClient({
|
|
38
|
+
baseUrl: '/api/achievements',
|
|
39
|
+
});
|
|
39
40
|
|
|
40
41
|
function Game() {
|
|
41
|
-
const { track } = useSimpleAchievements();
|
|
42
|
+
const { track, event } = useSimpleAchievements();
|
|
42
43
|
|
|
43
44
|
return (
|
|
44
|
-
|
|
45
|
-
Score 100
|
|
46
|
-
|
|
45
|
+
<>
|
|
46
|
+
<button onClick={() => track('score', 100)}>Score 100</button>
|
|
47
|
+
<button onClick={() => event('lesson.completed', { lessonId: 'intro' })}>
|
|
48
|
+
Complete lesson
|
|
49
|
+
</button>
|
|
50
|
+
</>
|
|
47
51
|
);
|
|
48
52
|
}
|
|
49
53
|
|
|
50
54
|
export default function App() {
|
|
51
55
|
return (
|
|
52
|
-
<AchievementProvider
|
|
56
|
+
<AchievementProvider client={achievementsClient}>
|
|
53
57
|
<Game />
|
|
54
58
|
<AchievementsWidget />
|
|
55
59
|
</AchievementProvider>
|
|
@@ -59,6 +63,18 @@ export default function App() {
|
|
|
59
63
|
|
|
60
64
|
`AchievementsWidget` reads from context, shows the unlocked count, and opens a modal with locked and unlocked achievements. Use `placement="inline"` to put it in a drawer, sidebar, or navigation area. For an exact visual match, pass `renderTrigger` and use your app's own drawer row, nav item, or profile menu button while the widget still controls the modal.
|
|
61
65
|
|
|
66
|
+
Your server should expose this contract:
|
|
67
|
+
|
|
68
|
+
```http
|
|
69
|
+
GET /api/achievements
|
|
70
|
+
POST /api/achievements/track
|
|
71
|
+
POST /api/achievements/increment
|
|
72
|
+
POST /api/achievements/event
|
|
73
|
+
POST /api/achievements/reset
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The official `achievements-engine` package can run those routes on your server, but any backend can return the same snapshot shape.
|
|
77
|
+
|
|
62
78
|
```tsx
|
|
63
79
|
<AchievementsWidget
|
|
64
80
|
placement="inline"
|
|
@@ -120,7 +136,7 @@ Provider-level icons and UI options are shared across notifications, widgets, mo
|
|
|
120
136
|
|
|
121
137
|
```tsx
|
|
122
138
|
<AchievementProvider
|
|
123
|
-
|
|
139
|
+
client={achievementsClient}
|
|
124
140
|
icons={{ login: '🔑', streak: '🔥' }}
|
|
125
141
|
ui={{
|
|
126
142
|
theme: 'minimal',
|
|
@@ -142,7 +158,7 @@ Provider-level icons and UI options are shared across notifications, widgets, mo
|
|
|
142
158
|
|
|
143
159
|
Set `ui.enableConfetti` to `false` to disable the built-in celebration. Omit `ConfettiComponent` when you only want to tune the default `canvas-confetti` animation through `ui.confetti`.
|
|
144
160
|
|
|
145
|
-
Rewards can optionally override the global confetti settings. Omit `confetti` to use the provider defaults, or set `confetti: false` for quieter rewards:
|
|
161
|
+
Rewards returned by your server can optionally include `confetti` to override the global confetti settings. Omit `confetti` to use the provider defaults, or set `confetti: false` for quieter rewards:
|
|
146
162
|
|
|
147
163
|
```tsx
|
|
148
164
|
const achievements = {
|
|
@@ -173,6 +189,7 @@ const achievements = {
|
|
|
173
189
|
const {
|
|
174
190
|
track,
|
|
175
191
|
increment,
|
|
192
|
+
event,
|
|
176
193
|
trackMultiple,
|
|
177
194
|
unlockedIds,
|
|
178
195
|
unlockedAchievements,
|
|
@@ -184,41 +201,34 @@ const {
|
|
|
184
201
|
|
|
185
202
|
Deprecated aliases from v3, including `unlocked` and `all`, remain available until 5.0.
|
|
186
203
|
|
|
187
|
-
##
|
|
204
|
+
## Server Engine Example
|
|
188
205
|
|
|
189
|
-
|
|
206
|
+
Use `achievements-engine` on your server when you want JavaScript rule evaluation and persistence adapters:
|
|
190
207
|
|
|
191
|
-
```
|
|
208
|
+
```ts
|
|
192
209
|
import {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
} from 'react-achievements';
|
|
210
|
+
AchievementService,
|
|
211
|
+
MemoryAchievementRepository,
|
|
212
|
+
createAchievementFetchHandler,
|
|
213
|
+
} from 'achievements-engine/server';
|
|
198
214
|
|
|
199
|
-
const
|
|
215
|
+
const service = new AchievementService({
|
|
200
216
|
achievements,
|
|
217
|
+
repository: new MemoryAchievementRepository(),
|
|
201
218
|
eventMapping: {
|
|
202
|
-
|
|
219
|
+
'lesson.completed': () => ({ completedLesson: true }),
|
|
203
220
|
},
|
|
204
|
-
storage: 'local',
|
|
205
221
|
});
|
|
206
222
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
export default function App() {
|
|
213
|
-
return (
|
|
214
|
-
<AchievementProvider engine={engine}>
|
|
215
|
-
<Game />
|
|
216
|
-
<AchievementsWidget />
|
|
217
|
-
</AchievementProvider>
|
|
218
|
-
);
|
|
219
|
-
}
|
|
223
|
+
export const handleAchievementsRequest = createAchievementFetchHandler({
|
|
224
|
+
service,
|
|
225
|
+
basePath: '/api/achievements',
|
|
226
|
+
getSubjectId: (request) => getUserIdFromSession(request),
|
|
227
|
+
});
|
|
220
228
|
```
|
|
221
229
|
|
|
230
|
+
For Rails Merit or a custom backend, expose the same REST endpoints and return the same achievement snapshot fields.
|
|
231
|
+
|
|
222
232
|
## Headless Usage
|
|
223
233
|
|
|
224
234
|
Use the DOM-free entry point when building custom UI or preparing a React Native integration:
|
|
@@ -250,7 +260,7 @@ function CustomAchievementsPanel() {
|
|
|
250
260
|
|
|
251
261
|
export function App() {
|
|
252
262
|
return (
|
|
253
|
-
<AchievementProvider
|
|
263
|
+
<AchievementProvider client={achievementsClient}>
|
|
254
264
|
<CustomAchievementsPanel />
|
|
255
265
|
</AchievementProvider>
|
|
256
266
|
);
|
|
@@ -275,12 +285,9 @@ React Native UI components are not included in the web package; use `achievement
|
|
|
275
285
|
|
|
276
286
|
## License
|
|
277
287
|
|
|
278
|
-
React Achievements is
|
|
279
|
-
|
|
280
|
-
- **Free for Non-Commercial Use** (MIT License)
|
|
281
|
-
- **Commercial License Required** for businesses, SaaS, commercial apps, and enterprise use
|
|
288
|
+
React Achievements is licensed under the MIT License. It is free to use, modify, distribute, and include in personal, open-source, and commercial projects.
|
|
282
289
|
|
|
283
|
-
|
|
290
|
+
See [LICENSE](./LICENSE) for details.
|
|
284
291
|
|
|
285
292
|
## AI Agents
|
|
286
293
|
|