shogun-core 3.0.4 → 3.0.5
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/browser/shogun-core.js +92134 -0
- package/dist/browser/shogun-core.js.map +1 -0
- package/dist/config/simplified-config.js +230 -0
- package/dist/core.js +338 -0
- package/dist/gundb/crypto.js +268 -0
- package/dist/gundb/db.js +1833 -0
- package/dist/gundb/derive.js +229 -0
- package/dist/gundb/errors.js +66 -0
- package/dist/gundb/index.js +6 -0
- package/dist/gundb/restricted-put.js +81 -0
- package/dist/gundb/rxjs.js +445 -0
- package/dist/gundb/simple-api.js +438 -0
- package/dist/gundb/types.js +4 -0
- package/dist/index.js +16 -0
- package/dist/interfaces/common.js +1 -0
- package/dist/interfaces/events.js +36 -0
- package/dist/interfaces/plugin.js +1 -0
- package/dist/interfaces/shogun.js +34 -0
- package/dist/managers/AuthManager.js +225 -0
- package/dist/managers/CoreInitializer.js +240 -0
- package/dist/managers/EventManager.js +67 -0
- package/dist/managers/PluginManager.js +296 -0
- package/dist/migration-test.js +91 -0
- package/dist/plugins/base.js +47 -0
- package/dist/plugins/index.js +15 -0
- package/dist/plugins/nostr/index.js +4 -0
- package/dist/plugins/nostr/nostrConnector.js +413 -0
- package/dist/plugins/nostr/nostrConnectorPlugin.js +446 -0
- package/dist/plugins/nostr/nostrSigner.js +313 -0
- package/dist/plugins/nostr/types.js +1 -0
- package/dist/plugins/oauth/index.js +3 -0
- package/dist/plugins/oauth/oauthConnector.js +753 -0
- package/dist/plugins/oauth/oauthPlugin.js +396 -0
- package/dist/plugins/oauth/types.js +1 -0
- package/dist/plugins/web3/index.js +4 -0
- package/dist/plugins/web3/types.js +1 -0
- package/dist/plugins/web3/web3Connector.js +528 -0
- package/dist/plugins/web3/web3ConnectorPlugin.js +448 -0
- package/dist/plugins/web3/web3Signer.js +308 -0
- package/dist/plugins/webauthn/index.js +3 -0
- package/dist/plugins/webauthn/types.js +11 -0
- package/dist/plugins/webauthn/webauthn.js +478 -0
- package/dist/plugins/webauthn/webauthnPlugin.js +398 -0
- package/dist/plugins/webauthn/webauthnSigner.js +304 -0
- package/dist/storage/storage.js +147 -0
- package/dist/types/config/simplified-config.d.ts +114 -0
- package/dist/types/core.d.ts +305 -0
- package/dist/types/gundb/crypto.d.ts +95 -0
- package/dist/types/gundb/db.d.ts +404 -0
- package/dist/types/gundb/derive.d.ts +21 -0
- package/dist/types/gundb/errors.d.ts +42 -0
- package/dist/types/gundb/index.d.ts +3 -0
- package/dist/types/gundb/restricted-put.d.ts +15 -0
- package/dist/types/gundb/rxjs.d.ts +110 -0
- package/dist/types/gundb/simple-api.d.ts +90 -0
- package/dist/types/gundb/types.d.ts +264 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/interfaces/common.d.ts +85 -0
- package/dist/types/interfaces/events.d.ts +131 -0
- package/dist/types/interfaces/plugin.d.ts +162 -0
- package/dist/types/interfaces/shogun.d.ts +215 -0
- package/dist/types/managers/AuthManager.d.ts +72 -0
- package/dist/types/managers/CoreInitializer.d.ts +40 -0
- package/dist/types/managers/EventManager.d.ts +49 -0
- package/dist/types/managers/PluginManager.d.ts +145 -0
- package/dist/types/migration-test.d.ts +16 -0
- package/dist/types/plugins/base.d.ts +35 -0
- package/dist/types/plugins/index.d.ts +14 -0
- package/dist/types/plugins/nostr/index.d.ts +4 -0
- package/dist/types/plugins/nostr/nostrConnector.d.ts +119 -0
- package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +163 -0
- package/dist/types/plugins/nostr/nostrSigner.d.ts +105 -0
- package/dist/types/plugins/nostr/types.d.ts +122 -0
- package/dist/types/plugins/oauth/index.d.ts +3 -0
- package/dist/types/plugins/oauth/oauthConnector.d.ts +110 -0
- package/dist/types/plugins/oauth/oauthPlugin.d.ts +91 -0
- package/dist/types/plugins/oauth/types.d.ts +114 -0
- package/dist/types/plugins/web3/index.d.ts +4 -0
- package/dist/types/plugins/web3/types.d.ts +107 -0
- package/dist/types/plugins/web3/web3Connector.d.ts +129 -0
- package/dist/types/plugins/web3/web3ConnectorPlugin.d.ts +160 -0
- package/dist/types/plugins/web3/web3Signer.d.ts +114 -0
- package/dist/types/plugins/webauthn/index.d.ts +3 -0
- package/dist/types/plugins/webauthn/types.d.ts +162 -0
- package/dist/types/plugins/webauthn/webauthn.d.ts +129 -0
- package/dist/types/plugins/webauthn/webauthnPlugin.d.ts +158 -0
- package/dist/types/plugins/webauthn/webauthnSigner.d.ts +91 -0
- package/dist/types/storage/storage.d.ts +50 -0
- package/dist/types/utils/errorHandler.d.ts +119 -0
- package/dist/types/utils/eventEmitter.d.ts +39 -0
- package/dist/types/utils/validation.d.ts +27 -0
- package/dist/utils/errorHandler.js +241 -0
- package/dist/utils/eventEmitter.js +76 -0
- package/dist/utils/validation.js +72 -0
- package/package.json +1 -1
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manages plugin registration, validation, and lifecycle
|
|
3
|
+
*/
|
|
4
|
+
export class PluginManager {
|
|
5
|
+
plugins = new Map();
|
|
6
|
+
core;
|
|
7
|
+
constructor(core) {
|
|
8
|
+
this.core = core;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Register a plugin with the Shogun SDK
|
|
12
|
+
* @param plugin Plugin instance to register
|
|
13
|
+
* @throws Error if a plugin with the same name is already registered
|
|
14
|
+
*/
|
|
15
|
+
register(plugin) {
|
|
16
|
+
try {
|
|
17
|
+
if (!plugin.name) {
|
|
18
|
+
if (typeof console !== "undefined" && console.error) {
|
|
19
|
+
console.error("Plugin registration failed: Plugin must have a name");
|
|
20
|
+
}
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (this.plugins.has(plugin.name)) {
|
|
24
|
+
if (typeof console !== "undefined" && console.warn) {
|
|
25
|
+
console.warn(`Plugin "${plugin.name}" is already registered. Skipping.`);
|
|
26
|
+
}
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
// Initialize plugin with core instance
|
|
30
|
+
plugin.initialize(this.core);
|
|
31
|
+
this.plugins.set(plugin.name, plugin);
|
|
32
|
+
this.core.emit("plugin:registered", {
|
|
33
|
+
name: plugin.name,
|
|
34
|
+
version: plugin.version || "unknown",
|
|
35
|
+
category: plugin._category || "unknown",
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (typeof console !== "undefined" && console.error) {
|
|
40
|
+
console.error(`Error registering plugin "${plugin.name}":`, error);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Unregister a plugin from the Shogun SDK
|
|
46
|
+
* @param name Name of the plugin to unregister
|
|
47
|
+
*/
|
|
48
|
+
unregister(name) {
|
|
49
|
+
try {
|
|
50
|
+
const plugin = this.plugins.get(name);
|
|
51
|
+
if (!plugin) {
|
|
52
|
+
if (typeof console !== "undefined" && console.warn) {
|
|
53
|
+
console.warn(`Plugin "${name}" not found for unregistration`);
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
// Destroy plugin if it has a destroy method
|
|
58
|
+
if (typeof plugin.destroy === "function") {
|
|
59
|
+
try {
|
|
60
|
+
plugin.destroy();
|
|
61
|
+
}
|
|
62
|
+
catch (destroyError) {
|
|
63
|
+
if (typeof console !== "undefined" && console.error) {
|
|
64
|
+
console.error(`Error destroying plugin "${name}":`, destroyError);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
this.plugins.delete(name);
|
|
69
|
+
this.core.emit("plugin:unregistered", {
|
|
70
|
+
name: plugin.name,
|
|
71
|
+
});
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
if (typeof console !== "undefined" && console.error) {
|
|
76
|
+
console.error(`Error unregistering plugin "${name}":`, error);
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Retrieve a registered plugin by name
|
|
83
|
+
* @param name Name of the plugin
|
|
84
|
+
* @returns The requested plugin or undefined if not found
|
|
85
|
+
* @template T Type of the plugin or its public interface
|
|
86
|
+
*/
|
|
87
|
+
getPlugin(name) {
|
|
88
|
+
if (!name || typeof name !== "string") {
|
|
89
|
+
if (typeof console !== "undefined" && console.warn) {
|
|
90
|
+
console.warn("Invalid plugin name provided to getPlugin");
|
|
91
|
+
}
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
const plugin = this.plugins.get(name);
|
|
95
|
+
if (!plugin) {
|
|
96
|
+
if (typeof console !== "undefined" && console.warn) {
|
|
97
|
+
console.warn(`Plugin "${name}" not found`);
|
|
98
|
+
}
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
return plugin;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Get information about all registered plugins
|
|
105
|
+
* @returns Array of plugin information objects
|
|
106
|
+
*/
|
|
107
|
+
getPluginsInfo() {
|
|
108
|
+
const pluginsInfo = [];
|
|
109
|
+
this.plugins.forEach((plugin) => {
|
|
110
|
+
pluginsInfo.push({
|
|
111
|
+
name: plugin.name,
|
|
112
|
+
version: plugin.version || "unknown",
|
|
113
|
+
category: plugin._category,
|
|
114
|
+
description: plugin.description,
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
return pluginsInfo;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Get the total number of registered plugins
|
|
121
|
+
* @returns Number of registered plugins
|
|
122
|
+
*/
|
|
123
|
+
getPluginCount() {
|
|
124
|
+
return this.plugins.size;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Check if all plugins are properly initialized
|
|
128
|
+
* @returns Object with initialization status for each plugin
|
|
129
|
+
*/
|
|
130
|
+
getPluginsInitializationStatus() {
|
|
131
|
+
const status = {};
|
|
132
|
+
this.plugins.forEach((plugin, name) => {
|
|
133
|
+
try {
|
|
134
|
+
// Verifica se il plugin ha un metodo per controllare l'inizializzazione
|
|
135
|
+
if (typeof plugin.assertInitialized === "function") {
|
|
136
|
+
plugin.assertInitialized();
|
|
137
|
+
status[name] = { initialized: true };
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
// Fallback: verifica se il plugin ha un riferimento al core
|
|
141
|
+
status[name] = {
|
|
142
|
+
initialized: !!plugin.core,
|
|
143
|
+
error: !plugin.core
|
|
144
|
+
? "No core reference found"
|
|
145
|
+
: undefined,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
status[name] = {
|
|
151
|
+
initialized: false,
|
|
152
|
+
error: error instanceof Error ? error.message : String(error),
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
return status;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Validate plugin system integrity
|
|
160
|
+
* @returns Object with validation results
|
|
161
|
+
*/
|
|
162
|
+
validatePluginSystem() {
|
|
163
|
+
const status = this.getPluginsInitializationStatus();
|
|
164
|
+
const totalPlugins = Object.keys(status).length;
|
|
165
|
+
const initializedPlugins = Object.values(status).filter((s) => s.initialized).length;
|
|
166
|
+
const failedPlugins = Object.entries(status)
|
|
167
|
+
.filter(([_, s]) => !s.initialized)
|
|
168
|
+
.map(([name, _]) => name);
|
|
169
|
+
const warnings = [];
|
|
170
|
+
if (totalPlugins === 0) {
|
|
171
|
+
warnings.push("No plugins registered");
|
|
172
|
+
}
|
|
173
|
+
if (failedPlugins.length > 0) {
|
|
174
|
+
warnings.push(`Failed plugins: ${failedPlugins.join(", ")}`);
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
totalPlugins,
|
|
178
|
+
initializedPlugins,
|
|
179
|
+
failedPlugins,
|
|
180
|
+
warnings,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Attempt to reinitialize failed plugins
|
|
185
|
+
* @returns Object with reinitialization results
|
|
186
|
+
*/
|
|
187
|
+
reinitializeFailedPlugins() {
|
|
188
|
+
const status = this.getPluginsInitializationStatus();
|
|
189
|
+
const failedPlugins = Object.entries(status)
|
|
190
|
+
.filter(([_, s]) => !s.initialized)
|
|
191
|
+
.map(([name, _]) => name);
|
|
192
|
+
const success = [];
|
|
193
|
+
const failed = [];
|
|
194
|
+
failedPlugins.forEach((pluginName) => {
|
|
195
|
+
try {
|
|
196
|
+
const plugin = this.plugins.get(pluginName);
|
|
197
|
+
if (!plugin) {
|
|
198
|
+
failed.push({ name: pluginName, error: "Plugin not found" });
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
// Reinizializza il plugin
|
|
202
|
+
plugin.initialize(this.core);
|
|
203
|
+
success.push(pluginName);
|
|
204
|
+
}
|
|
205
|
+
catch (error) {
|
|
206
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
207
|
+
failed.push({ name: pluginName, error: errorMessage });
|
|
208
|
+
if (typeof console !== "undefined" && console.error) {
|
|
209
|
+
console.error(`[PluginManager] Failed to reinitialize plugin ${pluginName}:`, error);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
return { success, failed };
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Check plugin compatibility with current ShogunCore version
|
|
217
|
+
* @returns Object with compatibility information
|
|
218
|
+
*/
|
|
219
|
+
checkPluginCompatibility() {
|
|
220
|
+
const compatible = [];
|
|
221
|
+
const incompatible = [];
|
|
222
|
+
const unknown = [];
|
|
223
|
+
this.plugins.forEach((plugin) => {
|
|
224
|
+
const pluginInfo = {
|
|
225
|
+
name: plugin.name,
|
|
226
|
+
version: plugin.version || "unknown",
|
|
227
|
+
};
|
|
228
|
+
// Verifica se il plugin ha informazioni di compatibilità
|
|
229
|
+
if (typeof plugin.getCompatibilityInfo === "function") {
|
|
230
|
+
try {
|
|
231
|
+
const compatibilityInfo = plugin.getCompatibilityInfo();
|
|
232
|
+
if (compatibilityInfo && compatibilityInfo.compatible) {
|
|
233
|
+
compatible.push(pluginInfo);
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
incompatible.push({
|
|
237
|
+
...pluginInfo,
|
|
238
|
+
reason: compatibilityInfo?.reason || "Unknown compatibility issue",
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
unknown.push(pluginInfo);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
// Se non ha informazioni di compatibilità, considera sconosciuto
|
|
248
|
+
unknown.push(pluginInfo);
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
return { compatible, incompatible, unknown };
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Get comprehensive debug information about the plugin system
|
|
255
|
+
* @returns Complete plugin system debug information
|
|
256
|
+
*/
|
|
257
|
+
getPluginSystemDebugInfo() {
|
|
258
|
+
const pluginsInfo = this.getPluginsInfo();
|
|
259
|
+
const initializationStatus = this.getPluginsInitializationStatus();
|
|
260
|
+
const plugins = pluginsInfo.map((info) => ({
|
|
261
|
+
...info,
|
|
262
|
+
initialized: initializationStatus[info.name]?.initialized || false,
|
|
263
|
+
error: initializationStatus[info.name]?.error,
|
|
264
|
+
}));
|
|
265
|
+
return {
|
|
266
|
+
shogunCoreVersion: "^1.6.6",
|
|
267
|
+
totalPlugins: this.getPluginCount(),
|
|
268
|
+
plugins,
|
|
269
|
+
initializationStatus,
|
|
270
|
+
validation: this.validatePluginSystem(),
|
|
271
|
+
compatibility: this.checkPluginCompatibility(),
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Check if a plugin is registered
|
|
276
|
+
* @param name Name of the plugin to check
|
|
277
|
+
* @returns true if the plugin is registered, false otherwise
|
|
278
|
+
*/
|
|
279
|
+
hasPlugin(name) {
|
|
280
|
+
return this.plugins.has(name);
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Get all plugins of a specific category
|
|
284
|
+
* @param category Category of plugins to filter
|
|
285
|
+
* @returns Array of plugins in the specified category
|
|
286
|
+
*/
|
|
287
|
+
getPluginsByCategory(category) {
|
|
288
|
+
const result = [];
|
|
289
|
+
this.plugins.forEach((plugin) => {
|
|
290
|
+
if (plugin._category === category) {
|
|
291
|
+
result.push(plugin);
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
return result;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration test file to verify that the refactored ShogunCore
|
|
3
|
+
* maintains the same public API as the original implementation
|
|
4
|
+
*/
|
|
5
|
+
import { ShogunCore } from "./core";
|
|
6
|
+
import { ShogunCore as OriginalShogunCore } from "./core";
|
|
7
|
+
/**
|
|
8
|
+
* Test function to verify API compatibility
|
|
9
|
+
*/
|
|
10
|
+
export function testApiCompatibility() {
|
|
11
|
+
const config = {
|
|
12
|
+
gunOptions: {
|
|
13
|
+
peers: ["https://gunjs.herokuapp.com/gun"],
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
// Test that both implementations can be instantiated with the same config
|
|
17
|
+
const originalCore = new OriginalShogunCore(config);
|
|
18
|
+
const refactoredCore = new ShogunCore(config);
|
|
19
|
+
// Test that all public methods exist on both implementations
|
|
20
|
+
const publicMethods = [
|
|
21
|
+
// Plugin management
|
|
22
|
+
"register",
|
|
23
|
+
"unregister",
|
|
24
|
+
"getPlugin",
|
|
25
|
+
"getPluginsInfo",
|
|
26
|
+
"getPluginCount",
|
|
27
|
+
"getPluginsInitializationStatus",
|
|
28
|
+
"validatePluginSystem",
|
|
29
|
+
"reinitializeFailedPlugins",
|
|
30
|
+
"checkPluginCompatibility",
|
|
31
|
+
"getPluginSystemDebugInfo",
|
|
32
|
+
"hasPlugin",
|
|
33
|
+
"getPluginsByCategory",
|
|
34
|
+
"getAuthenticationMethod",
|
|
35
|
+
// Error handling
|
|
36
|
+
"getRecentErrors",
|
|
37
|
+
// Authentication
|
|
38
|
+
"isLoggedIn",
|
|
39
|
+
"logout",
|
|
40
|
+
"login",
|
|
41
|
+
"loginWithPair",
|
|
42
|
+
"signUp",
|
|
43
|
+
// Event management
|
|
44
|
+
"emit",
|
|
45
|
+
"on",
|
|
46
|
+
"once",
|
|
47
|
+
"off",
|
|
48
|
+
"removeAllListeners",
|
|
49
|
+
// Auth method management
|
|
50
|
+
"setAuthMethod",
|
|
51
|
+
"getAuthMethod",
|
|
52
|
+
// Storage
|
|
53
|
+
"saveCredentials",
|
|
54
|
+
"getIsLoggedIn",
|
|
55
|
+
// Getters
|
|
56
|
+
"getCurrentUser",
|
|
57
|
+
];
|
|
58
|
+
const missingMethods = [];
|
|
59
|
+
publicMethods.forEach((method) => {
|
|
60
|
+
if (typeof refactoredCore[method] !== "function") {
|
|
61
|
+
missingMethods.push(method);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
if (missingMethods.length > 0) {
|
|
65
|
+
throw new Error(`Missing methods in refactored implementation: ${missingMethods.join(", ")}`);
|
|
66
|
+
}
|
|
67
|
+
console.log("✅ API compatibility test passed - all public methods are present");
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Test that the refactored implementation maintains the same static properties
|
|
71
|
+
*/
|
|
72
|
+
export function testStaticProperties() {
|
|
73
|
+
if (ShogunCore.API_VERSION !== OriginalShogunCore.API_VERSION) {
|
|
74
|
+
throw new Error("API_VERSION mismatch between implementations");
|
|
75
|
+
}
|
|
76
|
+
console.log("✅ Static properties test passed");
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Run all compatibility tests
|
|
80
|
+
*/
|
|
81
|
+
export function runCompatibilityTests() {
|
|
82
|
+
try {
|
|
83
|
+
testStaticProperties();
|
|
84
|
+
testApiCompatibility();
|
|
85
|
+
console.log("🎉 All compatibility tests passed! The refactored implementation is ready.");
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
console.error("❌ Compatibility test failed:", error);
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { EventEmitter } from "../utils/eventEmitter";
|
|
2
|
+
/**
|
|
3
|
+
* Classe base per tutti i plugin di ShogunCore
|
|
4
|
+
* Fornisce funzionalità comuni e implementazione base dell'interfaccia ShogunPlugin
|
|
5
|
+
*/
|
|
6
|
+
export class BasePlugin extends EventEmitter {
|
|
7
|
+
/** Descrizione opzionale del plugin */
|
|
8
|
+
description;
|
|
9
|
+
/** Categoria del plugin */
|
|
10
|
+
_category;
|
|
11
|
+
/** Riferimento all'istanza di ShogunCore */
|
|
12
|
+
core = null;
|
|
13
|
+
/**
|
|
14
|
+
* Inizializza il plugin con un'istanza di ShogunCore
|
|
15
|
+
* @param core Istanza di ShogunCore
|
|
16
|
+
*/
|
|
17
|
+
initialize(core) {
|
|
18
|
+
this.core = core;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Distrugge il plugin e libera le risorse
|
|
22
|
+
*/
|
|
23
|
+
destroy() {
|
|
24
|
+
try {
|
|
25
|
+
// Emetti evento di distruzione
|
|
26
|
+
this.emit("destroyed", {
|
|
27
|
+
name: this.name,
|
|
28
|
+
version: this.version,
|
|
29
|
+
});
|
|
30
|
+
this.core = null;
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
console.error(`[${this.name}] Error during plugin destruction:`, error);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Verifica che il plugin sia stato inizializzato prima di usare il core
|
|
38
|
+
* @throws Error se il plugin non è stato inizializzato
|
|
39
|
+
* @returns L'istanza di ShogunCore non null
|
|
40
|
+
*/
|
|
41
|
+
assertInitialized() {
|
|
42
|
+
if (!this.core) {
|
|
43
|
+
throw new Error(`Plugin ${this.name} not initialized`);
|
|
44
|
+
}
|
|
45
|
+
return this.core;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Base plugin interface and types
|
|
2
|
+
export { BasePlugin } from "./base";
|
|
3
|
+
// WebAuthn plugin exports
|
|
4
|
+
export { Webauthn } from "./webauthn/webauthn";
|
|
5
|
+
export { WebauthnPlugin } from "./webauthn/webauthnPlugin";
|
|
6
|
+
// Ethereum plugin exports
|
|
7
|
+
export { Web3Connector } from "./web3/web3Connector";
|
|
8
|
+
export { Web3ConnectorPlugin } from "./web3/web3ConnectorPlugin";
|
|
9
|
+
// Bitcoin plugin exports
|
|
10
|
+
export { NostrConnector } from "./nostr/nostrConnector";
|
|
11
|
+
export { NostrConnectorPlugin } from "./nostr/nostrConnectorPlugin";
|
|
12
|
+
// OAuth plugin exports
|
|
13
|
+
export { OAuthConnector } from "./oauth/oauthConnector";
|
|
14
|
+
export { OAuthPlugin } from "./oauth/oauthPlugin";
|
|
15
|
+
export * from "./oauth/types";
|