shogun-core 2.0.4 → 3.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.
@@ -42,7 +42,7 @@ export interface PluginManager {
42
42
  * @returns Il plugin richiesto o undefined se non trovato
43
43
  * @template T Tipo del plugin o dell'interfaccia pubblica del plugin
44
44
  */
45
- getPlugin<T>(name: string): T | undefined;
45
+ getPlugin<T = ShogunPlugin>(name: string): T | undefined;
46
46
  /**
47
47
  * Verifica se un plugin è registrato
48
48
  * @param name Nome del plugin da verificare
@@ -55,4 +55,108 @@ export interface PluginManager {
55
55
  * @returns Array di plugin della categoria specificata
56
56
  */
57
57
  getPluginsByCategory(category: PluginCategory): ShogunPlugin[];
58
+ /**
59
+ * Ottiene informazioni su tutti i plugin registrati
60
+ * @returns Array di oggetti con informazioni sui plugin
61
+ */
62
+ getPluginsInfo(): Array<{
63
+ name: string;
64
+ version: string;
65
+ category?: PluginCategory;
66
+ description?: string;
67
+ }>;
68
+ /**
69
+ * Ottiene il numero totale di plugin registrati
70
+ * @returns Numero di plugin registrati
71
+ */
72
+ getPluginCount(): number;
73
+ /**
74
+ * Verifica se tutti i plugin sono inizializzati correttamente
75
+ * @returns Oggetto con stato di inizializzazione per ogni plugin
76
+ */
77
+ getPluginsInitializationStatus(): Record<string, {
78
+ initialized: boolean;
79
+ error?: string;
80
+ }>;
81
+ /**
82
+ * Valida l'integrità del sistema di plugin
83
+ * @returns Oggetto con risultati della validazione
84
+ */
85
+ validatePluginSystem(): {
86
+ totalPlugins: number;
87
+ initializedPlugins: number;
88
+ failedPlugins: string[];
89
+ warnings: string[];
90
+ };
91
+ /**
92
+ * Tenta di reinizializzare i plugin falliti
93
+ * @returns Oggetto con risultati della reinizializzazione
94
+ */
95
+ reinitializeFailedPlugins(): {
96
+ success: string[];
97
+ failed: Array<{
98
+ name: string;
99
+ error: string;
100
+ }>;
101
+ };
102
+ /**
103
+ * Verifica la compatibilità dei plugin con la versione corrente di ShogunCore
104
+ * @returns Oggetto con informazioni sulla compatibilità
105
+ */
106
+ checkPluginCompatibility(): {
107
+ compatible: Array<{
108
+ name: string;
109
+ version: string;
110
+ }>;
111
+ incompatible: Array<{
112
+ name: string;
113
+ version: string;
114
+ reason: string;
115
+ }>;
116
+ unknown: Array<{
117
+ name: string;
118
+ version: string;
119
+ }>;
120
+ };
121
+ /**
122
+ * Ottiene informazioni complete di debug sul sistema di plugin
123
+ * @returns Informazioni complete di debug del sistema di plugin
124
+ */
125
+ getPluginSystemDebugInfo(): {
126
+ shogunCoreVersion: string;
127
+ totalPlugins: number;
128
+ plugins: Array<{
129
+ name: string;
130
+ version: string;
131
+ category?: PluginCategory;
132
+ description?: string;
133
+ initialized: boolean;
134
+ error?: string;
135
+ }>;
136
+ initializationStatus: Record<string, {
137
+ initialized: boolean;
138
+ error?: string;
139
+ }>;
140
+ validation: {
141
+ totalPlugins: number;
142
+ initializedPlugins: number;
143
+ failedPlugins: string[];
144
+ warnings: string[];
145
+ };
146
+ compatibility: {
147
+ compatible: Array<{
148
+ name: string;
149
+ version: string;
150
+ }>;
151
+ incompatible: Array<{
152
+ name: string;
153
+ version: string;
154
+ reason: string;
155
+ }>;
156
+ unknown: Array<{
157
+ name: string;
158
+ version: string;
159
+ }>;
160
+ };
161
+ };
58
162
  }
@@ -1,10 +1,12 @@
1
- import { IGunInstance } from "gun/types";
1
+ import { GunInstance, GunUserInstance } from "../gundb/types";
2
+ import { ISEAPair } from "gun";
2
3
  import { ethers } from "ethers";
