shogun-core 2.0.3 → 3.0.0
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/README.md +150 -19
- package/dist/browser/shogun-core.js +3241 -1286
- package/dist/browser/shogun-core.js.map +1 -1
- package/dist/config/simplified-config.js +230 -0
- package/dist/core.js +49 -571
- package/dist/gundb/db.js +466 -237
- package/dist/gundb/improved-types.js +4 -0
- package/dist/gundb/index.js +4 -0
- package/dist/gundb/simple-api.js +438 -0
- package/dist/index.js +8 -2
- package/dist/managers/AuthManager.js +225 -0
- package/dist/managers/CoreInitializer.js +227 -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/nostr/nostrConnectorPlugin.js +1 -1
- package/dist/plugins/oauth/oauthPlugin.js +1 -1
- package/dist/plugins/webauthn/webauthnPlugin.js +1 -1
- package/dist/types/config/simplified-config.d.ts +114 -0
- package/dist/types/core.d.ts +13 -46
- package/dist/types/gundb/db.d.ts +92 -14
- package/dist/types/gundb/improved-types.d.ts +123 -0
- package/dist/types/gundb/index.d.ts +2 -0
- package/dist/types/gundb/rxjs.d.ts +3 -3
- package/dist/types/gundb/simple-api.d.ts +90 -0
- package/dist/types/index.d.ts +6 -4
- package/dist/types/{types → interfaces}/shogun.d.ts +8 -10
- package/dist/types/managers/AuthManager.d.ts +69 -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 +2 -2
- package/dist/types/plugins/index.d.ts +1 -1
- package/dist/types/plugins/nostr/nostrConnectorPlugin.d.ts +1 -1
- package/dist/types/plugins/nostr/types.d.ts +2 -2
- package/dist/types/plugins/oauth/oauthPlugin.d.ts +1 -1
- package/dist/types/plugins/oauth/types.d.ts +2 -2
- package/dist/types/plugins/web3/types.d.ts +2 -2
- package/dist/types/plugins/web3/web3ConnectorPlugin.d.ts +1 -1
- package/dist/types/plugins/webauthn/types.d.ts +2 -2
- package/dist/types/plugins/webauthn/webauthnPlugin.d.ts +1 -1
- package/dist/types/utils/errorHandler.d.ts +1 -1
- package/package.json +1 -1
- /package/dist/{types → interfaces}/common.js +0 -0
- /package/dist/{types → interfaces}/events.js +0 -0
- /package/dist/{types → interfaces}/plugin.js +0 -0
- /package/dist/{types → interfaces}/shogun.js +0 -0
- /package/dist/types/{types → interfaces}/common.d.ts +0 -0
- /package/dist/types/{types → interfaces}/events.d.ts +0 -0
- /package/dist/types/{types → interfaces}/plugin.d.ts +0 -0
|
@@ -384,7 +384,7 @@ export class WebauthnPlugin extends BasePlugin {
|
|
|
384
384
|
throw new Error("Failed to generate SEA pair from WebAuthn credentials");
|
|
385
385
|
}
|
|
386
386
|
// Use pair-based authentication instead of password
|
|
387
|
-
return await core.signUp(username,
|
|
387
|
+
return await core.signUp(username, undefined, pair);
|
|
388
388
|
}
|
|
389
389
|
catch (error) {
|
|
390
390
|
console.error(`Error during WebAuthn registration: ${error}`);
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simplified configuration options to reduce complexity
|
|
3
|
+
* Provides sensible defaults and easy-to-use presets
|
|
4
|
+
*/
|
|
5
|
+
import { ShogunCoreConfig } from "../interfaces/shogun";
|
|
6
|
+
/**
|
|
7
|
+
* Preset configurations for common use cases
|
|
8
|
+
*/
|
|
9
|
+
export declare const ShogunPresets: {
|
|
10
|
+
/**
|
|
11
|
+
* Minimal configuration for simple apps
|
|
12
|
+
*/
|
|
13
|
+
minimal: () => ShogunCoreConfig;
|
|
14
|
+
/**
|
|
15
|
+
* Development configuration with local storage
|
|
16
|
+
*/
|
|
17
|
+
development: () => ShogunCoreConfig;
|
|
18
|
+
/**
|
|
19
|
+
* Production configuration with multiple peers
|
|
20
|
+
*/
|
|
21
|
+
production: (customPeers?: string[]) => ShogunCoreConfig;
|
|
22
|
+
/**
|
|
23
|
+
* Offline-first configuration
|
|
24
|
+
*/
|
|
25
|
+
offline: () => ShogunCoreConfig;
|
|
26
|
+
/**
|
|
27
|
+
* Web3-enabled configuration
|
|
28
|
+
*/
|
|
29
|
+
web3: () => ShogunCoreConfig;
|
|
30
|
+
/**
|
|
31
|
+
* WebAuthn-enabled configuration
|
|
32
|
+
*/
|
|
33
|
+
webauthn: () => ShogunCoreConfig;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Configuration builder for custom setups
|
|
37
|
+
*/
|
|
38
|
+
export declare class ShogunConfigBuilder {
|
|
39
|
+
private config;
|
|
40
|
+
/**
|
|
41
|
+
* Set Gun options
|
|
42
|
+
*/
|
|
43
|
+
gunOptions(options: any): this;
|
|
44
|
+
/**
|
|
45
|
+
* Add peers
|
|
46
|
+
*/
|
|
47
|
+
peers(peerList: string[]): this;
|
|
48
|
+
/**
|
|
49
|
+
* Enable WebAuthn
|
|
50
|
+
*/
|
|
51
|
+
enableWebAuthn(rpName?: string, rpId?: string): this;
|
|
52
|
+
/**
|
|
53
|
+
* Enable Web3
|
|
54
|
+
*/
|
|
55
|
+
enableWeb3(): this;
|
|
56
|
+
/**
|
|
57
|
+
* Enable Nostr
|
|
58
|
+
*/
|
|
59
|
+
enableNostr(): this;
|
|
60
|
+
/**
|
|
61
|
+
* Set timeouts
|
|
62
|
+
*/
|
|
63
|
+
timeouts(timeouts: {
|
|
64
|
+
login?: number;
|
|
65
|
+
signup?: number;
|
|
66
|
+
operation?: number;
|
|
67
|
+
}): this;
|
|
68
|
+
/**
|
|
69
|
+
* Build the final configuration
|
|
70
|
+
*/
|
|
71
|
+
build(): ShogunCoreConfig;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Helper functions for common configuration patterns
|
|
75
|
+
*/
|
|
76
|
+
export declare const ConfigHelpers: {
|
|
77
|
+
/**
|
|
78
|
+
* Create a configuration for a specific environment
|
|
79
|
+
*/
|
|
80
|
+
forEnvironment(env: "development" | "production" | "test"): ShogunCoreConfig;
|
|
81
|
+
/**
|
|
82
|
+
* Create a configuration with custom peers
|
|
83
|
+
*/
|
|
84
|
+
withPeers(peers: string[]): ShogunCoreConfig;
|
|
85
|
+
/**
|
|
86
|
+
* Create a configuration for a specific use case
|
|
87
|
+
*/
|
|
88
|
+
forUseCase(useCase: "chat" | "social" | "gaming" | "finance"): ShogunCoreConfig;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Quick configuration functions
|
|
92
|
+
*/
|
|
93
|
+
export declare const QuickConfig: {
|
|
94
|
+
/**
|
|
95
|
+
* Minimal setup for quick testing
|
|
96
|
+
*/
|
|
97
|
+
test: () => ShogunCoreConfig;
|
|
98
|
+
/**
|
|
99
|
+
* Standard setup for most apps
|
|
100
|
+
*/
|
|
101
|
+
standard: () => ShogunCoreConfig;
|
|
102
|
+
/**
|
|
103
|
+
* Setup with WebAuthn for secure apps
|
|
104
|
+
*/
|
|
105
|
+
secure: () => ShogunCoreConfig;
|
|
106
|
+
/**
|
|
107
|
+
* Setup with Web3 for crypto apps
|
|
108
|
+
*/
|
|
109
|
+
crypto: () => ShogunCoreConfig;
|
|
110
|
+
/**
|
|
111
|
+
* Offline setup for local development
|
|
112
|
+
*/
|
|
113
|
+
local: () => ShogunCoreConfig;
|
|
114
|
+
};
|
package/dist/types/core.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ShogunEventMap } from "./
|
|
1
|
+
import { ShogunEventMap } from "./interfaces/events";
|
|
2
2
|
import { ShogunError } from "./utils/errorHandler";
|
|
3
3
|
import { ShogunStorage } from "./storage/storage";
|
|
4
|
-
import { IShogunCore, ShogunCoreConfig, AuthResult, SignUpResult, PluginCategory, AuthMethod, Wallets } from "./
|
|
4
|
+
import { IShogunCore, ShogunCoreConfig, AuthResult, SignUpResult, PluginCategory, AuthMethod, Wallets } from "./interfaces/shogun";
|
|
5
5
|
import { ethers } from "ethers";
|
|
6
|
-
import { ShogunPlugin } from "./
|
|
7
|
-
import { IGunUserInstance, IGunInstance, DataBase, RxJS } from "./gundb";
|
|
6
|
+
import { ShogunPlugin } from "./interfaces/plugin";
|
|
8
7
|
import { ISEAPair } from "gun";
|
|
8
|
+
import { DataBase, RxJS, GunInstance, GunUserInstance } from "./gundb";
|
|
9
9
|
/**
|
|
10
10
|
* Main ShogunCore class - implements the IShogunCore interface
|
|
11
11
|
*
|
|
@@ -26,10 +26,11 @@ export declare class ShogunCore implements IShogunCore {
|
|
|
26
26
|
rx: RxJS;
|
|
27
27
|
private _gun;
|
|
28
28
|
private _user;
|
|
29
|
-
private readonly eventEmitter;
|
|
30
|
-
private readonly plugins;
|
|
31
|
-
private currentAuthMethod?;
|
|
32
29
|
wallets: Wallets | undefined;
|
|
30
|
+
private pluginManager;
|
|
31
|
+
private authManager;
|
|
32
|
+
private eventManager;
|
|
33
|
+
private coreInitializer;
|
|
33
34
|
/**
|
|
34
35
|
* Initialize the Shogun SDK
|
|
35
36
|
* @param config - SDK Configuration object
|
|
@@ -38,21 +39,16 @@ export declare class ShogunCore implements IShogunCore {
|
|
|
38
39
|
* and plugin system.
|
|
39
40
|
*/
|
|
40
41
|
constructor(config: ShogunCoreConfig);
|
|
41
|
-
/**
|
|
42
|
-
* Initialize the Shogun SDK asynchronously
|
|
43
|
-
* This method handles initialization tasks that require async operations
|
|
44
|
-
*/
|
|
45
|
-
initialize(): Promise<void>;
|
|
46
42
|
/**
|
|
47
43
|
* Access to the Gun instance
|
|
48
44
|
* @returns The Gun instance
|
|
49
45
|
*/
|
|
50
|
-
get gun():
|
|
46
|
+
get gun(): GunInstance;
|
|
51
47
|
/**
|
|
52
48
|
* Access to the current user
|
|
53
49
|
* @returns The current Gun user instance
|
|
54
50
|
*/
|
|
55
|
-
get user():
|
|
51
|
+
get user(): GunUserInstance | null;
|
|
56
52
|
/**
|
|
57
53
|
* Gets the current user information
|
|
58
54
|
* @returns Current user object or null
|
|
@@ -61,16 +57,6 @@ export declare class ShogunCore implements IShogunCore {
|
|
|
61
57
|
pub: string;
|
|
62
58
|
user?: any;
|
|
63
59
|
} | null;
|
|
64
|
-
/**
|
|
65
|
-
* Setup event forwarding from GunInstance to main event emitter
|
|
66
|
-
* @private
|
|
67
|
-
*/
|
|
68
|
-
private setupGunEventForwarding;
|
|
69
|
-
/**
|
|
70
|
-
* Register built-in plugins based on configuration
|
|
71
|
-
* @private
|
|
72
|
-
*/
|
|
73
|
-
private registerBuiltinPlugins;
|
|
74
60
|
/**
|
|
75
61
|
* Registers a plugin with the Shogun SDK
|
|
76
62
|
* @param plugin Plugin instance to register
|
|
@@ -82,16 +68,6 @@ export declare class ShogunCore implements IShogunCore {
|
|
|
82
68
|
* @param pluginName Name of the plugin to unregister
|
|
83
69
|
*/
|
|
84
70
|
unregister(pluginName: string): void;
|
|
85
|
-
/**
|
|
86
|
-
* Internal method to register a plugin
|
|
87
|
-
* @param plugin Plugin instance to register
|
|
88
|
-
*/
|
|
89
|
-
private registerPlugin;
|
|
90
|
-
/**
|
|
91
|
-
* Internal method to unregister a plugin
|
|
92
|
-
* @param name Name of the plugin to unregister
|
|
93
|
-
*/
|
|
94
|
-
private unregisterPlugin;
|
|
95
71
|
/**
|
|
96
72
|
* Retrieve a registered plugin by name
|
|
97
73
|
* @param name Name of the plugin
|
|
@@ -221,10 +197,7 @@ export declare class ShogunCore implements IShogunCore {
|
|
|
221
197
|
* @returns The authentication plugin or undefined if not available
|
|
222
198
|
* This is a more modern approach to accessing authentication methods
|
|
223
199
|
*/
|
|
224
|
-
getAuthenticationMethod(type: AuthMethod):
|
|
225
|
-
login: (username: string, password: string) => Promise<AuthResult>;
|
|
226
|
-
signUp: (username: string, password: string, confirm?: string) => Promise<SignUpResult>;
|
|
227
|
-
} | undefined;
|
|
200
|
+
getAuthenticationMethod(type: AuthMethod): unknown;
|
|
228
201
|
/**
|
|
229
202
|
* Retrieve recent errors logged by the system
|
|
230
203
|
* @param count - Number of errors to retrieve (default: 10)
|
|
@@ -265,13 +238,13 @@ export declare class ShogunCore implements IShogunCore {
|
|
|
265
238
|
* Register a new user with provided credentials
|
|
266
239
|
* @param username - Username
|
|
267
240
|
* @param password - Password
|
|
268
|
-
* @param
|
|
241
|
+
* @param email - Email (optional)
|
|
269
242
|
* @param pair - Pair of keys
|
|
270
243
|
* @returns {Promise<SignUpResult>} Registration result
|
|
271
244
|
* @description Creates a new user account with the provided credentials.
|
|
272
245
|
* Validates password requirements and emits signup event on success.
|
|
273
246
|
*/
|
|
274
|
-
signUp(username: string, password?: string,
|
|
247
|
+
signUp(username: string, password?: string, pair?: ISEAPair | null): Promise<SignUpResult>;
|
|
275
248
|
/**
|
|
276
249
|
* Emits an event through the core's event emitter.
|
|
277
250
|
* Plugins should use this method to emit events instead of accessing the private eventEmitter directly.
|
|
@@ -325,10 +298,4 @@ export declare class ShogunCore implements IShogunCore {
|
|
|
325
298
|
saveCredentials(credentials: any): Promise<void>;
|
|
326
299
|
getIsLoggedIn(): boolean;
|
|
327
300
|
}
|
|
328
|
-
declare global {
|
|
329
|
-
interface Window {
|
|
330
|
-
SHOGUN_CORE: (config: ShogunCoreConfig) => ShogunCore;
|
|
331
|
-
SHOGUN_CORE_CLASS: typeof ShogunCore;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
301
|
export default ShogunCore;
|
package/dist/types/gundb/db.d.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* - Direct authentication through Gun.user()
|
|
6
6
|
*/
|
|
7
7
|
import type { GunUser, UserInfo, AuthCallback, GunData, EventData, EventListener, GunOperationResult } from "./types";
|
|
8
|
-
import type {
|
|
8
|
+
import type { GunInstance, GunUserInstance, GunChain } from "./improved-types";
|
|
9
|
+
import type { AuthResult, SignUpResult } from "../interfaces/shogun";
|
|
9
10
|
import Gun from "gun/gun";
|
|
10
11
|
import SEA from "gun/sea";
|
|
11
12
|
import "gun/lib/then";
|
|
@@ -14,25 +15,25 @@ import "gun/lib/radisk";
|
|
|
14
15
|
import "gun/lib/store";
|
|
15
16
|
import "gun/lib/rindexed";
|
|
16
17
|
import "gun/lib/webrtc";
|
|
17
|
-
import "gun/lib/
|
|
18
|
-
import "gun/lib/
|
|
18
|
+
import "gun/lib/wire";
|
|
19
|
+
import "gun/lib/axe";
|
|
19
20
|
import { restrictedPut } from "./restricted-put";
|
|
20
21
|
import derive, { DeriveOptions } from "./derive";
|
|
21
|
-
import type {
|
|
22
|
-
import { GunDataEventData, GunPeerEventData } from "../
|
|
22
|
+
import type { IGunInstance, ISEAPair } from "gun/types";
|
|
23
|
+
import { GunDataEventData, GunPeerEventData } from "../interfaces/events";
|
|
23
24
|
import { RxJS } from "./rxjs";
|
|
24
25
|
import * as GunErrors from "./errors";
|
|
25
26
|
import * as crypto from "./crypto";
|
|
26
27
|
declare class DataBase {
|
|
27
|
-
gun:
|
|
28
|
-
user:
|
|
28
|
+
gun: GunInstance;
|
|
29
|
+
user: GunUserInstance | null;
|
|
29
30
|
crypto: typeof crypto;
|
|
30
31
|
sea: typeof SEA;
|
|
31
|
-
node:
|
|
32
|
+
node: GunChain;
|
|
32
33
|
private readonly onAuthCallbacks;
|
|
33
34
|
private readonly eventEmitter;
|
|
34
35
|
private _rxjs?;
|
|
35
|
-
constructor(gun:
|
|
36
|
+
constructor(gun: GunInstance, appScope?: string);
|
|
36
37
|
/**
|
|
37
38
|
* Initialize the GunInstance asynchronously
|
|
38
39
|
* This method should be called after construction to perform async operations
|
|
@@ -97,7 +98,7 @@ declare class DataBase {
|
|
|
97
98
|
* Gets the Gun instance
|
|
98
99
|
* @returns Gun instance
|
|
99
100
|
*/
|
|
100
|
-
getGun():
|
|
101
|
+
getGun(): GunInstance;
|
|
101
102
|
/**
|
|
102
103
|
* Gets the current user
|
|
103
104
|
* @returns Current user object or null
|
|
@@ -168,10 +169,6 @@ declare class DataBase {
|
|
|
168
169
|
* Validates signup credentials with enhanced security
|
|
169
170
|
*/
|
|
170
171
|
private validateSignupCredentials;
|
|
171
|
-
/**
|
|
172
|
-
* Checks if user exists by attempting authentication
|
|
173
|
-
*/
|
|
174
|
-
private checkUserExistence;
|
|
175
172
|
/**
|
|
176
173
|
* Creates a new user in Gun
|
|
177
174
|
*/
|
|
@@ -193,6 +190,87 @@ declare class DataBase {
|
|
|
193
190
|
*/
|
|
194
191
|
private createNewUserWithPair;
|
|
195
192
|
private runPostAuthOnAuthResult;
|
|
193
|
+
/**
|
|
194
|
+
* Sets up comprehensive user tracking system for agile user lookup
|
|
195
|
+
* Creates multiple indexes for efficient user discovery
|
|
196
|
+
*/
|
|
197
|
+
private setupComprehensiveUserTracking;
|
|
198
|
+
/**
|
|
199
|
+
* Creates alias index following GunDB pattern: ~@alias -> userPub
|
|
200
|
+
*/
|
|
201
|
+
private createAliasIndex;
|
|
202
|
+
/**
|
|
203
|
+
* Creates username mapping: usernames/alias -> userPub
|
|
204
|
+
*/
|
|
205
|
+
private createUsernameMapping;
|
|
206
|
+
/**
|
|
207
|
+
* Creates user registry: users/userPub -> user data
|
|
208
|
+
*/
|
|
209
|
+
private createUserRegistry;
|
|
210
|
+
/**
|
|
211
|
+
* Creates reverse lookup: userPub -> alias
|
|
212
|
+
*/
|
|
213
|
+
private createReverseLookup;
|
|
214
|
+
/**
|
|
215
|
+
* Creates epub index: epubKeys/epub -> userPub
|
|
216
|
+
*/
|
|
217
|
+
private createEpubIndex;
|
|
218
|
+
/**
|
|
219
|
+
* Creates user metadata in user's own node
|
|
220
|
+
*/
|
|
221
|
+
private createUserMetadata;
|
|
222
|
+
/**
|
|
223
|
+
* Gets user information by alias using the comprehensive tracking system
|
|
224
|
+
* @param alias Username/alias to lookup
|
|
225
|
+
* @returns Promise resolving to user information or null if not found
|
|
226
|
+
*/
|
|
227
|
+
getUserByAlias(alias: string): Promise<{
|
|
228
|
+
userPub: string;
|
|
229
|
+
epub: string | null;
|
|
230
|
+
username: string;
|
|
231
|
+
registeredAt: number;
|
|
232
|
+
lastSeen: number;
|
|
233
|
+
} | null>;
|
|
234
|
+
/**
|
|
235
|
+
* Gets user information by public key
|
|
236
|
+
* @param userPub User's public key
|
|
237
|
+
* @returns Promise resolving to user information or null if not found
|
|
238
|
+
*/
|
|
239
|
+
getUserDataByPub(userPub: string): Promise<{
|
|
240
|
+
userPub: string;
|
|
241
|
+
epub: string | null;
|
|
242
|
+
username: string;
|
|
243
|
+
registeredAt: number;
|
|
244
|
+
lastSeen: number;
|
|
245
|
+
} | null>;
|
|
246
|
+
/**
|
|
247
|
+
* Gets user public key by encryption public key (epub)
|
|
248
|
+
* @param epub User's encryption public key
|
|
249
|
+
* @returns Promise resolving to user public key or null if not found
|
|
250
|
+
*/
|
|
251
|
+
getUserPubByEpub(epub: string): Promise<string | null>;
|
|
252
|
+
/**
|
|
253
|
+
* Gets user alias by public key
|
|
254
|
+
* @param userPub User's public key
|
|
255
|
+
* @returns Promise resolving to user alias or null if not found
|
|
256
|
+
*/
|
|
257
|
+
getUserAliasByPub(userPub: string): Promise<string | null>;
|
|
258
|
+
/**
|
|
259
|
+
* Gets all registered users (for admin purposes)
|
|
260
|
+
* @returns Promise resolving to array of user information
|
|
261
|
+
*/
|
|
262
|
+
getAllRegisteredUsers(): Promise<Array<{
|
|
263
|
+
userPub: string;
|
|
264
|
+
epub: string | null;
|
|
265
|
+
username: string;
|
|
266
|
+
registeredAt: number;
|
|
267
|
+
lastSeen: number;
|
|
268
|
+
}>>;
|
|
269
|
+
/**
|
|
270
|
+
* Updates user's last seen timestamp
|
|
271
|
+
* @param userPub User's public key
|
|
272
|
+
*/
|
|
273
|
+
updateUserLastSeen(userPub: string): Promise<void>;
|
|
196
274
|
/**
|
|
197
275
|
* Performs authentication with Gun
|
|
198
276
|
*/
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Improved type definitions to reduce 'any' usage while maintaining GunDB compatibility
|
|
3
|
+
*/
|
|
4
|
+
import type { IGunUserInstance, IGunInstance, IGunChain, ISEAPair } from "gun/types";
|
|
5
|
+
export type GunInstance = IGunInstance<any>;
|
|
6
|
+
export type GunUserInstance = IGunUserInstance<any>;
|
|
7
|
+
export type GunChain = IGunChain<any, IGunInstance<any>, IGunInstance<any>, string>;
|
|
8
|
+
export interface GunData {
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
}
|
|
11
|
+
export interface GunNodeData {
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
_?: {
|
|
14
|
+
"#": string;
|
|
15
|
+
">": Record<string, number>;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export interface GunAckCallback {
|
|
19
|
+
(ack: {
|
|
20
|
+
err?: string;
|
|
21
|
+
ok?: number;
|
|
22
|
+
pub?: string;
|
|
23
|
+
}): void;
|
|
24
|
+
}
|
|
25
|
+
export interface GunDataCallback<T = unknown> {
|
|
26
|
+
(data: T, key: string): void;
|
|
27
|
+
}
|
|
28
|
+
export interface GunMapCallback<T = unknown> {
|
|
29
|
+
(data: T, key: string): void;
|
|
30
|
+
}
|
|
31
|
+
export interface TypedGunOperationResult<T = unknown> {
|
|
32
|
+
success: boolean;
|
|
33
|
+
data?: T;
|
|
34
|
+
error?: string;
|
|
35
|
+
ack?: {
|
|
36
|
+
err?: string;
|
|
37
|
+
ok?: number;
|
|
38
|
+
pub?: string;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export interface TypedUserInfo {
|
|
42
|
+
pub: string;
|
|
43
|
+
alias?: string;
|
|
44
|
+
timestamp?: number;
|
|
45
|
+
user?: GunUserInstance;
|
|
46
|
+
metadata?: Record<string, unknown>;
|
|
47
|
+
}
|
|
48
|
+
export interface TypedAuthCallback {
|
|
49
|
+
(user: GunUserInstance): void;
|
|
50
|
+
}
|
|
51
|
+
export interface TypedAuthResult {
|
|
52
|
+
success: boolean;
|
|
53
|
+
userPub?: string;
|
|
54
|
+
username?: string;
|
|
55
|
+
error?: string;
|
|
56
|
+
ack?: {
|
|
57
|
+
err?: string;
|
|
58
|
+
ok?: number;
|
|
59
|
+
pub?: string;
|
|
60
|
+
sea?: ISEAPair;
|
|
61
|
+
};
|
|
62
|
+
sea?: ISEAPair;
|
|
63
|
+
}
|
|
64
|
+
export interface TypedGunConfig {
|
|
65
|
+
peers?: string[];
|
|
66
|
+
localStorage?: boolean;
|
|
67
|
+
radisk?: boolean;
|
|
68
|
+
file?: string;
|
|
69
|
+
uuid?: () => string;
|
|
70
|
+
[key: string]: unknown;
|
|
71
|
+
}
|
|
72
|
+
export interface TypedEventData {
|
|
73
|
+
type: string;
|
|
74
|
+
data: unknown;
|
|
75
|
+
timestamp: number;
|
|
76
|
+
source?: string;
|
|
77
|
+
}
|
|
78
|
+
export type GunPath = string | string[];
|
|
79
|
+
export interface PathOperation<T = unknown> {
|
|
80
|
+
path: GunPath;
|
|
81
|
+
data?: T;
|
|
82
|
+
callback?: GunAckCallback;
|
|
83
|
+
}
|
|
84
|
+
export interface TypedRxJSObservable<T = unknown> {
|
|
85
|
+
subscribe: (observer: {
|
|
86
|
+
next: (value: T) => void;
|
|
87
|
+
error?: (error: Error) => void;
|
|
88
|
+
complete?: () => void;
|
|
89
|
+
}) => {
|
|
90
|
+
unsubscribe: () => void;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export interface TypedPluginConfig {
|
|
94
|
+
name: string;
|
|
95
|
+
version: string;
|
|
96
|
+
enabled: boolean;
|
|
97
|
+
config?: Record<string, unknown>;
|
|
98
|
+
}
|
|
99
|
+
export interface TypedStorageData {
|
|
100
|
+
key: string;
|
|
101
|
+
value: unknown;
|
|
102
|
+
timestamp: number;
|
|
103
|
+
ttl?: number;
|
|
104
|
+
}
|
|
105
|
+
export interface TypedGunError extends Error {
|
|
106
|
+
code?: string;
|
|
107
|
+
type: "GUN_ERROR" | "AUTH_ERROR" | "NETWORK_ERROR" | "VALIDATION_ERROR";
|
|
108
|
+
context?: Record<string, unknown>;
|
|
109
|
+
}
|
|
110
|
+
export type GunOperation = "get" | "put" | "set" | "remove" | "once" | "on" | "off";
|
|
111
|
+
export type GunAuthMethod = "password" | "pair" | "webauthn" | "web3" | "nostr";
|
|
112
|
+
export interface TypedGunWrapper<T = Record<string, unknown>> {
|
|
113
|
+
gun: GunInstance;
|
|
114
|
+
user: GunUserInstance | null;
|
|
115
|
+
get(path: GunPath): Promise<T>;
|
|
116
|
+
put(path: GunPath, data: T): Promise<TypedGunOperationResult<T>>;
|
|
117
|
+
set(path: GunPath, data: T): Promise<TypedGunOperationResult<T>>;
|
|
118
|
+
remove(path: GunPath): Promise<TypedGunOperationResult>;
|
|
119
|
+
getUserData(path: string): Promise<T>;
|
|
120
|
+
putUserData(path: string, data: T): Promise<void>;
|
|
121
|
+
login(username: string, password: string): Promise<TypedAuthResult>;
|
|
122
|
+
signUp(username: string, password: string): Promise<TypedAuthResult>;
|
|
123
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Observable } from "rxjs";
|
|
2
|
-
import {
|
|
2
|
+
import { GunInstance, GunUserInstance } from "./improved-types";
|
|
3
3
|
/**
|
|
4
4
|
* RxJS Integration for GunDB
|
|
5
5
|
* Provides reactive programming capabilities for GunDB data
|
|
@@ -11,12 +11,12 @@ export declare class RxJS {
|
|
|
11
11
|
* Initialize GunRxJS with a GunDB instance
|
|
12
12
|
* @param gun - GunDB instance
|
|
13
13
|
*/
|
|
14
|
-
constructor(gun:
|
|
14
|
+
constructor(gun: GunInstance);
|
|
15
15
|
/**
|
|
16
16
|
* Get the current user
|
|
17
17
|
* @returns The current user
|
|
18
18
|
*/
|
|
19
|
-
getUser():
|
|
19
|
+
getUser(): GunUserInstance;
|
|
20
20
|
/**
|
|
21
21
|
* Get the current user's public key
|
|
22
22
|
* @returns The current user's public key
|
|
@@ -0,0 +1,90 @@
|
|
|
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 declare class SimpleGunAPI {
|
|
10
|
+
private db;
|
|
11
|
+
constructor(db: DataBase);
|
|
12
|
+
/**
|
|
13
|
+
* Quick data operations - simplified interface
|
|
14
|
+
*/
|
|
15
|
+
get<T = unknown>(path: string): Promise<T | null>;
|
|
16
|
+
put<T = unknown>(path: string, data: T): Promise<boolean>;
|
|
17
|
+
set<T = unknown>(path: string, data: T): Promise<boolean>;
|
|
18
|
+
remove(path: string): Promise<boolean>;
|
|
19
|
+
/**
|
|
20
|
+
* Quick authentication - simplified interface
|
|
21
|
+
*/
|
|
22
|
+
login(username: string, password: string): Promise<{
|
|
23
|
+
userPub: string;
|
|
24
|
+
username: string;
|
|
25
|
+
} | null>;
|
|
26
|
+
signup(username: string, password: string): Promise<{
|
|
27
|
+
userPub: string;
|
|
28
|
+
username: string;
|
|
29
|
+
} | null>;
|
|
30
|
+
logout(): void;
|
|
31
|
+
isLoggedIn(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Quick user data operations - simplified interface
|
|
34
|
+
*/
|
|
35
|
+
getUserData<T = unknown>(path: string): Promise<T | null>;
|
|
36
|
+
putUserData<T = unknown>(path: string, data: T): Promise<boolean>;
|
|
37
|
+
setUserData<T = unknown>(path: string, data: T): Promise<boolean>;
|
|
38
|
+
removeUserData(path: string): Promise<boolean>;
|
|
39
|
+
/**
|
|
40
|
+
* Quick utility methods
|
|
41
|
+
*/
|
|
42
|
+
getCurrentUser(): {
|
|
43
|
+
pub: string;
|
|
44
|
+
username?: string;
|
|
45
|
+
} | null;
|
|
46
|
+
userExists(alias: string): Promise<boolean>;
|
|
47
|
+
getUser(alias: string): Promise<{
|
|
48
|
+
userPub: string;
|
|
49
|
+
username: string;
|
|
50
|
+
} | null>;
|
|
51
|
+
/**
|
|
52
|
+
* Advanced user space operations
|
|
53
|
+
*/
|
|
54
|
+
getAllUserData(): Promise<Record<string, unknown> | null>;
|
|
55
|
+
updateProfile(profileData: {
|
|
56
|
+
name?: string;
|
|
57
|
+
email?: string;
|
|
58
|
+
bio?: string;
|
|
59
|
+
avatar?: string;
|
|
60
|
+
[key: string]: unknown;
|
|
61
|
+
}): Promise<boolean>;
|
|
62
|
+
getProfile(): Promise<Record<string, unknown> | null>;
|
|
63
|
+
saveSettings(settings: Record<string, unknown>): Promise<boolean>;
|
|
64
|
+
getSettings(): Promise<Record<string, unknown> | null>;
|
|
65
|
+
savePreferences(preferences: Record<string, unknown>): Promise<boolean>;
|
|
66
|
+
getPreferences(): Promise<Record<string, unknown> | null>;
|
|
67
|
+
createCollection<T = unknown>(collectionName: string, items: Record<string, T>): Promise<boolean>;
|
|
68
|
+
addToCollection<T = unknown>(collectionName: string, itemId: string, item: T): Promise<boolean>;
|
|
69
|
+
getCollection(collectionName: string): Promise<Record<string, unknown> | null>;
|
|
70
|
+
removeFromCollection(collectionName: string, itemId: string): Promise<boolean>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Factory function to create a simple API instance
|
|
74
|
+
*/
|
|
75
|
+
export declare function createSimpleAPI(db: DataBase): SimpleGunAPI;
|
|
76
|
+
/**
|
|
77
|
+
* Quick start helper - creates a simple API with minimal configuration
|
|
78
|
+
*/
|
|
79
|
+
export declare class QuickStart {
|
|
80
|
+
private db;
|
|
81
|
+
private simpleAPI;
|
|
82
|
+
constructor(gunInstance: any, appScope?: string);
|
|
83
|
+
init(): Promise<void>;
|
|
84
|
+
get api(): SimpleGunAPI;
|
|
85
|
+
get database(): DataBase;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Global helper for quick setup
|
|
89
|
+
*/
|
|
90
|
+
export declare function quickStart(gunInstance: any, appScope?: string): QuickStart;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { ShogunCore } from "./core";
|
|
2
2
|
import { IGunUserInstance, IGunInstance, GunDataEventData, GunPeerEventData, DeriveOptions } from "./gundb/db";
|
|
3
3
|
import { SEA, RxJS, crypto, derive, GunErrors, DataBase } from "./gundb/db";
|
|
4
|
+
import { SimpleGunAPI, QuickStart, quickStart, createSimpleAPI, GunInstance, GunUserInstance, TypedGunOperationResult, TypedAuthResult } from "./gundb";
|
|
4
5
|
import Gun from "./gundb/db";
|
|
5
6
|
export * from "./utils/errorHandler";
|
|
6
7
|
export * from "./plugins";
|
|
7
|
-
export * from "./
|
|
8
|
-
export type * from "./
|
|
9
|
-
export
|
|
10
|
-
export {
|
|
8
|
+
export * from "./interfaces/shogun";
|
|
9
|
+
export type * from "./interfaces/plugin";
|
|
10
|
+
export * from "./config/simplified-config";
|
|
11
|
+
export type { IGunUserInstance, IGunInstance, GunDataEventData, GunPeerEventData, DeriveOptions, GunInstance, GunUserInstance, TypedGunOperationResult, TypedAuthResult, };
|
|
12
|
+
export { SEA, RxJS, crypto, derive, GunErrors, DataBase, SimpleGunAPI, QuickStart, quickStart, createSimpleAPI, };
|
|
11
13
|
export { Gun };
|
|
12
14
|
export { ShogunCore };
|