shogun-core 3.0.3 → 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 -215
  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,438 +0,0 @@
1
- /**
2
- * Simplified API layer to reduce complexity for common use cases
3
- * Provides quick-start methods that wrap the full DataBase functionality
4
- */
5
- import { DataBase } from "./db";
6
- /**
7
- * Simple API wrapper that provides common operations with minimal complexity
8
- */
9
- export class SimpleGunAPI {
10
- db;
11
- constructor(db) {
12
- this.db = db;
13
- }
14
- /**
15
- * Quick data operations - simplified interface
16
- */
17
- // Simple get - returns data directly or null
18
- async get(path) {
19
- try {
20
- const result = await this.db.getData(path);
21
- return result;
22
- }
23
- catch (error) {
24
- console.warn(`Failed to get data from ${path}:`, error);
25
- return null;
26
- }
27
- }
28
- // Simple put - returns success boolean
29
- async put(path, data) {
30
- try {
31
- const result = await this.db.put(path, data);
32
- return result.success;
33
- }
34
- catch (error) {
35
- console.warn(`Failed to put data to ${path}:`, error);
36
- return false;
37
- }
38
- }
39
- // Simple set - returns success boolean
40
- async set(path, data) {
41
- try {
42
- const result = await this.db.set(path, data);
43
- return result.success;
44
- }
45
- catch (error) {
46
- console.warn(`Failed to set data to ${path}:`, error);
47
- return false;
48
- }
49
- }
50
- // Simple remove - returns success boolean
51
- async remove(path) {
52
- try {
53
- const result = await this.db.remove(path);
54
- return result.success;
55
- }
56
- catch (error) {
57
- console.warn(`Failed to remove data from ${path}:`, error);
58
- return false;
59
- }
60
- }
61
- /**
62
- * Quick authentication - simplified interface
63
- */
64
- // Simple login - returns user info or null
65
- async login(username, password) {
66
- try {
67
- const result = await this.db.login(username, password);
68
- if (result.success && result.userPub) {
69
- return {
70
- userPub: result.userPub,
71
- username: result.username || username,
72
- };
73
- }
74
- return null;
75
- }
76
- catch (error) {
77
- console.warn(`Login failed for ${username}:`, error);
78
- return null;
79
- }
80
- }
81
- // Simple signup - returns user info or null
82
- async signup(username, password) {
83
- try {
84
- const result = await this.db.signUp(username, password);
85
- if (result.success && result.userPub) {
86
- return {
87
- userPub: result.userPub,
88
- username: result.username || username,
89
- };
90
- }
91
- return null;
92
- }
93
- catch (error) {
94
- console.warn(`Signup failed for ${username}:`, error);
95
- return null;
96
- }
97
- }
98
- // Simple logout
99
- logout() {
100
- this.db.logout();
101
- }
102
- // Simple check if logged in
103
- isLoggedIn() {
104
- return this.db.isLoggedIn();
105
- }
106
- /**
107
- * Quick user data operations - simplified interface
108
- */
109
- // Simple user data get
110
- async getUserData(path) {
111
- try {
112
- if (!this.isLoggedIn()) {
113
- console.warn("User not logged in");
114
- return null;
115
- }
116
- return (await this.db.getUserData(path));
117
- }
118
- catch (error) {
119
- console.warn(`Failed to get user data from ${path}:`, error);
120
- return null;
121
- }
122
- }
123
- // Simple user data put
124
- async putUserData(path, data) {
125
- try {
126
- if (!this.isLoggedIn()) {
127
- console.warn("User not logged in");
128
- return false;
129
- }
130
- await this.db.putUserData(path, data);
131
- return true;
132
- }
133
- catch (error) {
134
- console.warn(`Failed to put user data to ${path}:`, error);
135
- return false;
136
- }
137
- }
138
- // Simple user data set (alternative to put)
139
- async setUserData(path, data) {
140
- try {
141
- if (!this.isLoggedIn()) {
142
- console.warn("User not logged in");
143
- return false;
144
- }
145
- // Use the user's gun instance directly for set operations
146
- const user = this.db.getUser();
147
- if (user && user.is) {
148
- await new Promise((resolve, reject) => {
149
- user.get(path).set(data, (ack) => {
150
- if (ack.err) {
151
- reject(new Error(ack.err));
152
- }
153
- else {
154
- resolve();
155
- }
156
- });
157
- });
158
- return true;
159
- }
160
- return false;
161
- }
162
- catch (error) {
163
- console.warn(`Failed to set user data to ${path}:`, error);
164
- return false;
165
- }
166
- }
167
- // Simple user data remove
168
- async removeUserData(path) {
169
- try {
170
- if (!this.isLoggedIn()) {
171
- console.warn("User not logged in");
172
- return false;
173
- }
174
- const user = this.db.getUser();
175
- if (user && user.is) {
176
- await new Promise((resolve, reject) => {
177
- user.get(path).put(null, (ack) => {
178
- if (ack.err) {
179
- reject(new Error(ack.err));
180
- }
181
- else {
182
- resolve();
183
- }
184
- });
185
- });
186
- return true;
187
- }
188
- return false;
189
- }
190
- catch (error) {
191
- console.warn(`Failed to remove user data from ${path}:`, error);
192
- return false;
193
- }
194
- }
195
- /**
196
- * Quick utility methods
197
- */
198
- // Get current user info
199
- getCurrentUser() {
200
- const user = this.db.getCurrentUser();
201
- if (user) {
202
- return {
203
- pub: user.pub,
204
- username: user.username,
205
- };
206
- }
207
- return null;
208
- }
209
- // Check if user exists by alias
210
- async userExists(alias) {
211
- try {
212
- const user = await this.db.getUserByAlias(alias);
213
- return user !== null;
214
- }
215
- catch (error) {
216
- console.warn(`Failed to check if user exists: ${alias}`, error);
217
- return false;
218
- }
219
- }
220
- // Get user by alias
221
- async getUser(alias) {
222
- try {
223
- const user = await this.db.getUserByAlias(alias);
224
- if (user) {
225
- return {
226
- userPub: user.userPub,
227
- username: user.username,
228
- };
229
- }
230
- return null;
231
- }
232
- catch (error) {
233
- console.warn(`Failed to get user: ${alias}`, error);
234
- return null;
235
- }
236
- }
237
- /**
238
- * Advanced user space operations
239
- */
240
- // Get all user data (returns user's entire data tree)
241
- async getAllUserData() {
242
- try {
243
- if (!this.isLoggedIn()) {
244
- console.warn("User not logged in");
245
- return null;
246
- }
247
- const user = this.db.getUser();
248
- if (user && user.is) {
249
- const userData = await new Promise((resolve, reject) => {
250
- user.once((data) => {
251
- resolve(data);
252
- });
253
- });
254
- return userData;
255
- }
256
- return null;
257
- }
258
- catch (error) {
259
- console.warn("Failed to get all user data:", error);
260
- return null;
261
- }
262
- }
263
- // Update user profile (common use case)
264
- async updateProfile(profileData) {
265
- try {
266
- if (!this.isLoggedIn()) {
267
- console.warn("User not logged in");
268
- return false;
269
- }
270
- return await this.putUserData("profile", profileData);
271
- }
272
- catch (error) {
273
- console.warn("Failed to update profile:", error);
274
- return false;
275
- }
276
- }
277
- // Get user profile
278
- async getProfile() {
279
- try {
280
- if (!this.isLoggedIn()) {
281
- console.warn("User not logged in");
282
- return null;
283
- }
284
- return await this.getUserData("profile");
285
- }
286
- catch (error) {
287
- console.warn("Failed to get profile:", error);
288
- return null;
289
- }
290
- }
291
- // Save user settings
292
- async saveSettings(settings) {
293
- try {
294
- if (!this.isLoggedIn()) {
295
- console.warn("User not logged in");
296
- return false;
297
- }
298
- return await this.putUserData("settings", settings);
299
- }
300
- catch (error) {
301
- console.warn("Failed to save settings:", error);
302
- return false;
303
- }
304
- }
305
- // Get user settings
306
- async getSettings() {
307
- try {
308
- if (!this.isLoggedIn()) {
309
- console.warn("User not logged in");
310
- return null;
311
- }
312
- return await this.getUserData("settings");
313
- }
314
- catch (error) {
315
- console.warn("Failed to get settings:", error);
316
- return null;
317
- }
318
- }
319
- // Save user preferences
320
- async savePreferences(preferences) {
321
- try {
322
- if (!this.isLoggedIn()) {
323
- console.warn("User not logged in");
324
- return false;
325
- }
326
- return await this.putUserData("preferences", preferences);
327
- }
328
- catch (error) {
329
- console.warn("Failed to save preferences:", error);
330
- return false;
331
- }
332
- }
333
- // Get user preferences
334
- async getPreferences() {
335
- try {
336
- if (!this.isLoggedIn()) {
337
- console.warn("User not logged in");
338
- return null;
339
- }
340
- return await this.getUserData("preferences");
341
- }
342
- catch (error) {
343
- console.warn("Failed to get preferences:", error);
344
- return null;
345
- }
346
- }
347
- // Create a user collection (for storing multiple items)
348
- async createCollection(collectionName, items) {
349
- try {
350
- if (!this.isLoggedIn()) {
351
- console.warn("User not logged in");
352
- return false;
353
- }
354
- return await this.putUserData(`collections/${collectionName}`, items);
355
- }
356
- catch (error) {
357
- console.warn(`Failed to create collection ${collectionName}:`, error);
358
- return false;
359
- }
360
- }
361
- // Add item to collection
362
- async addToCollection(collectionName, itemId, item) {
363
- try {
364
- if (!this.isLoggedIn()) {
365
- console.warn("User not logged in");
366
- return false;
367
- }
368
- return await this.putUserData(`collections/${collectionName}/${itemId}`, item);
369
- }
370
- catch (error) {
371
- console.warn(`Failed to add item to collection ${collectionName}:`, error);
372
- return false;
373
- }
374
- }
375
- // Get collection
376
- async getCollection(collectionName) {
377
- try {
378
- if (!this.isLoggedIn()) {
379
- console.warn("User not logged in");
380
- return null;
381
- }
382
- return await this.getUserData(`collections/${collectionName}`);
383
- }
384
- catch (error) {
385
- console.warn(`Failed to get collection ${collectionName}:`, error);
386
- return null;
387
- }
388
- }
389
- // Remove item from collection
390
- async removeFromCollection(collectionName, itemId) {
391
- try {
392
- if (!this.isLoggedIn()) {
393
- console.warn("User not logged in");
394
- return false;
395
- }
396
- return await this.removeUserData(`collections/${collectionName}/${itemId}`);
397
- }
398
- catch (error) {
399
- console.warn(`Failed to remove item from collection ${collectionName}:`, error);
400
- return false;
401
- }
402
- }
403
- }
404
- /**
405
- * Factory function to create a simple API instance
406
- */
407
- export function createSimpleAPI(db) {
408
- return new SimpleGunAPI(db);
409
- }
410
- /**
411
- * Quick start helper - creates a simple API with minimal configuration
412
- */
413
- export class QuickStart {
414
- db;
415
- simpleAPI;
416
- constructor(gunInstance, appScope = "shogun") {
417
- this.db = new DataBase(gunInstance, appScope);
418
- this.simpleAPI = new SimpleGunAPI(this.db);
419
- }
420
- // Initialize the database
421
- async init() {
422
- await this.db.initialize();
423
- }
424
- // Get the simple API
425
- get api() {
426
- return this.simpleAPI;
427
- }
428
- // Get the full database instance for advanced usage
429
- get database() {
430
- return this.db;
431
- }
432
- }
433
- /**
434
- * Global helper for quick setup
435
- */
436
- export function quickStart(gunInstance, appScope) {
437
- return new QuickStart(gunInstance, appScope);
438
- }
@@ -1,4 +0,0 @@
1
- /**
2
- * Type definitions for GunDB to replace 'any' usage
3
- */
4
- export {};
package/dist/index.js DELETED
@@ -1,16 +0,0 @@
1
- import { ShogunCore } from "./core";
2
- import { SEA, RxJS, crypto, derive, GunErrors, DataBase } from "./gundb/db";
3
- // Import Simple API and improved types
4
- import { SimpleGunAPI, QuickStart, quickStart, createSimpleAPI, } from "./gundb";
5
- // Import Gun as default export
6
- import Gun from "./gundb/db";
7
- export * from "./utils/errorHandler";
8
- export * from "./plugins";
9
- export * from "./interfaces/shogun";
10
- // Export simplified configuration
11
- export * from "./config/simplified-config";
12
- export { SEA, RxJS, crypto, derive, GunErrors, DataBase,
13
- // Simple API exports
14
- SimpleGunAPI, QuickStart, quickStart, createSimpleAPI, };
15
- export { Gun };
16
- export { ShogunCore };
@@ -1 +0,0 @@
1
- export {};
@@ -1,36 +0,0 @@
1
- import { EventEmitter } from "../utils/eventEmitter";
2
- /**
3
- * Extended EventEmitter class with typed events for Shogun
4
- * @class ShogunEventEmitter
5
- * @extends EventEmitter
6
- */
7
- export class ShogunEventEmitter extends EventEmitter {
8
- /**
9
- * Emit a typed Shogun event
10
- * @template K - Event key type
11
- * @param {K} event - Event name
12
- * @param {ShogunEventMap[K]} data - Event data
13
- * @returns {boolean} - Returns true if the event had listeners, false otherwise
14
- */
15
- emit(event, data) {
16
- return super.emit(event, data);
17
- }
18
- /**
19
- * Register a listener for a typed Shogun event
20
- * @template K - Event key type
21
- * @param {K} event - Event name
22
- * @param {(data: ShogunEventMap[K]) => void} listener - Event listener function
23
- */
24
- on(event, listener) {
25
- super.on(event, listener);
26
- }
27
- /**
28
- * Remove a listener for a typed Shogun event
29
- * @template K - Event key type
30
- * @param {K} event - Event name
31
- * @param {(data: ShogunEventMap[K]) => void} listener - Event listener function to remove
32
- */
33
- off(event, listener) {
34
- super.off(event, listener);
35
- }
36
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,34 +0,0 @@
1
- /**
2
- * Standard plugin categories in ShogunCore
3
- */
4
- export var PluginCategory;
5
- (function (PluginCategory) {
6
- /** Authentication plugins (WebAuthn, MetaMask, Bitcoin) */
7
- PluginCategory["Authentication"] = "authentication";
8
- /** Wallet management plugins */
9
- PluginCategory["Wallet"] = "wallet";
10
- /** Privacy and anonymity plugins */
11
- PluginCategory["Privacy"] = "privacy";
12
- /** Decentralized identity plugins */
13
- PluginCategory["Identity"] = "identity";
14
- /** Other utility plugins */
15
- PluginCategory["Utility"] = "utility";
16
- /** Messages plugins */
17
- PluginCategory["Messages"] = "messages";
18
- /** Messaging plugins */
19
- PluginCategory["Other"] = "other";
20
- })(PluginCategory || (PluginCategory = {}));
21
- /**
22
- * Standard names for built-in plugins
23
- */
24
- export var CorePlugins;
25
- (function (CorePlugins) {
26
- /** WebAuthn plugin */
27
- CorePlugins["WebAuthn"] = "webauthn";
28
- /** Ethereum plugin */
29
- CorePlugins["Web3"] = "web3";
30
- /** Bitcoin wallet plugin */
31
- CorePlugins["Nostr"] = "nostr";
32
- /** OAuth plugin */
33
- CorePlugins["OAuth"] = "oauth";
34
- })(CorePlugins || (CorePlugins = {}));