shogun-core 2.0.3 → 3.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/README.md +150 -19
- package/dist/browser/shogun-core.js +3241 -1286
- package/dist/browser/shogun-core.js.map +1 -1
- package/dist/config/simplified-config.js +230 -0
- package/dist/core.js +49 -571
- package/dist/gundb/db.js +466 -237
- package/dist/gundb/improved-types.js +4 -0
- package/dist/gundb/index.js +4 -0
- package/dist/gundb/simple-api.js +438 -0
- package/dist/index.js +8 -2
- package/dist/managers/AuthManager.js +225 -0
- package/dist/managers/CoreInitializer.js +227 -0
- package/dist/managers/EventManager.js +67 -0
- package/dist/managers/PluginManager.js +296 -0
- package/dist/migration-test.js +91 -0
- package/dist/plugins/nostr/nostrConnectorPlugin.js +1 -1
- package/dist/plugins/oauth/oauthPlugin.js +1 -1
- package/dist/plugins/webauthn/webauthnPlugin.js +1 -1
- package/dist/types/config/simplified-config.d.ts +114 -0
- package/dist/types/core.d.ts +13 -46
- package/dist/types/gundb/db.d.ts +92 -14
- package/dist/types/gundb/improved-types.d.ts +123 -0
- package/dist/types/gundb/index.d.ts +2 -0
- package/dist/types/gundb/rxjs.d.ts +3 -3
- package/dist/types/gundb/simple-api.d.ts +90 -0
- package/dist/types/index.d.ts +6 -4
- package/dist/types/{types → interfaces}/shogun.d.ts +8 -10
- package/dist/types/managers/AuthManager.d.ts +69 -0
- package/dist/types/managers/CoreInitializer.d.ts +40 -0
- package/dist/types/managers/EventManager.d.ts +49 -0
- package/dist/types/managers/PluginManager.d.ts +145 -0
- package/dist/types/migration-test.d.ts +16 -0
- package/dist/types/plugins/base.d.ts +2 -2
- package/dist/types/plugins/index.d.ts +1 -1
- package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +1 -1
- package/dist/types/plugins/nostr/types.d.ts +2 -2
- package/dist/types/plugins/oauth/oauthPlugin.d.ts +1 -1
- package/dist/types/plugins/oauth/types.d.ts +2 -2
- package/dist/types/plugins/web3/types.d.ts +2 -2
- package/dist/types/plugins/web3/web3ConnectorPlugin.d.ts +1 -1
- package/dist/types/plugins/webauthn/types.d.ts +2 -2
- package/dist/types/plugins/webauthn/webauthnPlugin.d.ts +1 -1
- package/dist/types/utils/errorHandler.d.ts +1 -1
- package/package.json +1 -1
- /package/dist/{types → interfaces}/common.js +0 -0
- /package/dist/{types → interfaces}/events.js +0 -0
- /package/dist/{types → interfaces}/plugin.js +0 -0
- /package/dist/{types → interfaces}/shogun.js +0 -0
- /package/dist/types/{types → interfaces}/common.d.ts +0 -0
- /package/dist/types/{types → interfaces}/events.d.ts +0 -0
- /package/dist/types/{types → interfaces}/plugin.d.ts +0 -0
package/README.md
CHANGED
|
@@ -20,11 +20,20 @@ Shogun Core is a comprehensive SDK for building decentralized applications (dApp
|
|
|
20
20
|
- 🔑 **Password Recovery**: Secure password hint system with security questions
|
|
21
21
|
- ✅ **Type Consistency**: Unified return types across all authentication methods
|
|
22
22
|
- 🚀 **Simplified Architecture**: Focused on core functionality with reduced complexity
|
|
23
|
+
- ⭐ **Simple API**: Easy-to-use wrapper for common operations with minimal complexity
|
|
24
|
+
- 👤 **User Space Management**: Complete CRUD operations for user-specific data storage
|
|
25
|
+
- ⚡ **Quick Start**: Rapid initialization with pre-configured setups
|
|
26
|
+
- 🎛️ **Configuration Presets**: Pre-built configurations for common use cases
|
|
23
27
|
|
|
24
|
-
## Recent Updates (
|
|
28
|
+
## Recent Updates (v2.0.0)
|
|
25
29
|
|
|
26
|
-
### ✅ **Major API Simplification**
|
|
30
|
+
### ✅ **Major API Improvements & Simplification**
|
|
27
31
|
|
|
32
|
+
- **⭐ NEW: Simple API Layer**: Added `SimpleGunAPI` with simplified methods for common operations
|
|
33
|
+
- **⭐ NEW: User Space Management**: Complete CRUD operations for user-specific data storage
|
|
34
|
+
- **⭐ NEW: Quick Start Functions**: `quickStart()` and `QuickStart` class for rapid initialization
|
|
35
|
+
- **⭐ NEW: Improved Type System**: Reduced `any` usage with better TypeScript types
|
|
36
|
+
- **⭐ NEW: Configuration Presets**: Pre-built configurations for common use cases
|
|
28
37
|
- **Removed Non-Essential Functions**: Eliminated debug/testing functions, rate limiting system, frozen space system, and complex username management
|
|
29
38
|
- **Simplified Architecture**: Removed cryptographic key derivation functions and advanced peer management
|
|
30
39
|
- **Streamlined Event System**: Removed complex event emission for data and peer operations
|
|
@@ -51,7 +60,45 @@ yarn add shogun-core
|
|
|
51
60
|
|
|
52
61
|
## Quick Start
|
|
53
62
|
|
|
54
|
-
###
|
|
63
|
+
### ⭐ **NEW: Simple API Setup (Recommended)**
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { quickStart, Gun } from "shogun-core";
|
|
67
|
+
|
|
68
|
+
// Create Gun instance
|
|
69
|
+
const gun = Gun({
|
|
70
|
+
peers: ['https://gun-manhattan.herokuapp.com/gun']
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Quick start with simple API
|
|
74
|
+
const shogun = quickStart(gun, 'my-app');
|
|
75
|
+
await shogun.init();
|
|
76
|
+
|
|
77
|
+
// Use simplified API
|
|
78
|
+
const user = await shogun.api.signup('alice', 'password123');
|
|
79
|
+
if (user) {
|
|
80
|
+
console.log('User created:', user.username);
|
|
81
|
+
|
|
82
|
+
// User space operations
|
|
83
|
+
await shogun.api.updateProfile({
|
|
84
|
+
name: 'Alice',
|
|
85
|
+
email: 'alice@example.com'
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
await shogun.api.saveSettings({
|
|
89
|
+
theme: 'dark',
|
|
90
|
+
language: 'en'
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Create collections
|
|
94
|
+
await shogun.api.createCollection('todos', {
|
|
95
|
+
'1': { text: 'Learn Shogun Core', done: false },
|
|
96
|
+
'2': { text: 'Build dApp', done: false }
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Advanced Setup (Full Features)
|
|
55
102
|
|
|
56
103
|
```typescript
|
|
57
104
|
import { ShogunCore } from "shogun-core";
|
|
@@ -108,6 +155,71 @@ await shogun.initialize();
|
|
|
108
155
|
console.log("Shogun Core initialized!");
|
|
109
156
|
```
|
|
110
157
|
|
|
158
|
+
## ⭐ **NEW: Simple API**
|
|
159
|
+
|
|
160
|
+
The Simple API provides an easy-to-use interface for common operations with minimal complexity. Perfect for beginners or when you need quick setup.
|
|
161
|
+
|
|
162
|
+
### Simple API Methods
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
import { quickStart, Gun } from "shogun-core";
|
|
166
|
+
|
|
167
|
+
const gun = Gun({ peers: ['https://gun-manhattan.herokuapp.com/gun'] });
|
|
168
|
+
const shogun = quickStart(gun, 'my-app');
|
|
169
|
+
await shogun.init();
|
|
170
|
+
|
|
171
|
+
// Authentication
|
|
172
|
+
const user = await shogun.api.signup('username', 'password');
|
|
173
|
+
const loginResult = await shogun.api.login('username', 'password');
|
|
174
|
+
shogun.api.logout();
|
|
175
|
+
const isLoggedIn = shogun.api.isLoggedIn();
|
|
176
|
+
|
|
177
|
+
// Basic data operations
|
|
178
|
+
await shogun.api.put('path/to/data', { value: 'hello' });
|
|
179
|
+
const data = await shogun.api.get('path/to/data');
|
|
180
|
+
await shogun.api.set('path/to/data', { value: 'updated' });
|
|
181
|
+
await shogun.api.remove('path/to/data');
|
|
182
|
+
|
|
183
|
+
// User space operations (requires login)
|
|
184
|
+
await shogun.api.putUserData('preferences', { theme: 'dark' });
|
|
185
|
+
const prefs = await shogun.api.getUserData('preferences');
|
|
186
|
+
await shogun.api.removeUserData('preferences');
|
|
187
|
+
|
|
188
|
+
// Profile management
|
|
189
|
+
await shogun.api.updateProfile({
|
|
190
|
+
name: 'John Doe',
|
|
191
|
+
email: 'john@example.com',
|
|
192
|
+
bio: 'Developer'
|
|
193
|
+
});
|
|
194
|
+
const profile = await shogun.api.getProfile();
|
|
195
|
+
|
|
196
|
+
// Settings and preferences
|
|
197
|
+
await shogun.api.saveSettings({ language: 'en', notifications: true });
|
|
198
|
+
const settings = await shogun.api.getSettings();
|
|
199
|
+
|
|
200
|
+
await shogun.api.savePreferences({ theme: 'dark', fontSize: 14 });
|
|
201
|
+
const preferences = await shogun.api.getPreferences();
|
|
202
|
+
|
|
203
|
+
// Collections (for structured data)
|
|
204
|
+
await shogun.api.createCollection('todos', {
|
|
205
|
+
'1': { text: 'Learn Shogun Core', done: false },
|
|
206
|
+
'2': { text: 'Build dApp', done: false }
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
await shogun.api.addToCollection('todos', '3', {
|
|
210
|
+
text: 'Deploy to production',
|
|
211
|
+
done: false
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
const todos = await shogun.api.getCollection('todos');
|
|
215
|
+
await shogun.api.removeFromCollection('todos', '2');
|
|
216
|
+
|
|
217
|
+
// Utility methods
|
|
218
|
+
const currentUser = shogun.api.getCurrentUser();
|
|
219
|
+
const userExists = await shogun.api.userExists('username');
|
|
220
|
+
const user = await shogun.api.getUser('username');
|
|
221
|
+
```
|
|
222
|
+
|
|
111
223
|
## Plugin Authentication APIs
|
|
112
224
|
|
|
113
225
|
Shogun Core provides a unified plugin system for different authentication methods. Each plugin implements standardized `login()` and `signUp()` methods that return consistent `AuthResult` and `SignUpResult` objects.
|
|
@@ -474,10 +586,44 @@ You can also use Shogun Core directly in the browser by including it from a CDN.
|
|
|
474
586
|
|
|
475
587
|
## API Reference
|
|
476
588
|
|
|
477
|
-
###
|
|
589
|
+
### ⭐ **Simple API Methods**
|
|
478
590
|
|
|
479
591
|
#### Authentication
|
|
592
|
+
- `signup(username: string, password: string): Promise<UserInfo | null>` - Create new user account
|
|
593
|
+
- `login(username: string, password: string): Promise<UserInfo | null>` - Authenticate with username/password
|
|
594
|
+
- `logout(): void` - Logout current user
|
|
595
|
+
- `isLoggedIn(): boolean` - Check if user is authenticated
|
|
480
596
|
|
|
597
|
+
#### Data Operations
|
|
598
|
+
- `get<T>(path: string): Promise<T | null>` - Get data from path
|
|
599
|
+
- `put<T>(path: string, data: T): Promise<boolean>` - Store data at path
|
|
600
|
+
- `set<T>(path: string, data: T): Promise<boolean>` - Update data at path
|
|
601
|
+
- `remove(path: string): Promise<boolean>` - Remove data from path
|
|
602
|
+
|
|
603
|
+
#### User Space Operations
|
|
604
|
+
- `putUserData<T>(path: string, data: T): Promise<boolean>` - Store user-specific data
|
|
605
|
+
- `getUserData<T>(path: string): Promise<T | null>` - Get user-specific data
|
|
606
|
+
- `setUserData<T>(path: string, data: T): Promise<boolean>` - Update user-specific data
|
|
607
|
+
- `removeUserData(path: string): Promise<boolean>` - Remove user-specific data
|
|
608
|
+
- `getAllUserData(): Promise<Record<string, unknown> | null>` - Get all user data
|
|
609
|
+
|
|
610
|
+
#### Profile & Settings
|
|
611
|
+
- `updateProfile(profileData: ProfileData): Promise<boolean>` - Update user profile
|
|
612
|
+
- `getProfile(): Promise<Record<string, unknown> | null>` - Get user profile
|
|
613
|
+
- `saveSettings(settings: Record<string, unknown>): Promise<boolean>` - Save user settings
|
|
614
|
+
- `getSettings(): Promise<Record<string, unknown> | null>` - Get user settings
|
|
615
|
+
- `savePreferences(preferences: Record<string, unknown>): Promise<boolean>` - Save user preferences
|
|
616
|
+
- `getPreferences(): Promise<Record<string, unknown> | null>` - Get user preferences
|
|
617
|
+
|
|
618
|
+
#### Collections
|
|
619
|
+
- `createCollection<T>(name: string, items: Record<string, T>): Promise<boolean>` - Create user collection
|
|
620
|
+
- `addToCollection<T>(name: string, itemId: string, item: T): Promise<boolean>` - Add item to collection
|
|
621
|
+
- `getCollection(name: string): Promise<Record<string, unknown> | null>` - Get collection
|
|
622
|
+
- `removeFromCollection(name: string, itemId: string): Promise<boolean>` - Remove item from collection
|
|
623
|
+
|
|
624
|
+
### Advanced API Methods
|
|
625
|
+
|
|
626
|
+
#### Core Authentication
|
|
481
627
|
- `login(username: string, password: string): Promise<AuthResult>` - Authenticate with username/password
|
|
482
628
|
- `loginWithPair(pair: ISEAPair): Promise<AuthResult>` - Authenticate directly with a GunDB SEA pair
|
|
483
629
|
- `signUp(username: string, password: string, email?: string, pair?: ISEAPair | null): Promise<SignUpResult>` - Create new user account
|
|
@@ -485,14 +631,12 @@ You can also use Shogun Core directly in the browser by including it from a CDN.
|
|
|
485
631
|
- `isLoggedIn(): boolean` - Check if user is authenticated
|
|
486
632
|
|
|
487
633
|
#### Plugin Management
|
|
488
|
-
|
|
489
634
|
- `getPlugin<T>(name: string): T | undefined` - Get plugin by name
|
|
490
635
|
- `hasPlugin(name: string): boolean` - Check if plugin exists
|
|
491
636
|
- `register(plugin: ShogunPlugin): void` - Register custom plugin
|
|
492
637
|
- `unregister(pluginName: string): void` - Remove plugin
|
|
493
638
|
|
|
494
639
|
#### Event Handling
|
|
495
|
-
|
|
496
640
|
- `on<K extends keyof ShogunEventMap>(eventName: K, listener: Function): this` - Subscribe to typed events
|
|
497
641
|
- `off<K extends keyof ShogunEventMap>(eventName: K, listener: Function): this` - Unsubscribe from events
|
|
498
642
|
- `emit<K extends keyof ShogunEventMap>(eventName: K, data?: ShogunEventMap[K]): boolean` - Emit custom events
|
|
@@ -547,19 +691,6 @@ interface ShogunEventMap {
|
|
|
547
691
|
"auth:login": AuthEventData; // User logged in
|
|
548
692
|
"auth:logout": void; // User logged out
|
|
549
693
|
"auth:signup": AuthEventData; // New user registered
|
|
550
|
-
"auth:username_changed": {
|
|
551
|
-
oldUsername?: string;
|
|
552
|
-
newUsername?: string;
|
|
553
|
-
userPub?: string;
|
|
554
|
-
}; // Username changed
|
|
555
|
-
"gun:put": GunDataEventData; // Data written to GunDB
|
|
556
|
-
"gun:get": GunDataEventData; // Data read from GunDB
|
|
557
|
-
"gun:set": GunDataEventData; // Data updated in GunDB
|
|
558
|
-
"gun:remove": GunDataEventData; // Data removed from GunDB
|
|
559
|
-
"gun:peer:add": GunPeerEventData; // Peer added
|
|
560
|
-
"gun:peer:remove": GunPeerEventData; // Peer removed
|
|
561
|
-
"gun:peer:connect": GunPeerEventData; // Peer connected
|
|
562
|
-
"gun:peer:disconnect": GunPeerEventData; // Peer disconnected
|
|
563
694
|
"plugin:registered": { name: string; version?: string; category?: string }; // Plugin registered
|
|
564
695
|
"plugin:unregistered": { name: string }; // Plugin unregistered
|
|
565
696
|
debug: { action: string; [key: string]: any }; // Debug information
|