3
4
  import { ShogunError } from "../utils/errorHandler";
4
5
  import { DataBase } from "../gundb/db";
5
6
  import { RxJS } from "../gundb/rxjs";
6
7
  import { ShogunPlugin, PluginManager } from "./plugin";
7
8
  import { ShogunStorage } from "../storage/storage";
9
+ import { ShogunEventMap } from "./events";
8
10
  /**
9
11
  * Standard plugin categories in ShogunCore
10
12
  */
@@ -37,7 +39,7 @@ export declare enum CorePlugins {
37
39
  /** OAuth plugin */
38
40
  OAuth = "oauth"
39
41
  }
40
- export type AuthMethod = "password" | "webauthn" | "web3" | "nostr" | "oauth" | "bitcoin" | "pair";
42
+ export type AuthMethod = "password" | "webauthn" | "web3" | "nostr" | "oauth" | "pair";
41
43
  export interface AuthResult {
42
44
  success: boolean;
43
45
  error?: string;
@@ -112,28 +114,36 @@ export interface SignUpResult {
112
114
  };
113
115
  }
114
116
  export interface IShogunCore extends PluginManager {
115
- gun: IGunInstance<any>;
117
+ gun: GunInstance;
118
+ user: GunUserInstance | null;
116
119
  db: DataBase;
117
120
  rx: RxJS;
118
121
  storage: ShogunStorage;
119
122
  config: ShogunCoreConfig;
120
123
  provider?: ethers.Provider;
121
124
  signer?: ethers.Signer;
122
- on(eventName: string | symbol, listener: (...args: any[]) => void): any;
123
- off(eventName: string | symbol, listener: (...args: any[]) => void): any;
124
- once(eventName: string | symbol, listener: (...args: any[]) => void): any;
125
- removeAllListeners(eventName?: string | symbol): any;
126
- emit(eventName: string | symbol, ...args: any[]): boolean;
125
+ wallets?: Wallets;
126
+ pluginManager: any;
127
+ on<K extends keyof ShogunEventMap>(eventName: K, listener: ShogunEventMap[K] extends void ? () => void : (data: ShogunEventMap[K]) => void): this;
128
+ off<K extends keyof ShogunEventMap>(eventName: K, listener: ShogunEventMap[K] extends void ? () => void : (data: ShogunEventMap[K]) => void): this;
129
+ once<K extends keyof ShogunEventMap>(eventName: K, listener: ShogunEventMap[K] extends void ? () => void : (data: ShogunEventMap[K]) => void): this;
130
+ removeAllListeners(eventName?: string | symbol): this;
131
+ emit<K extends keyof ShogunEventMap>(eventName: K, data?: ShogunEventMap[K] extends void ? never : ShogunEventMap[K]): boolean;
127
132
  getRecentErrors(count?: number): ShogunError[];
128
- login(username: string, password: string): Promise<AuthResult>;
129
- signUp(username: string, password: string, passwordConfirmation?: string): Promise<SignUpResult>;
133
+ login(username: string, password: string, pair?: ISEAPair | null): Promise<AuthResult>;
134
+ loginWithPair(pair: ISEAPair): Promise<AuthResult>;
135
+ signUp(username: string, password?: string, pair?: ISEAPair | null): Promise<SignUpResult>;
130
136
  getAuthenticationMethod(type: AuthMethod): any;
137
+ setAuthMethod(method: AuthMethod): void;
138
+ getAuthMethod(): AuthMethod | undefined;
131
139
  getCurrentUser(): {
132
140
  pub: string;
133
141
  user?: any;
134
142
  } | null;
143
+ getIsLoggedIn(): boolean;
135
144
  logout(): void;
136
145
  isLoggedIn(): boolean;
146
+ saveCredentials(credentials: any): Promise<void>;
137
147
  }
138
148
  /**
139
149
  * WebAuthn configuration
@@ -150,12 +160,8 @@ export interface WebauthnConfig {
150
160
  * Shogun SDK configuration
151
161
  */
