shogun-core 3.0.2 → 3.0.4

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.
Files changed (95) hide show
  1. package/package.json +1 -1
  2. package/dist/browser/shogun-core.js +0 -92128
  3. package/dist/browser/shogun-core.js.map +0 -1
  4. package/dist/config/simplified-config.js +0 -230
  5. package/dist/core.js +0 -338
  6. package/dist/gundb/crypto.js +0 -268
  7. package/dist/gundb/db.js +0 -1833
  8. package/dist/gundb/derive.js +0 -229
  9. package/dist/gundb/errors.js +0 -66
  10. package/dist/gundb/index.js +0 -6
  11. package/dist/gundb/restricted-put.js +0 -81
  12. package/dist/gundb/rxjs.js +0 -445
  13. package/dist/gundb/simple-api.js +0 -438
  14. package/dist/gundb/types.js +0 -4
  15. package/dist/index.js +0 -16
  16. package/dist/interfaces/common.js +0 -1
  17. package/dist/interfaces/events.js +0 -36
  18. package/dist/interfaces/plugin.js +0 -1
  19. package/dist/interfaces/shogun.js +0 -34
  20. package/dist/managers/AuthManager.js +0 -225
  21. package/dist/managers/CoreInitializer.js +0 -234
  22. package/dist/managers/EventManager.js +0 -67
  23. package/dist/managers/PluginManager.js +0 -296
  24. package/dist/migration-test.js +0 -91
  25. package/dist/plugins/base.js +0 -47
  26. package/dist/plugins/index.js +0 -15
  27. package/dist/plugins/nostr/index.js +0 -4
  28. package/dist/plugins/nostr/nostrConnector.js +0 -413
  29. package/dist/plugins/nostr/nostrConnectorPlugin.js +0 -446
  30. package/dist/plugins/nostr/nostrSigner.js +0 -313
  31. package/dist/plugins/nostr/types.js +0 -1
  32. package/dist/plugins/oauth/index.js +0 -3
  33. package/dist/plugins/oauth/oauthConnector.js +0 -753
  34. package/dist/plugins/oauth/oauthPlugin.js +0 -396
  35. package/dist/plugins/oauth/types.js +0 -1
  36. package/dist/plugins/web3/index.js +0 -4
  37. package/dist/plugins/web3/types.js +0 -1
  38. package/dist/plugins/web3/web3Connector.js +0 -528
  39. package/dist/plugins/web3/web3ConnectorPlugin.js +0 -448
  40. package/dist/plugins/web3/web3Signer.js +0 -308
  41. package/dist/plugins/webauthn/index.js +0 -3
  42. package/dist/plugins/webauthn/types.js +0 -11
  43. package/dist/plugins/webauthn/webauthn.js +0 -478
  44. package/dist/plugins/webauthn/webauthnPlugin.js +0 -398
  45. package/dist/plugins/webauthn/webauthnSigner.js +0 -304
  46. package/dist/storage/storage.js +0 -147
  47. package/dist/types/config/simplified-config.d.ts +0 -114
  48. package/dist/types/core.d.ts +0 -305
  49. package/dist/types/gundb/crypto.d.ts +0 -95
  50. package/dist/types/gundb/db.d.ts +0 -404
  51. package/dist/types/gundb/derive.d.ts +0 -21
  52. package/dist/types/gundb/errors.d.ts +0 -42
  53. package/dist/types/gundb/index.d.ts +0 -3
  54. package/dist/types/gundb/restricted-put.d.ts +0 -15
  55. package/dist/types/gundb/rxjs.d.ts +0 -110
  56. package/dist/types/gundb/simple-api.d.ts +0 -90
  57. package/dist/types/gundb/types.d.ts +0 -264
  58. package/dist/types/index.d.ts +0 -14
  59. package/dist/types/interfaces/common.d.ts +0 -85
  60. package/dist/types/interfaces/events.d.ts +0 -131
  61. package/dist/types/interfaces/plugin.d.ts +0 -162
  62. package/dist/types/interfaces/shogun.d.ts +0 -214
  63. package/dist/types/managers/AuthManager.d.ts +0 -72
  64. package/dist/types/managers/CoreInitializer.d.ts +0 -40
  65. package/dist/types/managers/EventManager.d.ts +0 -49
  66. package/dist/types/managers/PluginManager.d.ts +0 -145
  67. package/dist/types/migration-test.d.ts +0 -16
  68. package/dist/types/plugins/base.d.ts +0 -35
  69. package/dist/types/plugins/index.d.ts +0 -14
  70. package/dist/types/plugins/nostr/index.d.ts +0 -4
  71. package/dist/types/plugins/nostr/nostrConnector.d.ts +0 -119
  72. package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +0 -163
  73. package/dist/types/plugins/nostr/nostrSigner.d.ts +0 -105
  74. package/dist/types/plugins/nostr/types.d.ts +0 -122
  75. package/dist/types/plugins/oauth/index.d.ts +0 -3
  76. package/dist/types/plugins/oauth/oauthConnector.d.ts +0 -110
  77. package/dist/types/plugins/oauth/oauthPlugin.d.ts +0 -91
  78. package/dist/types/plugins/oauth/types.d.ts +0 -114
  79. package/dist/types/plugins/web3/index.d.ts +0 -4
  80. package/dist/types/plugins/web3/types.d.ts +0 -107
  81. package/dist/types/plugins/web3/web3Connector.d.ts +0 -129
  82. package/dist/types/plugins/web3/web3ConnectorPlugin.d.ts +0 -160
  83. package/dist/types/plugins/web3/web3Signer.d.ts +0 -114
  84. package/dist/types/plugins/webauthn/index.d.ts +0 -3
  85. package/dist/types/plugins/webauthn/types.d.ts +0 -162
  86. package/dist/types/plugins/webauthn/webauthn.d.ts +0 -129
  87. package/dist/types/plugins/webauthn/webauthnPlugin.d.ts +0 -158
  88. package/dist/types/plugins/webauthn/webauthnSigner.d.ts +0 -91
  89. package/dist/types/storage/storage.d.ts +0 -50
  90. package/dist/types/utils/errorHandler.d.ts +0 -119
  91. package/dist/types/utils/eventEmitter.d.ts +0 -39
  92. package/dist/types/utils/validation.d.ts +0 -27
  93. package/dist/utils/errorHandler.js +0 -241
  94. package/dist/utils/eventEmitter.js +0 -76
  95. package/dist/utils/validation.js +0 -72
