shogun-button-react 1.3.12 → 1.3.14

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 CHANGED
@@ -27,48 +27,35 @@ yarn add shogun-button-react
27
27
 
28
28
  ```tsx
29
29
  import React from "react";
30
- import {
31
- ShogunButton,
32
- ShogunButtonProvider,
33
- shogunConnector,
34
- } from "shogun-button-react";
30
+ import { ShogunButton, ShogunButtonProvider, shogunConnector } from "shogun-button-react";
35
31
  import "shogun-button-react/styles.css";
36
32
 
37
33
  function App() {
38
- const { sdk, options } = shogunConnector({
34
+ const { core, options } = shogunConnector({
39
35
  appName: "My Awesome App",
40
- appDescription: "A decentralized application with Shogun authentication",
41
- appUrl: "https://myapp.com",
42
- appIcon: "https://myapp.com/icon.png",
43
36
  // Enable specific authentication methods
44
37
  showMetamask: true,
45
38
  showWebauthn: true,
46
39
  showNostr: true,
47
40
  showOauth: true,
41
+ // Optional peers
42
+ peers: [
43
+ "https://gun-manhattan.herokuapp.com/gun"
44
+ ],
48
45
  });
49
46
 
50
47
  return (
51
48
  <ShogunButtonProvider
52
- sdk={sdk}
49
+ core={core}
53
50
  options={options}
54
51
  onLoginSuccess={(data) => {
55
- console.log("🎉 Login successful!", data);
56
- // Handle successful login
57
- // data.userPub - User's public key
58
- // data.username - Display name
59
- // data.authMethod - Authentication method used
52
+ console.log("Login successful!", data);
60
53
  }}
61
54
  onSignupSuccess={(data) => {
62
- console.log("🎊 Account created successfully!", data);
63
- // Handle successful account creation
55
+ console.log("Account created successfully!", data);
64
56
  }}
65
57
  onError={(error) => {
66
- console.error("Authentication error:", error);
67
- // Handle authentication errors
68
- }}
69
- onLogout={() => {
70
- console.log("👋 User logged out");
71
- // Handle logout events
58
+ console.error("Authentication error:", error);
72
59
  }}
73
60
  >
74
61
  <div className="app">
@@ -76,9 +63,7 @@ function App() {
76
63
  <h1>Welcome to My Awesome App</h1>
77
64
  <ShogunButton />
78
65
  </header>
79
- <main>
80
- {/* Your app content */}
81
- </main>
66
+ <main>{/* Your app content */}</main>
82
67
  </div>
83
68
  </ShogunButtonProvider>
84
69
  );
@@ -92,47 +77,35 @@ export default App;
92
77
  ### Custom Authentication Options
93
78
 
94
79
  ```tsx