152
162
  export interface ShogunCoreConfig {
153
- gunInstance?: IGunInstance<any>;
154
- authToken?: string;
155
- scope?: string;
156
- peers?: string[];
157
- localStorage?: boolean;
158
- radisk?: boolean;
163
+ gunInstance?: GunInstance;
164
+ gunOptions?: any;
159
165
  webauthn?: WebauthnConfig;
160
166
  web3?: {
161
167
  enabled?: boolean;
@@ -0,0 +1,72 @@
1
+ import { IShogunCore, AuthResult, SignUpResult, AuthMethod } from "../interfaces/shogun";
2
+ import { ISEAPair } from "gun";
3
+ /**
4
+ * Manages authentication operations for ShogunCore
5
+ */
6
+ export declare class AuthManager {
7
+ private core;
8
+ private currentAuthMethod?;
9
+ constructor(core: IShogunCore);
10
+ /**
11
+ * Check if user is logged in
12
+ * @returns {boolean} True if user is logged in, false otherwise
13
+ * @description Verifies authentication status by checking GunInstance login state
14
+ * and presence of authentication credentials in storage
15
+ */
16
+ isLoggedIn(): boolean;
17
+ /**
18
+ * Perform user logout
19
+ * @description Logs out the current user from GunInstance and emits logout event.
20
+ * If user is not authenticated, the logout operation is ignored.
21
+ */
22
+ logout(): void;
23
+ /**
24
+ * Authenticate user with username and password
25
+ * @param username - Username
26
+ * @param password - User password
27
+ * @returns {Promise<AuthResult>} Promise with authentication result
28
+ * @description Attempts to log in user with provided credentials.
29
+ * Emits login event on success.
30
+ */
31
+ login(username: string, password: string, pair?: ISEAPair | null): Promise<AuthResult>;
32
+ /**
33
+ * Login with GunDB pair directly
34
+ * @param pair - GunDB SEA pair for authentication
35
+ * @returns {Promise<AuthResult>} Promise with authentication result
36
+ * @description Authenticates user using a GunDB pair directly.
37
+ * Emits login event on success.
38
+ */
39
+ loginWithPair(pair: ISEAPair): Promise<AuthResult>;
40
+ /**
41
+ * Register a new user with provided credentials
42
+ * @param username - Username
43
+ * @param password - Password
44
+ * @param email - Email (optional)
45
+ * @param pair - Pair of keys
46
+ * @returns {Promise<SignUpResult>} Registration result
47
+ * @description Creates a new user account with the provided credentials.
48
+ * Validates password requirements and emits signup event on success.
49
+ */
50
+ signUp(username: string, password?: string, pair?: ISEAPair | null): Promise<SignUpResult>;
51
+ /**
52
+ * Set the current authentication method
53
+ * This is used by plugins to indicate which authentication method was used
54
+ * @param method The authentication method used
55
+ */
56
+ setAuthMethod(method: AuthMethod): void;
57
+ /**
58
+ * Get the current authentication method
59
+ * @returns The current authentication method or undefined if not set
60
+ */
61
+ getAuthMethod(): AuthMethod | undefined;
62
+ /**
63
+ * Get an authentication method plugin by type
64
+ * @param type The type of authentication method
65
+ * @returns The authentication plugin or undefined if not available
66
+ * This is a more modern approach to accessing authentication methods
67
+ */
68
+ getAuthenticationMethod(type: AuthMethod): import("..").ShogunPlugin | {
69
+ login: (username: string, password: string) => Promise<AuthResult>;
70
+ signUp: (username: string, password: string, confirm?: string) => Promise<SignUpResult>;
71
+ } | undefined;
72
+ }
@@ -0,0 +1,40 @@
1
+ import { IShogunCore, ShogunCoreConfig } from "../interfaces/shogun";
2
+ /**
3
+ * Handles initialization of ShogunCore components
4
+ */
5
+ export declare class CoreInitializer {
6
+ private core;
7
+ constructor(core: IShogunCore);
8
+ /**
9
+ * Initialize the Shogun SDK
10
+ * @param config - SDK Configuration object
11
+ * @description Creates a new instance of ShogunCore with the provided configuration.
12
+ * Initializes all required components including storage, event emitter, GunInstance connection,
13
+ * and plugin system.
14
+ */
15
+ initialize(config: ShogunCoreConfig): Promise<void>;
16
+ /**
17
+ * Initialize Gun instance
18
+ */
19
+ private initializeGun;
20
+ /**
21
+ * Initialize Gun user
22
+ */
23
+ private initializeGunUser;
24
+ /**
25
+ * Setup Gun event forwarding
26
+ */
27
+ private setupGunEventForwarding;
28
+ /**
29
+ * Setup wallet derivation
30
+ */
31
+ private setupWalletDerivation;
32
+ /**
33
+ * Register built-in plugins based on configuration
34
+ */
35
+ private registerBuiltinPlugins;
36
+ /**
37
+ * Initialize async components
38
+ */
39
+ private initializeAsync;
40
+ }
@@ -0,0 +1,49 @@
1
+ import { ShogunEventEmitter, ShogunEventMap } from "../interfaces/events";
2
+ /**
3
+ * Manages event operations for ShogunCore
4
+ */
5
+ export declare class EventManager {
6
+ private eventEmitter;
7
+ constructor();
8
+ /**
9
+ * Emits an event through the core's event emitter.
10
+ * Plugins should use this method to emit events instead of accessing the private eventEmitter directly.
11
+ * @param eventName The name of the event to emit.
12
+ * @param data The data to pass with the event.
13
+ * @returns {boolean} Indicates if the event had listeners.
14
+ */
15
+ emit<K extends keyof ShogunEventMap>(eventName: K, data?: ShogunEventMap[K] extends void ? never : ShogunEventMap[K]): boolean;
16
+ /**
17
+ * Add an event listener
18
+ * @param eventName The name of the event to listen for
19
+ * @param listener The callback function to execute when the event is emitted
20
+ * @returns {this} Returns this instance for method chaining
21
+ */
22
+ on<K extends keyof ShogunEventMap>(eventName: K, listener: ShogunEventMap[K] extends void ? () => void : (data: ShogunEventMap[K]) => void): this;
23
+ /**
24
+ * Add a one-time event listener
25
+ * @param eventName The name of the event to listen for
26
+ * @param listener The callback function to execute when the event is emitted
27
+ * @returns {this} Returns this instance for method chaining
28
+ */
29
+ once<K extends keyof ShogunEventMap>(eventName: K, listener: ShogunEventMap[K] extends void ? () => void : (data: ShogunEventMap[K]) => void): this;
30
+ /**
31
+ * Remove an event listener
32
+ * @param eventName The name of the event to stop listening for
33
+ * @param listener The callback function to remove
34
+ * @returns {this} Returns this instance for method chaining
35
+ */
36
+ off<K extends keyof ShogunEventMap>(eventName: K, listener: ShogunEventMap[K] extends void ? () => void : (data: ShogunEventMap[K]) => void): this;
37
+ /**
38
+ * Remove all listeners for a specific event or all events
39
+ * @param eventName Optional. The name of the event to remove listeners for.
40
+ * If not provided, all listeners for all events are removed.
41
+ * @returns {this} Returns this instance for method chaining
42
+ */
43
+ removeAllListeners(eventName?: string | symbol): this;
44
+ /**
45
+ * Get the underlying event emitter instance
46
+ * @returns The ShogunEventEmitter instance
47
+ */
48
+ getEventEmitter(): ShogunEventEmitter;
49
+ }
@@ -0,0 +1,145 @@
1
+ import { ShogunPlugin } from "../interfaces/plugin";
2
+ import { PluginCategory } from "../interfaces/shogun";
3
+ import { IShogunCore } from "../interfaces/shogun";
4
+ /**
5
+ * Manages plugin registration, validation, and lifecycle
6
+ */
7
+ export declare class PluginManager {
8
+ private plugins;
9
+ private core;
10
+ constructor(core: IShogunCore);
11
+ /**
12
+ * Register a plugin with the Shogun SDK
13
+ * @param plugin Plugin instance to register
14
+ * @throws Error if a plugin with the same name is already registered
15
+ */
16
+ register(plugin: ShogunPlugin): void;
17
+ /**
18
+ * Unregister a plugin from the Shogun SDK
19
+ * @param name Name of the plugin to unregister
20
+ */
21
+ unregister(name: string): boolean;
22
+ /**
23
+ * Retrieve a registered plugin by name
24
+ * @param name Name of the plugin
25
+ * @returns The requested plugin or undefined if not found
26
+ * @template T Type of the plugin or its public interface
27
+ */
28
+ getPlugin<T = ShogunPlugin>(name: string): T | undefined;
29
+ /**
30
+ * Get information about all registered plugins
31
+ * @returns Array of plugin information objects
32
+ */
33
+ getPluginsInfo(): Array<{
34
+ name: string;
35
+ version: string;
36
+ category?: PluginCategory;
37
+ description?: string;
38
+ }>;
39
+ /**
40
+ * Get the total number of registered plugins
41
+ * @returns Number of registered plugins
42
+ */
43
+ getPluginCount(): number;
44
+ /**
45
+ * Check if all plugins are properly initialized
46
+ * @returns Object with initialization status for each plugin
47
+ */
48
+ getPluginsInitializationStatus(): Record<string, {
49
+ initialized: boolean;
50
+ error?: string;
51
+ }>;
52
+ /**
53
+ * Validate plugin system integrity
54
+ * @returns Object with validation results
55
+ */
56
+ validatePluginSystem(): {
57
+ totalPlugins: number;
58
+ initializedPlugins: number;
59
+ failedPlugins: string[];
60
+ warnings: string[];
61
+ };
62
+ /**
63
+ * Attempt to reinitialize failed plugins
64
+ * @returns Object with reinitialization results
65
+ */
66
+ reinitializeFailedPlugins(): {
67
+ success: string[];
68
+ failed: Array<{
69
+ name: string;
70
+ error: string;
71
+ }>;
72
+ };
73
+ /**
74
+ * Check plugin compatibility with current ShogunCore version
75
+ * @returns Object with compatibility information
76
+ */
77
+ checkPluginCompatibility(): {
78
+ compatible: Array<{
79
+ name: string;
80
+ version: string;
81
+ }>;
82
+ incompatible: Array<{
83
+ name: string;
84
+ version: string;
85
+ reason: string;
86
+ }>;
87
+ unknown: Array<{
88
+ name: string;
89
+ version: string;
90
+ }>;
91
+ };
92
+ /**
93
+ * Get comprehensive debug information about the plugin system
94
+ * @returns Complete plugin system debug information
95
+ */
96
+ getPluginSystemDebugInfo(): {
97
+ shogunCoreVersion: string;
98
+ totalPlugins: number;
99
+ plugins: Array<{
100
+ name: string;
101
+ version: string;
102
+ category?: PluginCategory;
103
+ description?: string;
104
+ initialized: boolean;
105
+ error?: string;
106
+ }>;
107
+ initializationStatus: Record<string, {
108
+ initialized: boolean;
109
+ error?: string;
110
+ }>;
111
+ validation: {
112
+ totalPlugins: number;
113
+ initializedPlugins: number;
114
+ failedPlugins: string[];
115
+ warnings: string[];
116
+ };
117
+ compatibility: {
118
+ compatible: Array<{
119
+ name: string;
120
+ version: string;
121
+ }>;
122
+ incompatible: Array<{
123
+ name: string;
124
+ version: string;
125
+ reason: string;
126
+ }>;
127
+ unknown: Array<{
128
+ name: string;
129
+ version: string;
130
+ }>;
131
+ };
132
+ };
133
+ /**
134
+ * Check if a plugin is registered
135
+ * @param name Name of the plugin to check
136
+ * @returns true if the plugin is registered, false otherwise
137
+ */
138
+ hasPlugin(name: string): boolean;
139
+ /**
140
+ * Get all plugins of a specific category
141
+ * @param category Category of plugins to filter
142
+ * @returns Array of plugins in the specified category
143
+ */
144
+ getPluginsByCategory(category: PluginCategory): ShogunPlugin[];
145
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Migration test file to verify that the refactored ShogunCore
3
+ * maintains the same public API as the original implementation
4
+ */
5
+ /**
6
+ * Test function to verify API compatibility
7
+ */
8
+ export declare function testApiCompatibility(): void;
9
+ /**
10
+ * Test that the refactored implementation maintains the same static properties
11
+ */
12
+ export declare function testStaticProperties(): void;
13
+ /**
14
+ * Run all compatibility tests
15
+ */
16
+ export declare function runCompatibilityTests(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shogun-core",
3
- "version": "2.0.4",
3
+ "version": "3.0.1",
4
4
  "description": "SHOGUN CORE - Core library for Shogun Ecosystem",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",