shogun-button-react 4.3.5 → 5.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 +59 -4
- package/dist/components/ShogunButton.js +17 -5
- package/dist/connector.js +19 -5
- package/dist/index.js +1 -1
- package/dist/interfaces/connector-options.d.ts +6 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
A comprehensive React component library for seamless integration of Shogun authentication into your applications. This library provides a simple yet powerful way to add multi-method authentication, account management, and real-time data synchronization to your React applications.
|
|
4
4
|
|
|
5
|
-
> **Version 4.
|
|
5
|
+
> **Version 4.4.0** - Compatible with shogun-core ^5.0.0
|
|
6
6
|
|
|
7
7
|
## ✨ Features
|
|
8
8
|
|
|
@@ -14,11 +14,13 @@ A comprehensive React component library for seamless integration of Shogun authe
|
|
|
14
14
|
- 🌍 **TypeScript Support** - Full type safety and IntelliSense support
|
|
15
15
|
- 🔌 **Plugin System** - Advanced Gun operations with custom hooks
|
|
16
16
|
- 📊 **Real-time Data** - Reactive data synchronization with RxJS observables
|
|
17
|
+
- ✅ **Robust Foundation** - Built on shogun-core v5.0.0 with 99.86% test coverage
|
|
18
|
+
- 🗄️ **Flexible Storage** - Support for GunDB, SQLite, PostgreSQL, MongoDB via TransportLayer
|
|
17
19
|
|
|
18
20
|
## 📦 Requirements
|
|
19
21
|
|
|
20
22
|
- **React**: ^18.0.0
|
|
21
|
-
- **shogun-core**: ^
|
|
23
|
+
- **shogun-core**: ^5.0.0
|
|
22
24
|
- **Node.js**: ≥18
|
|
23
25
|
|
|
24
26
|
## 🚀 Quick Start
|
|
@@ -104,7 +106,7 @@ const { core, options } = shogunConnector({
|
|
|
104
106
|
showNostr: true,
|
|
105
107
|
showZkProof: true,
|
|
106
108
|
|
|
107
|
-
// Network configuration
|
|
109
|
+
// Network configuration (backward compatible)
|
|
108
110
|
peers: [
|
|
109
111
|
"https://gun-manhattan.herokuapp.com/gun"
|
|
110
112
|
],
|
|
@@ -123,6 +125,51 @@ const { core, options } = shogunConnector({
|
|
|
123
125
|
});
|
|
124
126
|
```
|
|
125
127
|
|
|
128
|
+
### Advanced Transport Layer Configuration (New in v5.0.0)
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
const { core, options } = shogunConnector({
|
|
132
|
+
appName: "My App",
|
|
133
|
+
|
|
134
|
+
// Use new transport layer system
|
|
135
|
+
transport: {
|
|
136
|
+
type: "gun", // or "sqlite", "postgresql", "mongodb", "custom"
|
|
137
|
+
options: {
|
|
138
|
+
peers: ["https://gun-manhattan.herokuapp.com/gun"],
|
|
139
|
+
// Additional transport-specific options
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
// Alternative: Use SQLite for local development
|
|
144
|
+
transport: {
|
|
145
|
+
type: "sqlite",
|
|
146
|
+
options: {
|
|
147
|
+
filename: "./my-app.db",
|
|
148
|
+
// SQLite-specific options
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
// Alternative: Use PostgreSQL for production
|
|
153
|
+
transport: {
|
|
154
|
+
type: "postgresql",
|
|
155
|
+
options: {
|
|
156
|
+
host: "localhost",
|
|
157
|
+
port: 5432,
|
|
158
|
+
database: "myapp",
|
|
159
|
+
username: "user",
|
|
160
|
+
password: "password",
|
|
161
|
+
// PostgreSQL-specific options
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
// Authentication methods
|
|
166
|
+
showMetamask: true,
|
|
167
|
+
showWebauthn: true,
|
|
168
|
+
showNostr: true,
|
|
169
|
+
showZkProof: true,
|
|
170
|
+
});
|
|
171
|
+
```
|
|
172
|
+
|
|
126
173
|
## 🎯 API Reference
|
|
127
174
|
|
|
128
175
|
### ShogunButtonProvider
|
|
@@ -602,10 +649,18 @@ interface ShogunConnectorOptions {
|
|
|
602
649
|
showNostr?: boolean;
|
|
603
650
|
darkMode?: boolean;
|
|
604
651
|
|
|
605
|
-
// Network configuration
|
|
652
|
+
// Network configuration (backward compatible)
|
|
606
653
|
peers?: string[];
|
|
607
654
|
authToken?: string;
|
|
608
655
|
gunInstance?: IGunInstance<any>;
|
|
656
|
+
gunOptions?: any;
|
|
657
|
+
|
|
658
|
+
// Transport layer configuration (new in v5.0.0)
|
|
659
|
+
transport?: {
|
|
660
|
+
type: "gun" | "sqlite" | "postgresql" | "mongodb" | "custom";
|
|
661
|
+
options?: any;
|
|
662
|
+
customTransport?: any;
|
|
663
|
+
};
|
|
609
664
|
|
|
610
665
|
// Timeouts and provider configs
|
|
611
666
|
timeouts?: {
|
|
@@ -191,15 +191,25 @@ export function ShogunButtonProvider({ children, core, options, onLoginSuccess,
|
|
|
191
191
|
throw new Error("Passwords do not match");
|
|
192
192
|
}
|
|
193
193
|
console.log(`[DEBUG] ShogunButton: Calling core.signUp for username: ${username}`);
|
|
194
|
-
|
|
195
|
-
console.log(`[DEBUG] ShogunButton: core.signUp
|
|
194
|
+
console.log(`[DEBUG] ShogunButton: core object:`, core);
|
|
195
|
+
console.log(`[DEBUG] ShogunButton: core.signUp exists:`, typeof (core === null || core === void 0 ? void 0 : core.signUp));
|
|
196
|
+
try {
|
|
197
|
+
console.log(`[DEBUG] ShogunButton: About to call core.signUp...`);
|
|
198
|
+
result = await core.signUp(args[0], args[1]);
|
|
199
|
+
console.log(`[DEBUG] ShogunButton: core.signUp completed successfully`);
|
|
200
|
+
console.log(`[DEBUG] ShogunButton: core.signUp result:`, result);
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
console.error(`[DEBUG] ShogunButton: core.signUp error:`, error);
|
|
204
|
+
throw error;
|
|
205
|
+
}
|
|
196
206
|
break;
|
|
197
207
|
case "webauthn":
|
|
198
208
|
username = args[0];
|
|
199
209
|
const webauthn = core.getPlugin("webauthn");
|
|
200
210
|
if (!webauthn)
|
|
201
211
|
throw new Error("WebAuthn plugin not available");
|
|
202
|
-
result = await webauthn.signUp(username);
|
|
212
|
+
result = await webauthn.signUp(username, { generateSeedPhrase: true });
|
|
203
213
|
break;
|
|
204
214
|
case "web3":
|
|
205
215
|
const web3 = core.getPlugin("web3");
|
|
@@ -557,12 +567,15 @@ export const ShogunButton = (() => {
|
|
|
557
567
|
}
|
|
558
568
|
// Event handlers
|
|
559
569
|
const handleAuth = async (method, ...args) => {
|
|
570
|
+
console.log(`[DEBUG] handleAuth called with method: ${method}, formMode: ${formMode}, args:`, args);
|
|
560
571
|
setError("");
|
|
561
572
|
setLoading(true);
|
|
562
573
|
try {
|
|
563
574
|
// Use formMode to determine whether to call login or signUp
|
|
564
575
|
const action = formMode === "login" ? login : signUp;
|
|
576
|
+
console.log(`[DEBUG] handleAuth calling action: ${action.name}, method: ${method}`);
|
|
565
577
|
const result = await action(method, ...args);
|
|
578
|
+
console.log(`[DEBUG] handleAuth result:`, result);
|
|
566
579
|
if (result && !result.success && result.error) {
|
|
567
580
|
setError(result.error);
|
|
568
581
|
}
|
|
@@ -582,6 +595,7 @@ export const ShogunButton = (() => {
|
|
|
582
595
|
};
|
|
583
596
|
const handleSubmit = async (e) => {
|
|
584
597
|
e.preventDefault();
|
|
598
|
+
console.log(`[DEBUG] handleSubmit called, formMode: ${formMode}, username: ${formUsername}`);
|
|
585
599
|
setError("");
|
|
586
600
|
setLoading(true);
|
|
587
601
|
try {
|
|
@@ -618,7 +632,6 @@ export const ShogunButton = (() => {
|
|
|
618
632
|
setLoading(false);
|
|
619
633
|
}
|
|
620
634
|
};
|
|
621
|
-
const handleWeb3Auth = () => handleAuth("web3");
|
|
622
635
|
const handleWebAuthnAuth = () => {
|
|
623
636
|
if (!(core === null || core === void 0 ? void 0 : core.hasPlugin("webauthn"))) {
|
|
624
637
|
setError("WebAuthn is not supported in your browser");
|
|
@@ -626,7 +639,6 @@ export const ShogunButton = (() => {
|
|
|
626
639
|
}
|
|
627
640
|
setAuthView("webauthn-username");
|
|
628
641
|
};
|
|
629
|
-
const handleNostrAuth = () => handleAuth("nostr");
|
|
630
642
|
const handleZkProofAuth = () => {
|
|
631
643
|
if (!(core === null || core === void 0 ? void 0 : core.hasPlugin("zkproof"))) {
|
|
632
644
|
setError("ZK-Proof plugin not available");
|
package/dist/connector.js
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
import { ShogunCore } from "shogun-core";
|
|
2
2
|
export async function shogunConnector(options) {
|
|
3
|
-
const { gunInstance, gunOptions, appName, timeouts, webauthn, nostr, web3, zkproof, showWebauthn, showNostr, showMetamask, showZkProof, darkMode, enableGunDebug = true, enableConnectionMonitoring = true, defaultPageSize = 20, connectionTimeout = 10000, debounceInterval = 100, ...restOptions } = options;
|
|
3
|
+
const { gunInstance, gunOptions, transport, appName, timeouts, webauthn, nostr, web3, zkproof, showWebauthn, showNostr, showMetamask, showZkProof, darkMode, enableGunDebug = true, enableConnectionMonitoring = true, defaultPageSize = 20, connectionTimeout = 10000, debounceInterval = 100, ...restOptions } = options;
|
|
4
4
|
let core = null;
|
|
5
|
-
|
|
5
|
+
// Priority: transport > gunInstance > gunOptions
|
|
6
|
+
if (transport !== undefined) {
|
|
7
|
+
// Use new transport layer configuration
|
|
8
|
+
core = new ShogunCore({
|
|
9
|
+
transport: transport,
|
|
10
|
+
webauthn,
|
|
11
|
+
nostr,
|
|
12
|
+
web3,
|
|
13
|
+
zkproof,
|
|
14
|
+
timeouts,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
else if (gunInstance !== undefined) {
|
|
18
|
+
// Use existing Gun instance (backward compatibility)
|
|
6
19
|
core = new ShogunCore({
|
|
7
20
|
gunInstance: gunInstance,
|
|
8
21
|
webauthn,
|
|
@@ -13,6 +26,7 @@ export async function shogunConnector(options) {
|
|
|
13
26
|
});
|
|
14
27
|
}
|
|
15
28
|
else {
|
|
29
|
+
// Use Gun options (backward compatibility)
|
|
16
30
|
core = new ShogunCore({
|
|
17
31
|
gunOptions: gunOptions,
|
|
18
32
|
webauthn,
|
|
@@ -24,12 +38,12 @@ export async function shogunConnector(options) {
|
|
|
24
38
|
}
|
|
25
39
|
// Wait for core to initialize (plugins registration, etc.)
|
|
26
40
|
try {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
41
|
+
await core.initialize();
|
|
42
|
+
console.log(`[DEBUG] ShogunConnector: ShogunCore initialized`);
|
|
30
43
|
}
|
|
31
44
|
catch (error) {
|
|
32
45
|
console.error("Error initializing ShogunCore:", error);
|
|
46
|
+
console.error(`[DEBUG] ShogunConnector: Error initializing ShogunCore: ${error}`);
|
|
33
47
|
}
|
|
34
48
|
const setProvider = (provider) => {
|
|
35
49
|
var _a;
|