95
- const { sdk, options } = shogunConnector({
80
+ const { core, options } = shogunConnector({
96
81
  appName: "My App",
97
-
98
- // Customize which authentication methods to show
99
- showMetamask: true, // Enable MetaMask login
100
- showWebauthn: true, // Enable WebAuthn (biometric/security keys)
101
- showNostr: true, // Enable Nostr wallet connection
102
- showOauth: true, // Enable OAuth providers
103
-
82
+
83
+ // Toggle authentication methods in the UI
84
+ showMetamask: true,
85
+ showWebauthn: true,
86
+ showNostr: true,
87
+ showOauth: true,
88
+
104
89
  // Network configuration
105
90
  peers: [
106
- "https://gun-manhattan.herokuapp.com/gun",
107
- "https://gun-us.herokuapp.com/gun"
91
+ "https://gun-manhattan.herokuapp.com/gun"
108
92
  ],
109
-
110
- // OAuth provider configuration
93
+
94
+ // OAuth provider configuration (optional)
111
95
  oauth: {
112
96
  providers: {
113
97
  google: {
114
98
  clientId: "your-google-client-id",
115
- clientSecret: "your-google-client-secret",
116
- redirectUri: "https://myapp.com/auth/callback"
117
- },
118
- github: {
119
- clientId: "your-github-client-id",
120
99
  redirectUri: "https://myapp.com/auth/callback"
121
100
  }
122
101
  }
123
102
  },
124
-
125
- // Advanced plugin configuration
103
+
104
+ // Gun Advanced Plugin configuration
126
105
  enableGunDebug: true,
127
106
  enableConnectionMonitoring: true,
128
107
  defaultPageSize: 20,
129
108
  connectionTimeout: 10000,
130
-
131
- // Logging configuration
132
- logging: {
133
- enabled: true,
134
- level: "info" // "error" | "warning" | "info" | "debug"
135
- }
136
109
  });
137
110
  ```
138
111
 
@@ -146,12 +119,11 @@ The provider component that supplies Shogun context to your application.
146
119
 
147
120
  | Name | Type | Description | Required |
148
121
  |------|------|-------------|----------|
149
- | `sdk` | `ShogunCore` | Shogun SDK instance created by `shogunConnector` | ✅ |
122
+ | `core` | `ShogunCore` | Shogun SDK instance created by `shogunConnector` | ✅ |
150
123
  | `options` | `ShogunConnectorOptions` | Configuration options | ✅ |
151
124
  | `onLoginSuccess` | `(data: AuthData) => void` | Callback fired on successful login | ❌ |
152
125
  | `onSignupSuccess` | `(data: AuthData) => void` | Callback fired on successful signup | ❌ |
153
126
  | `onError` | `(error: string) => void` | Callback fired when an error occurs | ❌ |
154
- | `onLogout` | `() => void` | Callback fired when user logs out | ❌ |
155
127
 
156
128
  #### AuthData Interface
157
129
 
@@ -189,26 +161,26 @@ function UserProfile() {
189
161
  isLoggedIn,
190
162
  userPub,
191
163
  username,
192
-
164
+
193
165
  // Authentication methods
194
166
  login,
195
167
  signUp,
196
168
  logout,
197
-
169
+
198
170
  // Plugin management
199
171
  hasPlugin,
200
172
  getPlugin,
201
-
173
+
202
174
  // Account management
203
175
  exportGunPair,
204
176
  importGunPair,
205
-
177
+
206
178
  // Data operations
207
179
  observe,
208
180
  put,
209
181
  get,
210
182
  remove,
211
-
183
+
212
184
  // Advanced Gun hooks
213
185
  useGunState,
214
186
  useGunCollection,
@@ -302,12 +274,8 @@ function UserProfile() {
302
274
  </div>
303
275
 
304
276
  <div className="actions">
305
- <button onClick={handleExportAccount}>
306
- 🔒 Export Account
307
- </button>
308
- <button onClick={logout}>
309
- 🚪 Logout
310
- </button>
277
+ <button onClick={handleExportAccount}>Export Account</button>
278
+ <button onClick={logout}>Logout</button>
311
279
  </div>
312
280
  </div>
313
281
  );
@@ -509,29 +477,20 @@ Customize the appearance using CSS variables:
509
477
  interface ShogunConnectorOptions {
510
478
  // App information
511
479
  appName: string;
512
- appDescription?: string;
513
- appUrl?: string;
514
- appIcon?: string;
515
-
480
+
516
481
  // Feature toggles
517
482
  showMetamask?: boolean;
518
483
  showWebauthn?: boolean;
519
484
  showNostr?: boolean;
520
485
  showOauth?: boolean;
521
486
  darkMode?: boolean;
522
-
487
+
523
488
  // Network configuration
524
- websocketSecure?: boolean;
525
- providerUrl?: string | null;
526
489
  peers?: string[];
527
490
  authToken?: string;
528
491
  gunInstance?: IGunInstance<any>;
529
-
530
- // Advanced options
531
- logging?: {
532
- enabled: boolean;
533
- level: "error" | "warning" | "info" | "debug";
534
- };
492
+
493
+ // Timeouts and provider configs
535
494
  timeouts?: {
536
495
  login?: number;
537
496
  signup?: number;
@@ -540,11 +499,11 @@ interface ShogunConnectorOptions {
540
499
  oauth?: {
541
500
  providers: Record<string, {
542
501
  clientId: string;
543
- clientSecret?: string;
544
502
  redirectUri?: string;
545
- }>
503
+ clientSecret?: string;
504
+ }>;
546
505
  };
547
-
506
+
548
507
  // Gun Advanced Plugin configuration
549
508
  enableGunDebug?: boolean;
550
509
  enableConnectionMonitoring?: boolean;
@@ -558,8 +517,10 @@ interface ShogunConnectorOptions {
558
517
 
559
518
  ```typescript
560
519
  interface ShogunConnectorResult {
561
- sdk: ShogunCore;
520
+ core: ShogunCore;
562
521
  options: ShogunConnectorOptions;
522
+ setProvider: (provider: any) => boolean;
523
+ getCurrentProviderUrl: () => string | null;
563
524
  registerPlugin: (plugin: any) => boolean;
564
525
  hasPlugin: (name: string) => boolean;
565
526
  gunPlugin: GunAdvancedPlugin;
@@ -2,7 +2,6 @@ import React from "react";
2
2
  import { ShogunCore } from "shogun-core";
3
3
  import { Observable } from "rxjs";
4
4
  import { GunAdvancedPlugin } from "../plugins/GunAdvancedPlugin";
5
- import "../types/index.js";
6
5
  import "../styles/index.css";
7
6
  type ShogunContextType = {
8
7
  core: ShogunCore | null;
@@ -1,7 +1,6 @@
1
1
  import React, { useContext, useState, createContext, useEffect, useRef, } from "react";
2
2
  import { Observable } from "rxjs";
3
3
  import { GunAdvancedPlugin } from "../plugins/GunAdvancedPlugin";
4
- import "../types/index.js"; // Import type file to extend definitions
5
4
  import "../styles/index.css";
6
5
  // Default context
7
6
  const defaultShogunContext = {
@@ -624,8 +623,8 @@ export const ShogunButton = (() => {
624
623
  if (formMode === "signup") {
625
624
  const result = await signUp("password", formUsername, formPassword, formPasswordConfirm);
626
625
  if (result && result.success) {
627
- if (core === null || core === void 0 ? void 0 : core.gundb) {
628
- await core.gundb.setPasswordHint(formUsername, formPassword, formHint, [formSecurityQuestion], [formSecurityAnswer]);
626
+ if (core === null || core === void 0 ? void 0 : core.db) {
627
+ await core.db.setPasswordHint(formHint);
629
628
  }
630
629
  setModalIsOpen(false);
631
630
  }
@@ -658,10 +657,10 @@ export const ShogunButton = (() => {
658
657
  setError("");
659
658
  setLoading(true);
660
659
  try {
661
- if (!(core === null || core === void 0 ? void 0 : core.gundb)) {
660
+ if (!(core === null || core === void 0 ? void 0 : core.db)) {
662
661
  throw new Error("SDK not ready");
663
662
  }
664
- const result = await core.gundb.forgotPassword(formUsername, [
663
+ const result = await core.db.forgotPassword(formUsername, [
665
664
  formSecurityAnswer,
666
665
  ]);
667
666
  if (result.success && result.hint) {
package/dist/connector.js CHANGED
@@ -1,13 +1,18 @@
1
1
  import { ShogunCore } from "shogun-core";
2
2
  import { GunAdvancedPlugin } from "./plugins/GunAdvancedPlugin";
3
3
  export function shogunConnector(options) {
4
- const { peers = ["https://gun-manhattan.herokuapp.com/gun"], appName, logging, timeouts, oauth, enableGunDebug = true, enableConnectionMonitoring = true, defaultPageSize = 20, connectionTimeout = 10000, debounceInterval = 100, ...restOptions } = options;
4
+ const { peers = ["https://gun-manhattan.herokuapp.com/gun"], appName, timeouts, oauth, webauthn, nostr, web3, localStorage, radisk, showOauth, showWebauthn, showNostr, showMetamask, darkMode, authToken, enableGunDebug = true, enableConnectionMonitoring = true, defaultPageSize = 20, connectionTimeout = 10000, debounceInterval = 100, ...restOptions } = options;
5
5
  const core = new ShogunCore({
6
6
  peers,
7
7
  scope: appName,
8
- logging,
9
- timeouts,
10
8
  oauth,
9
+ webauthn,
10
+ nostr,
11
+ web3,
12
+ localStorage,
13
+ radisk,
14
+ authToken,
15
+ timeouts,
11
16
  });
12
17
  const setProvider = (provider) => {
13
18
  var _a;
@@ -69,7 +69,7 @@ export declare class GunAdvancedPlugin extends BasePlugin {
69
69
  key: string;
70
70
  };
71
71
  put(path: string, data: any): Promise<void>;
72
- get(path: string): any;
72
+ get(path: string): import("gun").IGunChain<any, import("gun").IGunInstance<any>, import("gun").IGunInstance<any>, string>;
73
73
  remove(path: string): Promise<void>;
74
74
  cleanup(): void;
75
75
  getStats(): {
@@ -46,8 +46,8 @@ export class GunAdvancedPlugin extends BasePlugin {
46
46
  return;
47
47
  setIsLoading(true);
48
48
  setError(null);
49
- const gunRef = this.core.gun.get(path);
50
- const off = gunRef.on((item) => {
49
+ const chain = this.core.gun.get(path);
50
+ const handler = (item) => {
51
51
  if (!isMounted.current)
52
52
  return;
53
53
  if (item) {
@@ -56,7 +56,8 @@ export class GunAdvancedPlugin extends BasePlugin {
56
56
  setError(null);
57
57
  this.log(`State updated for ${path}:`, item);
58
58
  }
59
- });
59
+ };
60
+ chain.on(handler);
60
61
  const timeoutId = setTimeout(() => {
61
62
  if (isLoading) {
62
63
  setError('Connection timeout - no data received');
@@ -65,8 +66,7 @@ export class GunAdvancedPlugin extends BasePlugin {
65
66
  }, this.config.connectionTimeout);
66
67
  return () => {
67
68
  isMounted.current = false;
68
- if (typeof off === 'function')
69
- off();
69
+ chain.off();
70
70
  clearTimeout(timeoutId);
71
71
  };
72
72
  }, [path]);
@@ -183,7 +183,7 @@ export class GunAdvancedPlugin extends BasePlugin {
183
183
  return;
184
184
  setIsLoading(true);
185
185
  setError(null);
186
- const gunRef = this.core.gun.get(path);
186
+ const chain = this.core.gun.get(path);
187
187
  const tempItems = [];
188
188
  const processItems = (items) => {
189
189
  if (!isMounted.current)
@@ -216,7 +216,7 @@ export class GunAdvancedPlugin extends BasePlugin {
216
216
  timestamp: Date.now()
217
217
  });
218
218
  };
219
- const off = gunRef.map().on((item, key) => {
219
+ const mapHandler = (item, key) => {
220
220
  if (item) {
221
221
  const itemWithKey = { ...item, _key: key };
222
222
  tempItems.push(itemWithKey);
@@ -224,7 +224,8 @@ export class GunAdvancedPlugin extends BasePlugin {
224
224
  processItems(tempItems);
225
225
  }
226
226
  }
227
- });
227
+ };
228
+ chain.map().on(mapHandler);
228
229
  const timeoutId = setTimeout(() => {
229
230
  if (isLoading) {
230
231
  setError('Connection timeout - no data received');
@@ -233,8 +234,7 @@ export class GunAdvancedPlugin extends BasePlugin {
233
234
  }, this.config.connectionTimeout);
234
235
  return () => {
235
236
  isMounted.current = false;
236
- if (typeof off === 'function')
237
- off();
237
+ chain.off();
238
238
  clearTimeout(timeoutId);
239
239
  };
240
240
  }, [path, currentPage, pageSize, sortBy, sortOrder, filter, enableRealtime]);
@@ -369,7 +369,7 @@ export class GunAdvancedPlugin extends BasePlugin {
369
369
  if (!this.config.enableConnectionMonitoring || !((_a = this.core) === null || _a === void 0 ? void 0 : _a.gun) || !this.core.isLoggedIn())
370
370
  return;
371
371
  let timeoutId;
372
- const gunRef = this.core.gun.get(path);
372
+ const chain = this.core.gun.get(path);
373
373
  const resetTimeout = () => {
374
374
  clearTimeout(timeoutId);
375
375
  timeoutId = window.setTimeout(() => {
@@ -378,19 +378,19 @@ export class GunAdvancedPlugin extends BasePlugin {
378
378
  this.log(`Connection timeout for ${path}`);
379
379
  }, this.config.connectionTimeout);
380
380
  };
381
- const off = gunRef.on(() => {
381
+ const handler = () => {
382
382
  setIsConnected(true);
383
383
  setLastSeen(new Date());
384
384
  setError(null);
385
385
  resetTimeout();
386
386
  this.log(`Connection active for ${path}`);
387
- });
387
+ };
388
+ chain.on(handler);
388
389
  resetTimeout();
389
- this.connectionMonitors.set(path, { off, timeoutId });
390
+ this.connectionMonitors.set(path, { off: () => chain.off(), timeoutId });
390
391
  return () => {
391
392
  clearTimeout(timeoutId);
392
- if (typeof off === 'function')
393
- off();
393
+ chain.off();
394
394
  this.connectionMonitors.delete(path);
395
395
  };
396
396
  }, [path]);
@@ -402,17 +402,17 @@ export class GunAdvancedPlugin extends BasePlugin {
402
402
  if (!enabled || !this.debugEnabled || !((_a = this.core) === null || _a === void 0 ? void 0 : _a.gun) || !this.core.isLoggedIn())
403
403
  return;
404
404
  this.log(`Debug mode enabled for ${path}`);
405
- const gunRef = this.core.gun.get(path);
406
- const off = gunRef.on((data, key) => {
405
+ const chain = this.core.gun.get(path);
406
+ const handler = (data, key) => {
407
407
  this.log(`[${path}] Update:`, {
408
408
  key,
409
409
  data,
410
410
  timestamp: new Date().toISOString(),
411
411
  });
412
- });
412
+ };
413
+ chain.on(handler);
413
414
  return () => {
414
- if (typeof off === 'function')
415
- off();
415
+ chain.off();
416
416
  this.log(`Debug mode disabled for ${path}`);
417
417
  };
418
418
  }, [path, enabled]);
@@ -424,8 +424,8 @@ export class GunAdvancedPlugin extends BasePlugin {
424
424
  var _a;
425
425
  if (!((_a = this.core) === null || _a === void 0 ? void 0 : _a.gun) || !this.core.isLoggedIn())
426
426
  return;
427
- const gunRef = this.core.gun.get(path);
428
- const off = gunRef.on((item, itemKey) => {
427
+ const chain = this.core.gun.get(path);
428
+ const handler = (item, itemKey) => {
429
429
  if (item) {
430
430
  setData(item);
431
431
  setKey(itemKey);
@@ -434,10 +434,10 @@ export class GunAdvancedPlugin extends BasePlugin {
434
434
  }
435
435
  this.log(`Realtime update for ${path}:`, { data: item, key: itemKey });
436
436
  }
437
- });
437
+ };
438
+ chain.on(handler);
438
439
  return () => {
439
- if (typeof off === 'function')
440
- off();
440
+ chain.off();
441
441
  };
442
442
  }, [path, callback]);
443
443
  return { data, key };
@@ -10,15 +10,9 @@ export interface ShogunConnectorOptions {
10
10
  showNostr?: boolean;
11
11
  showOauth?: boolean;
12
12
  darkMode?: boolean;
13
- websocketSecure?: boolean;
14
- providerUrl?: string | null;
15
13
  peers?: string[];
16
14
  authToken?: string;
17
15
  gunInstance?: IGunInstance<any>;
18
- logging?: {
19
- enabled: boolean;
20
- level: "error" | "warning" | "info" | "debug";
21
- };
22
16
  timeouts?: {
23
17
  login?: number;
24
18
  signup?: number;
@@ -31,6 +25,17 @@ export interface ShogunConnectorOptions {
31
25
  redirectUri?: string;
32
26
  }>;
33
27
  };
28
+ webauthn?: {
29
+ enabled?: boolean;
30
+ };
31
+ nostr?: {
32
+ enabled?: boolean;
33
+ };
34
+ web3?: {
35
+ enabled?: boolean;
36
+ };
37
+ localStorage?: boolean;
38
+ radisk?: boolean;
34
39
  enableGunDebug?: boolean;
35
40
  enableConnectionMonitoring?: boolean;
36
41
  defaultPageSize?: number;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "shogun-button-react",
3
3
  "description": "Shogun connector button",
4
- "version": "1.3.12",
4
+ "version": "1.3.14",
5
5
  "files": [
6
6
  "dist",
7
7
  "src/styles/index.css"
@@ -34,7 +34,7 @@
34
34
  "ethers": "^6.13.5",
35
35
  "prettier": "^3.5.3",
36
36
  "rxjs": "^7.8.1",
37
- "shogun-core": "^1.5.0"
37
+ "shogun-core": "^1.10.4"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "react": "^18.0.0",