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
|
@@ -0,0 +1,230 @@
|
|
|
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
|
+
};
|