@@ -1,230 +0,0 @@
1
- /**
2
- * Simplified configuration options to reduce complexity
3
- * Provides sensible defaults and easy-to-use presets
4
- */
5
- /**
6
- * Preset configurations for common use cases
7
- */
8
- export const ShogunPresets = {
9
- /**
10
- * Minimal configuration for simple apps
11
- */
12
- minimal: () => ({
13
- gunOptions: {
14
- peers: ["https://gunjs.herokuapp.com/gun"],
15
- localStorage: true,
16
- },
17
- }),
18
- /**
19
- * Development configuration with local storage
20
- */
21
- development: () => ({
22
- gunOptions: {
23
- peers: ["https://gunjs.herokuapp.com/gun"],
24
- localStorage: true,
25
- radisk: false,
26
- },
27
- timeouts: {
28
- login: 5000,
29
- signup: 5000,
30
- operation: 3000,
31
- },
32
- }),
33
- /**
34
- * Production configuration with multiple peers
35
- */
36
- production: (customPeers) => ({
37
- gunOptions: {
38
- peers: customPeers || [
39
- "https://gunjs.herokuapp.com/gun",
40
- "https://gun-manhattan.herokuapp.com/gun",
41
- ],
42
- localStorage: true,
43
- radisk: true,
44
- },
45
- timeouts: {
46
- login: 10000,
47
- signup: 10000,
48
- operation: 5000,
49
- },
50
- }),
51
- /**
52
- * Offline-first configuration
53
- */
54
- offline: () => ({
55
- gunOptions: {
56
- peers: [],
57
- localStorage: true,
58
- radisk: true,
59
- },
60
- }),
61
- /**
62
- * Web3-enabled configuration
63
- */
64
- web3: () => ({
65
- gunOptions: {
66
- peers: ["https://gunjs.herokuapp.com/gun"],
67
- localStorage: true,
68
- },
69
- web3: {
70
- enabled: true,
71
- },
72
- }),
73
- /**
74
- * WebAuthn-enabled configuration
75
- */
76
- webauthn: () => ({
77
- gunOptions: {
78
- peers: ["https://gunjs.herokuapp.com/gun"],
79
- localStorage: true,
80
- },
81
- webauthn: {
82
- enabled: true,
83
- rpName: "My Shogun App",
84
- rpId: window.location.hostname,
85
- },
86
- }),
87
- };
88
- /**
89
- * Configuration builder for custom setups
90
- */
91
- export class ShogunConfigBuilder {
92
- config = {};
93
- /**
94
- * Set Gun options
95
- */
96
- gunOptions(options) {
97
- this.config.gunOptions = { ...this.config.gunOptions, ...options };
98
- return this;
99
- }
100
- /**
101
- * Add peers
102
- */
103
- peers(peerList) {
104
- this.config.gunOptions = {
105
- ...this.config.gunOptions,
106
- peers: [...(this.config.gunOptions?.peers || []), ...peerList],
107
- };
108
- return this;
109
- }
110
- /**
111
- * Enable WebAuthn
112
- */
113
- enableWebAuthn(rpName, rpId) {
114
- this.config.webauthn = {
115
- enabled: true,
116
- rpName: rpName || "My App",
117
- rpId: rpId || window.location.hostname,
118
- };
119
- return this;
120
- }
121
- /**
122
- * Enable Web3
123
- */
124
- enableWeb3() {
125
- this.config.web3 = { enabled: true };
126
- return this;
127
- }
128
- /**
129
- * Enable Nostr
130
- */
131
- enableNostr() {
132
- this.config.nostr = { enabled: true };
133
- return this;
134
- }
135
- /**
136
- * Set timeouts
137
- */
138
- timeouts(timeouts) {
139
- this.config.timeouts = { ...this.config.timeouts, ...timeouts };
140
- return this;
141
- }
142
- /**
143
- * Build the final configuration
144
- */
145
- build() {
146
- return this.config;
147
- }
148
- }
149
- /**
150
- * Helper functions for common configuration patterns
151
- */
152
- export const ConfigHelpers = {
153
- /**
154
- * Create a configuration for a specific environment
155
- */
156
- forEnvironment(env) {
157
- switch (env) {
158
- case "development":
159
- return ShogunPresets.development();
160
- case "production":
161
- return ShogunPresets.production();
162
- case "test":
163
- return ShogunPresets.offline();
164
- default:
165
- return ShogunPresets.minimal();
166
- }
167
- },
168
- /**
169
- * Create a configuration with custom peers
170
- */
171
- withPeers(peers) {
172
- return ShogunPresets.production(peers);
173
- },
174
- /**
175
- * Create a configuration for a specific use case
176
- */
177
- forUseCase(useCase) {
178
- const baseConfig = ShogunPresets.production();
179
- switch (useCase) {
180
- case "chat":
181
- return {
182
- ...baseConfig,
183
- timeouts: { ...baseConfig.timeouts, operation: 2000 },
184
- };
185
- case "social":
186
- return {
187
- ...baseConfig,
188
- webauthn: { enabled: true, rpName: "Social App" },
189
- };
190
- case "gaming":
191
- return {
192
- ...baseConfig,
193
- timeouts: { ...baseConfig.timeouts, operation: 1000 },
194
- };
195
- case "finance":
196
- return {
197
- ...baseConfig,
198
- webauthn: { enabled: true, rpName: "Finance App" },
199
- timeouts: { ...baseConfig.timeouts, login: 15000 },
200
- };
201
- default:
202
- return baseConfig;
203
- }
204
- },
205
- };
206
- /**
207
- * Quick configuration functions
208
- */
209
- export const QuickConfig = {
210
- /**
211
- * Minimal setup for quick testing
212
- */
213
- test: () => ShogunPresets.minimal(),
214
- /**
215
- * Standard setup for most apps
216
- */
217
- standard: () => ShogunPresets.production(),
218
- /**
219
- * Setup with WebAuthn for secure apps
220
- */
221
- secure: () => ShogunPresets.webauthn(),
222
- /**
223
- * Setup with Web3 for crypto apps
224
- */
225
- crypto: () => ShogunPresets.web3(),
226
- /**
227
- * Offline setup for local development
228
- */
229
- local: () => ShogunPresets.offline(),
230
- };
package/dist/core.js DELETED
@@ -1,338 +0,0 @@
1
- import { ErrorHandler } from "./utils/errorHandler";
2
- // Import managers
3
- import { PluginManager } from "./managers/PluginManager";
4
- import { AuthManager } from "./managers/AuthManager";
5
- import { EventManager } from "./managers/EventManager";
6
- import { CoreInitializer } from "./managers/CoreInitializer";
7
- /**
8
- * Main ShogunCore class - implements the IShogunCore interface
9
- *
10
- * This is the primary entry point for the Shogun SDK, providing access to:
11
- * - Decentralized database (GunInstance)
12
- * - Authentication methods (traditional, WebAuthn, MetaMask)
13
- * - Plugin system for extensibility
14
- * - RxJS integration for reactive programming
15
- *
16
- * @since 2.0.0
17
- */
18
- export class ShogunCore {
19
- static API_VERSION = "^3.0.1";
20
- db;
21
- storage;
22
- provider;
23
- config;
24
- rx;
25
- _gun;
26
- _user = null;
27
- wallets;
28
- // Managers
29
- pluginManager;
30
- authManager;
31
- eventManager;
32
- coreInitializer;
33
- /**
34
- * Initialize the Shogun SDK
35
- * @param config - SDK Configuration object
36
- * @description Creates a new instance of ShogunCore with the provided configuration.
37
- * Initializes all required components including storage, event emitter, GunInstance connection,
38
- * and plugin system.
39
- */
40
- constructor(config) {
41
- this.config = config;
42
- // Initialize managers
43
- this.eventManager = new EventManager();
44
- this.pluginManager = new PluginManager(this);
45
- this.authManager = new AuthManager(this);
46
- this.coreInitializer = new CoreInitializer(this);
47
- // Initialize async components
48
- this.coreInitializer.initialize(config).catch((error) => {
49
- if (typeof console !== "undefined" && console.warn) {
50
- console.warn("Error during async initialization:", error);
51
- }
52
- });
53
- }
54
- /**
55
- * Access to the Gun instance
56
- * @returns The Gun instance
57
- */
58
- get gun() {
59
- return this._gun;
60
- }
61
- /**
62
- * Access to the current user
63
- * @returns The current Gun user instance
64
- */
65
- get user() {
66
- return this._user;
67
- }
68
- /**
69
- * Gets the current user information
70
- * @returns Current user object or null
71
- */
72
- getCurrentUser() {
73
- if (!this.db) {
74
- return null;
75
- }
76
- return this.db.getCurrentUser();
77
- }
78
- // *********************************************************************************************************
79
- // 🔌 PLUGIN MANAGEMENT 🔌
80
- // *********************************************************************************************************
81
- /**
82
- * Registers a plugin with the Shogun SDK
83
- * @param plugin Plugin instance to register
84
- * @throws Error if a plugin with the same name is already registered
85
- */
86
- register(plugin) {
87
- this.pluginManager.register(plugin);
88
- }
89
- /**
90
- * Unregisters a plugin from the Shogun SDK
91
- * @param pluginName Name of the plugin to unregister
92
- */
93
- unregister(pluginName) {
94
- this.pluginManager.unregister(pluginName);
95
- }
96
- /**
97
- * Retrieve a registered plugin by name
98
- * @param name Name of the plugin
99
- * @returns The requested plugin or undefined if not found
100
- * @template T Type of the plugin or its public interface
101
- */
102
- getPlugin(name) {
103
- return this.pluginManager.getPlugin(name);
104
- }
105
- /**
106
- * Get information about all registered plugins
107
- * @returns Array of plugin information objects
108
- */
109
- getPluginsInfo() {
110
- return this.pluginManager.getPluginsInfo();
111
- }
112
- /**
113
- * Get the total number of registered plugins
114
- * @returns Number of registered plugins
115
- */
116
- getPluginCount() {
117
- return this.pluginManager.getPluginCount();
118
- }
119
- /**
120
- * Check if all plugins are properly initialized
121
- * @returns Object with initialization status for each plugin
122
- */
123
- getPluginsInitializationStatus() {
124
- return this.pluginManager.getPluginsInitializationStatus();
125
- }
126
- /**
127
- * Validate plugin system integrity
128
- * @returns Object with validation results
129
- */
130
- validatePluginSystem() {
131
- return this.pluginManager.validatePluginSystem();
132
- }
133
- /**
134
- * Attempt to reinitialize failed plugins
135
- * @returns Object with reinitialization results
136
- */
137
- reinitializeFailedPlugins() {
138
- return this.pluginManager.reinitializeFailedPlugins();
139
- }
140
- /**
141
- * Check plugin compatibility with current ShogunCore version
142
- * @returns Object with compatibility information
143
- */
144
- checkPluginCompatibility() {
145
- return this.pluginManager.checkPluginCompatibility();
146
- }
147
- /**
148
- * Get comprehensive debug information about the plugin system
149
- * @returns Complete plugin system debug information
150
- */
151
- getPluginSystemDebugInfo() {
152
- return this.pluginManager.getPluginSystemDebugInfo();
153
- }
154
- /**
155
- * Check if a plugin is registered
156
- * @param name Name of the plugin to check
157
- * @returns true if the plugin is registered, false otherwise
158
- */
159
- hasPlugin(name) {
160
- return this.pluginManager.hasPlugin(name);
161
- }
162
- /**
163
- * Get all plugins of a specific category
164
- * @param category Category of plugins to filter
165
- * @returns Array of plugins in the specified category
166
- */
167
- getPluginsByCategory(category) {
168
- return this.pluginManager.getPluginsByCategory(category);
169
- }
170
- /**
171
- * Get an authentication method plugin by type
172
- * @param type The type of authentication method
173
- * @returns The authentication plugin or undefined if not available
174
- * This is a more modern approach to accessing authentication methods
175
- */
176
- getAuthenticationMethod(type) {
177
- return this.authManager.getAuthenticationMethod(type);
178
- }
179
- // *********************************************************************************************************
180
- // 🔐 ERROR HANDLER 🔐
181
- // *********************************************************************************************************
182
- /**
183
- * Retrieve recent errors logged by the system
184
- * @param count - Number of errors to retrieve (default: 10)
185
- * @returns List of most recent errors
186
- */
187
- getRecentErrors(count = 10) {
188
- return ErrorHandler.getRecentErrors(count);
189
- }
190
- // *********************************************************************************************************
191
- // 🔐 AUTHENTICATION
192
- // *********************************************************************************************************
193
- /**
194
- * Check if user is logged in
195
- * @returns {boolean} True if user is logged in, false otherwise
196
- * @description Verifies authentication status by checking GunInstance login state
197
- * and presence of authentication credentials in storage
198
- */
199
- isLoggedIn() {
200
- return this.authManager.isLoggedIn();
201
- }
202
- /**
203
- * Perform user logout
204
- * @description Logs out the current user from GunInstance and emits logout event.
205
- * If user is not authenticated, the logout operation is ignored.
206
- */
207
- logout() {
208
- this.authManager.logout();
209
- }
210
- /**
211
- * Authenticate user with username and password
212
- * @param username - Username
213
- * @param password - User password
214
- * @returns {Promise<AuthResult>} Promise with authentication result
215
- * @description Attempts to log in user with provided credentials.
216
- * Emits login event on success.
217
- */
218
- async login(username, password, pair) {
219
- return this.authManager.login(username, password, pair);
220
- }
221
- /**
222
- * Login with GunDB pair directly
223
- * @param pair - GunDB SEA pair for authentication
224
- * @returns {Promise<AuthResult>} Promise with authentication result
225
- * @description Authenticates user using a GunDB pair directly.
226
- * Emits login event on success.
227
- */
228
- async loginWithPair(pair) {
229
- return this.authManager.loginWithPair(pair);
230
- }
231
- /**
232
- * Register a new user with provided credentials
233
- * @param username - Username
234
- * @param password - Password
235
- * @param email - Email (optional)
236
- * @param pair - Pair of keys
237
- * @returns {Promise<SignUpResult>} Registration result
238
- * @description Creates a new user account with the provided credentials.
239
- * Validates password requirements and emits signup event on success.
240
- */
241
- async signUp(username, password, pair) {
242
- return this.authManager.signUp(username, password, pair);
243
- }
244
- // 📢 EVENT EMITTER 📢
245
- /**
246
- * Emits an event through the core's event emitter.
247
- * Plugins should use this method to emit events instead of accessing the private eventEmitter directly.
248
- * @param eventName The name of the event to emit.
249
- * @param data The data to pass with the event.
250
- * @returns {boolean} Indicates if the event had listeners.
251
- */
252
- emit(eventName, data) {
253
- return this.eventManager.emit(eventName, data);
254
- }
255
- /**
256
- * Add an event listener
257
- * @param eventName The name of the event to listen for
258
- * @param listener The callback function to execute when the event is emitted
259
- * @returns {this} Returns this instance for method chaining
260
- */
261
- on(eventName, listener) {
262
- this.eventManager.on(eventName, listener);
263
- return this;
264
- }
265
- /**
266
- * Add a one-time event listener
267
- * @param eventName The name of the event to listen for
268
- * @param listener The callback function to execute when the event is emitted
269
- * @returns {this} Returns this instance for method chaining
270
- */
271
- once(eventName, listener) {
272
- this.eventManager.once(eventName, listener);
273
- return this;
274
- }
275
- /**
276
- * Remove an event listener
277
- * @param eventName The name of the event to stop listening for
278
- * @param listener The callback function to remove
279
- * @returns {this} Returns this instance for method chaining
280
- */
281
- off(eventName, listener) {
282
- this.eventManager.off(eventName, listener);
283
- return this;
284
- }
285
- /**
286
- * Remove all listeners for a specific event or all events
287
- * @param eventName Optional. The name of the event to remove listeners for.
288
- * If not provided, all listeners for all events are removed.
289
- * @returns {this} Returns this instance for method chaining
290
- */
291
- removeAllListeners(eventName) {
292
- this.eventManager.removeAllListeners(eventName);
293
- return this;
294
- }
295
- /**
296
- * Set the current authentication method
297
- * This is used by plugins to indicate which authentication method was used
298
- * @param method The authentication method used
299
- */
300
- setAuthMethod(method) {
301
- this.authManager.setAuthMethod(method);
302
- }
303
- /**
304
- * Get the current authentication method
305
- * @returns The current authentication method or undefined if not set
306
- */
307
- getAuthMethod() {
308
- return this.authManager.getAuthMethod();
309
- }
310
- /**
311
- * Saves the current user credentials to storage
312
- */
313
- async saveCredentials(credentials) {
314
- try {
315
- this.storage.setItem("userCredentials", JSON.stringify(credentials));
316
- }
317
- catch (error) {
318
- if (typeof console !== "undefined" && console.warn) {
319
- console.warn("Failed to save credentials to storage");
320
- }
321
- if (typeof console !== "undefined" && console.error) {
322
- console.error(`Error saving credentials:`, error);
323
- }
324
- }
325
- }
326
- getIsLoggedIn() {
327
- return !!(this.user && this.user.is);
328
- }
329
- }
330
- // Global declarations are handled in the original core.ts file
331
- // to avoid conflicts, we only set the window properties here
332
- if (typeof window !== "undefined") {
333
- window.SHOGUN_CORE = (config) => {
334
- return new ShogunCore(config);
335
- };
336
- window.SHOGUN_CORE_CLASS = ShogunCore;
337
- }
338
- export default ShogunCore;