shogun-button-react 1.10.3 → 1.11.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/dist/connector.js CHANGED
@@ -1,53 +1,64 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.shogunConnector = shogunConnector;
4
- const shogun_core_1 = require("shogun-core");
5
- function shogunConnector(options) {
6
- const { peers = ["https://relay.shogun-eco.xyz/gun"], appName, timeouts, oauth, showMetamask, showWebauthn, showNostr, showOauth, localStorage, radisk, ...restOptions } = options;
7
- // Build ShogunCore configuration with authentication plugins
8
- const shogunConfig = {
1
+ import { ShogunCore } from "shogun-core";
2
+ import { GunAdvancedPlugin } from "./plugins/GunAdvancedPlugin";
3
+ export function shogunConnector(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
+ const core = new ShogunCore({
9
6
  peers,
10
7
  scope: appName,
11
- timeouts,
8
+ oauth,
9
+ webauthn,
10
+ nostr,
11
+ web3,
12
12
  localStorage,
13
13
  radisk,
14
- };
15
- // Configure Web3/MetaMask plugin
16
- if (showMetamask) {
17
- shogunConfig.web3 = { enabled: true };
18
- console.log("✅ Web3 plugin configured");
19
- }
20
- // Configure WebAuthn plugin
21
- if (showWebauthn) {
22
- shogunConfig.webauthn = {
23
- enabled: true,
24
- rpName: appName || "Shogun App",
25
- rpId: typeof window !== "undefined" ? window.location.hostname : "localhost",
26
- };
27
- console.log("✅ WebAuthn plugin configured");
28
- }
29
- // Configure Nostr plugin
30
- if (showNostr) {
31
- shogunConfig.nostr = { enabled: true };
32
- console.log("✅ Nostr plugin configured");
33
- }
34
- // Configure OAuth plugin
35
- if (showOauth && oauth) {
36
- shogunConfig.oauth = {
37
- enabled: true,
38
- usePKCE: true, // Mandatory for security
39
- allowUnsafeClientSecret: true, // Required for Google OAuth
40
- ...oauth,
41
- };
42
- console.log("✅ OAuth plugin configured");
43
- }
44
- console.log("🔧 Creating ShogunCore with config:", {
45
- showMetamask,
46
- showWebauthn,
47
- showNostr,
48
- showOauth,
14
+ authToken,
15
+ timeouts,
49
16
  });
50
- const core = new shogun_core_1.ShogunCore(shogunConfig);
17
+ const setProvider = (provider) => {
18
+ var _a;
19
+ if (!core) {
20
+ return false;
21
+ }
22
+ try {
23
+ let newProviderUrl = null;
24
+ if (provider && provider.connection && provider.connection.url) {
25
+ newProviderUrl = provider.connection.url;
26
+ }
27
+ else if (typeof provider === "string") {
28
+ newProviderUrl = provider;
29
+ }
30
+ if (newProviderUrl) {
31
+ const gun = ((_a = core === null || core === void 0 ? void 0 : core.db) === null || _a === void 0 ? void 0 : _a.gun) || (core === null || core === void 0 ? void 0 : core.gun);
32
+ if (gun && typeof gun.opt === "function") {
33
+ try {
34
+ gun.opt({ peers: [newProviderUrl] });
35
+ return true;
36
+ }
37
+ catch (e) {
38
+ console.error("Error adding peer via gun.opt:", e);
39
+ return false;
40
+ }
41
+ }
42
+ }
43
+ return false;
44
+ }
45
+ catch (error) {
46
+ console.error("Error setting provider:", error);
47
+ return false;
48
+ }
49
+ };
50
+ const getCurrentProviderUrl = () => {
51
+ var _a;
52
+ const gun = ((_a = core === null || core === void 0 ? void 0 : core.db) === null || _a === void 0 ? void 0 : _a.gun) || (core === null || core === void 0 ? void 0 : core.gun);
53
+ try {
54
+ const peersObj = gun && gun.back ? gun.back('opt.peers') : undefined;
55
+ const urls = peersObj && typeof peersObj === 'object' ? Object.keys(peersObj) : [];
56
+ return urls.length > 0 ? urls[0] : null;
57
+ }
58
+ catch {
59
+ return null;
60
+ }
61
+ };
51
62
  const registerPlugin = (plugin) => {
52
63
  if (core && typeof core.register === "function") {
53
64
  try {
@@ -64,10 +75,29 @@ function shogunConnector(options) {
64
75
  const hasPlugin = (name) => {
65
76
  return core ? core.hasPlugin(name) : false;
66
77
  };
78
+ // Registra automaticamente il plugin Gun avanzato
79
+ let gunPlugin = null;
80
+ if (core) {
81
+ gunPlugin = new GunAdvancedPlugin(core, {
82
+ enableDebug: enableGunDebug,
83
+ enableConnectionMonitoring,
84
+ defaultPageSize,
85
+ connectionTimeout,
86
+ debounceInterval,
87
+ });
88
+ registerPlugin(gunPlugin);
89
+ }
90
+ // Ensure gunPlugin is always available
91
+ if (!gunPlugin) {
92
+ throw new Error("Failed to initialize GunAdvancedPlugin");
93
+ }
67
94
  return {
68
95
  core,
69
96
  options,
97
+ setProvider,
98
+ getCurrentProviderUrl,
70
99
  registerPlugin,
71
100
  hasPlugin,
101
+ gunPlugin,
72
102
  };
73
103
  }
@@ -445,36 +445,10 @@
445
445
  border-radius: 6px;
446
446
  background-color: transparent;
447
447
  transition: all 0.2s ease;
448
- cursor: pointer;
449
- display: inline-block;
450
- text-decoration: none;
451
- font-size: 14px;
452
- line-height: 1.4;
453
- min-height: 44px;
454
- display: flex;
455
- align-items: center;
456
- justify-content: center;
457
448
  }
458
449
 
459
450
  .shogun-prominent-toggle:hover {
460
451
  text-decoration: underline;
461
- background-color: rgba(59, 130, 246, 0.1);
462
- transform: translateY(-1px);
463
- }
464
-
465
- .shogun-prominent-toggle:active {
466
- transform: translateY(0);
467
- }
468
-
469
- .shogun-prominent-toggle:disabled {
470
- opacity: 0.5;
471
- cursor: not-allowed;
472
- pointer-events: none;
473
- }
474
-
475
- .shogun-prominent-toggle:focus {
476
- outline: 2px solid var(--shogun-primary);
477
- outline-offset: 2px;
478
452
  }
479
453
 
480
454
  /* Redundant dark theme styles removed */
package/dist/index.d.ts CHANGED
@@ -1,6 +1,9 @@
1
- import { ShogunButton, ShogunButtonProvider, useShogun } from "./components/ShogunButton";
2
- import { ShogunConnectorOptions, ShogunConnectorResult } from "./types/connector-options";
3
- import { shogunConnector } from "./connector";
1
+ import { ShogunButton, ShogunButtonProvider, useShogun } from './components/ShogunButton';
2
+ import { ShogunConnectorOptions, ShogunConnectorResult } from './types/connector-options';
3
+ import { shogunConnector } from './connector';
4
+ import { GunAdvancedPlugin } from './plugins/GunAdvancedPlugin';
4
5
  export { ShogunButton, ShogunButtonProvider, useShogun };
5
6
  export { shogunConnector };
7
+ export * from './types/connector-options';
6
8
  export { ShogunConnectorOptions, ShogunConnectorResult };
9
+ export { GunAdvancedPlugin };
package/dist/index.js CHANGED
@@ -1,9 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.shogunConnector = exports.useShogun = exports.ShogunButtonProvider = exports.ShogunButton = void 0;
4
- const ShogunButton_1 = require("./components/ShogunButton");
5
- Object.defineProperty(exports, "ShogunButton", { enumerable: true, get: function () { return ShogunButton_1.ShogunButton; } });
6
- Object.defineProperty(exports, "ShogunButtonProvider", { enumerable: true, get: function () { return ShogunButton_1.ShogunButtonProvider; } });
7
- Object.defineProperty(exports, "useShogun", { enumerable: true, get: function () { return ShogunButton_1.useShogun; } });
8
- const connector_1 = require("./connector");
9
- Object.defineProperty(exports, "shogunConnector", { enumerable: true, get: function () { return connector_1.shogunConnector; } });
1
+ import { ShogunButton, ShogunButtonProvider, useShogun } from './components/ShogunButton';
2
+ import { shogunConnector } from './connector';
3
+ import { GunAdvancedPlugin } from './plugins/GunAdvancedPlugin';
4
+ // Export components
5
+ export { ShogunButton, ShogunButtonProvider, useShogun };
6
+ // Export connector function
7
+ export { shogunConnector };
8
+ // Export all types
9
+ export * from './types/connector-options';
10
+ export { GunAdvancedPlugin };
@@ -0,0 +1,81 @@
1
+ import { ShogunCore, BasePlugin } from "shogun-core";
2
+ export interface GunAdvancedPluginConfig {
3
+ enableDebug?: boolean;
4
+ enableConnectionMonitoring?: boolean;
5
+ defaultPageSize?: number;
6
+ connectionTimeout?: number;
7
+ debounceInterval?: number;
8
+ }
9
+ export interface GunCollectionOptions<T> {
10
+ pageSize?: number;
11
+ sortBy?: keyof T | ((a: T, b: T) => number);
12
+ sortOrder?: 'asc' | 'desc';
13
+ filter?: (item: T) => boolean;
14
+ enableRealtime?: boolean;
15
+ }
16
+ export interface GunCollectionResult<T> {
17
+ items: T[];
18
+ currentPage: number;
19
+ totalPages: number;
20
+ hasNextPage: boolean;
21
+ hasPrevPage: boolean;
22
+ nextPage: () => void;
23
+ prevPage: () => void;
24
+ goToPage: (page: number) => void;
25
+ isLoading: boolean;
26
+ error: string | null;
27
+ refresh: () => void;
28
+ addItem: (item: T) => Promise<void>;
29
+ updateItem: (id: string, updates: Partial<T>) => Promise<void>;
30
+ removeItem: (id: string) => Promise<void>;
31
+ }
32
+ export interface GunStateResult<T> {
33
+ data: T | null;
34
+ isLoading: boolean;
35
+ error: string | null;
36
+ update: (updates: Partial<T>) => Promise<void>;
37
+ set: (data: T) => Promise<void>;
38
+ remove: () => Promise<void>;
39
+ refresh: () => void;
40
+ }
41
+ export declare class GunAdvancedPlugin extends BasePlugin {
42
+ version: string;
43
+ readonly name = "gun-advanced";
44
+ core: ShogunCore;
45
+ private config;
46
+ private debugEnabled;
47
+ private connectionMonitors;
48
+ private collectionCache;
49
+ constructor(core: ShogunCore, config?: GunAdvancedPluginConfig);
50
+ setDebugEnabled(enabled: boolean): void;
51
+ private log;
52
+ createHooks(): {
53
+ useGunState: any;
54
+ useGunCollection: any;
55
+ useGunConnection: any;
56
+ useGunDebug: any;
57
+ useGunRealtime: any;
58
+ };
59
+ useGunState<T>(path: string, defaultValue?: T): GunStateResult<T>;
60
+ useGunCollection<T>(path: string, options?: GunCollectionOptions<T>): GunCollectionResult<T>;
61
+ useGunConnection(path: string): {
62
+ isConnected: boolean;
63
+ lastSeen: Date;
64
+ error: string;
65
+ };
66
+ useGunDebug(path: string, enabled?: boolean): void;
67
+ useGunRealtime<T>(path: string, callback?: (data: T, key: string) => void): {
68
+ data: T;
69
+ key: string;
70
+ };
71
+ put(path: string, data: any): Promise<void>;
72
+ get(path: string): import("gun").IGunChain<any, import("gun").IGunInstance<any>, import("gun").IGunInstance<any>, string>;
73
+ remove(path: string): Promise<void>;
74
+ cleanup(): void;
75
+ getStats(): {
76
+ activeConnections: number;
77
+ cachedCollections: number;
78
+ debugEnabled: boolean;
79
+ config: GunAdvancedPluginConfig;
80
+ };
81
+ }