shogun-core 3.0.13 → 3.0.15
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 +27 -1
- package/dist/browser/shogun-core.js +103157 -84871
- package/dist/browser/shogun-core.js.map +1 -1
- package/dist/config/simplified-config.js +22 -16
- package/dist/core.js +18 -26
- package/dist/examples/api-test.js +273 -0
- package/dist/examples/simple-api-test.js +89 -0
- package/dist/gundb/api.js +126 -189
- package/dist/gundb/crypto.js +32 -17
- package/dist/gundb/db.js +89 -137
- package/dist/gundb/derive.js +20 -17
- package/dist/gundb/errors.js +17 -7
- package/dist/gundb/index.js +19 -3
- package/dist/gundb/rxjs.js +19 -17
- package/dist/gundb/types.js +2 -1
- package/dist/index.js +43 -12
- package/dist/interfaces/common.js +2 -1
- package/dist/interfaces/events.js +6 -2
- package/dist/interfaces/plugin.js +2 -1
- package/dist/interfaces/shogun.js +7 -4
- package/dist/managers/AuthManager.js +9 -7
- package/dist/managers/CoreInitializer.js +23 -20
- package/dist/managers/EventManager.js +7 -4
- package/dist/managers/PluginManager.js +6 -3
- package/dist/migration-test.js +13 -8
- package/dist/plugins/base.js +11 -8
- package/dist/plugins/index.js +36 -10
- package/dist/plugins/nostr/index.js +20 -4
- package/dist/plugins/nostr/nostrConnector.js +42 -36
- package/dist/plugins/nostr/nostrConnectorPlugin.js +36 -29
- package/dist/plugins/nostr/nostrSigner.js +17 -11
- package/dist/plugins/nostr/types.js +2 -1
- package/dist/plugins/oauth/index.js +7 -2
- package/dist/plugins/oauth/oauthConnector.js +75 -69
- package/dist/plugins/oauth/oauthPlugin.js +31 -27
- package/dist/plugins/oauth/types.js +2 -1
- package/dist/plugins/web3/index.js +20 -4
- package/dist/plugins/web3/types.js +2 -1
- package/dist/plugins/web3/web3Connector.js +38 -33
- package/dist/plugins/web3/web3ConnectorPlugin.js +29 -22
- package/dist/plugins/web3/web3Signer.js +24 -18
- package/dist/plugins/webauthn/index.js +19 -3
- package/dist/plugins/webauthn/types.js +5 -2
- package/dist/plugins/webauthn/webauthn.js +30 -25
- package/dist/plugins/webauthn/webauthnPlugin.js +21 -14
- package/dist/plugins/webauthn/webauthnSigner.js +20 -14
- package/dist/storage/storage.js +5 -4
- package/dist/types/events.js +8 -2
- package/dist/types/examples/api-test.d.ts +12 -0
- package/dist/types/examples/simple-api-test.d.ts +5 -0
- package/dist/types/gundb/api.d.ts +0 -26
- package/dist/types/gundb/db.d.ts +2 -35
- package/dist/types/shogun.js +7 -4
- package/dist/utils/errorHandler.js +13 -8
- package/dist/utils/eventEmitter.js +5 -2
- package/dist/utils/validation.js +14 -7
- package/package.json +2 -1
package/dist/gundb/errors.js
CHANGED
|
@@ -1,63 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Error classes for Gun and Auth
|
|
3
4
|
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NetworkError = exports.MultipleAuthError = exports.TimeoutError = exports.UserExists = exports.InvalidCredentials = exports.AuthError = exports.GunError = void 0;
|
|
4
7
|
/**
|
|
5
8
|
* Base error for Gun
|
|
6
9
|
*/
|
|
7
|
-
|
|
10
|
+
class GunError extends Error {
|
|
8
11
|
constructor(message) {
|
|
9
12
|
super(message);
|
|
10
13
|
this.name = "GunError";
|
|
11
14
|
}
|
|
12
15
|
}
|
|
16
|
+
exports.GunError = GunError;
|
|
13
17
|
/**
|
|
14
18
|
* Generic authentication error
|
|
15
19
|
*/
|
|
16
|
-
|
|
20
|
+
class AuthError extends GunError {
|
|
17
21
|
constructor(message) {
|
|
18
22
|
super(message);
|
|
19
23
|
this.name = "AuthError";
|
|
20
24
|
}
|
|
21
25
|
}
|
|
26
|
+
exports.AuthError = AuthError;
|
|
22
27
|
/**
|
|
23
28
|
* Invalid credentials error
|
|
24
29
|
*/
|
|
25
|
-
|
|
30
|
+
class InvalidCredentials extends AuthError {
|
|
26
31
|
constructor(message = "Credenziali non valide") {
|
|
27
32
|
super(message);
|
|
28
33
|
this.name = "InvalidCredentials";
|
|
29
34
|
}
|
|
30
35
|
}
|
|
36
|
+
exports.InvalidCredentials = InvalidCredentials;
|
|
31
37
|
/**
|
|
32
38
|
* User already exists error
|
|
33
39
|
*/
|
|
34
|
-
|
|
40
|
+
class UserExists extends AuthError {
|
|
35
41
|
constructor(message = "Utente già esistente") {
|
|
36
42
|
super(message);
|
|
37
43
|
this.name = "UserExists";
|
|
38
44
|
}
|
|
39
45
|
}
|
|
46
|
+
exports.UserExists = UserExists;
|
|
40
47
|
/**
|
|
41
48
|
* Timeout error
|
|
42
49
|
*/
|
|
43
|
-
|
|
50
|
+
class TimeoutError extends GunError {
|
|
44
51
|
constructor(message = "Timeout durante l'operazione") {
|
|
45
52
|
super(message);
|
|
46
53
|
this.name = "TimeoutError";
|
|
47
54
|
}
|
|
48
55
|
}
|
|
56
|
+
exports.TimeoutError = TimeoutError;
|
|
49
57
|
/**
|
|
50
58
|
* Multiple authentication error
|
|
51
59
|
*/
|
|
52
|
-
|
|
60
|
+
class MultipleAuthError extends AuthError {
|
|
53
61
|
constructor(message = "Autenticazione multipla in corso") {
|
|
54
62
|
super(message);
|
|
55
63
|
this.name = "MultipleAuthError";
|
|
56
64
|
}
|
|
57
65
|
}
|
|
66
|
+
exports.MultipleAuthError = MultipleAuthError;
|
|
58
67
|
/** Base error related to the network. */
|
|
59
|
-
|
|
68
|
+
class NetworkError extends GunError {
|
|
60
69
|
}
|
|
70
|
+
exports.NetworkError = NetworkError;
|
|
61
71
|
const withDefaultMessage = (args, defaultMessage) => {
|
|
62
72
|
if (args.length === 0 || (args.length === 1 && !args[0])) {
|
|
63
73
|
args = [defaultMessage];
|
package/dist/gundb/index.js
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
17
|
// Export the main class
|
|
2
|
-
|
|
18
|
+
__exportStar(require("./db"), exports);
|
|
3
19
|
// Export improved types
|
|
4
|
-
|
|
20
|
+
__exportStar(require("./types"), exports);
|
|
5
21
|
// Export simplified API
|
|
6
|
-
|
|
22
|
+
__exportStar(require("./api"), exports);
|
package/dist/gundb/rxjs.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RxJS = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
3
6
|
/**
|
|
4
7
|
* RxJS Integration for GunDB
|
|
5
8
|
* Provides reactive programming capabilities for GunDB data
|
|
6
9
|
*/
|
|
7
|
-
|
|
8
|
-
gun;
|
|
9
|
-
user;
|
|
10
|
+
class RxJS {
|
|
10
11
|
/**
|
|
11
12
|
* Initialize GunRxJS with a GunDB instance
|
|
12
13
|
* @param gun - GunDB instance
|
|
@@ -35,7 +36,7 @@ export class RxJS {
|
|
|
35
36
|
* @returns Observable that emits whenever the node changes
|
|
36
37
|
*/
|
|
37
38
|
observe(path) {
|
|
38
|
-
return new Observable((subscriber) => {
|
|
39
|
+
return new rxjs_1.Observable((subscriber) => {
|
|
39
40
|
let node;
|
|
40
41
|
if (Array.isArray(path)) {
|
|
41
42
|
// Support array paths by chaining get calls
|
|
@@ -72,7 +73,7 @@ export class RxJS {
|
|
|
72
73
|
}
|
|
73
74
|
node.off();
|
|
74
75
|
};
|
|
75
|
-
}).pipe(distinctUntilChanged((prev, curr) => {
|
|
76
|
+
}).pipe((0, operators_1.distinctUntilChanged)((prev, curr) => {
|
|
76
77
|
return JSON.stringify(prev) === JSON.stringify(curr);
|
|
77
78
|
}));
|
|
78
79
|
}
|
|
@@ -83,7 +84,7 @@ export class RxJS {
|
|
|
83
84
|
* @returns Observable array of matched items
|
|
84
85
|
*/
|
|
85
86
|
match(path, matchFn) {
|
|
86
|
-
return new Observable((subscriber) => {
|
|
87
|
+
return new rxjs_1.Observable((subscriber) => {
|
|
87
88
|
if (!path) {
|
|
88
89
|
subscriber.next([]);
|
|
89
90
|
subscriber.complete();
|
|
@@ -123,7 +124,7 @@ export class RxJS {
|
|
|
123
124
|
* @returns Observable that completes when the put is acknowledged
|
|
124
125
|
*/
|
|
125
126
|
put(path, data) {
|
|
126
|
-
return new Observable((subscriber) => {
|
|
127
|
+
return new rxjs_1.Observable((subscriber) => {
|
|
127
128
|
const performPut = (target, value) => {
|
|
128
129
|
target.put(value, (ack) => {
|
|
129
130
|
if (ack.err) {
|
|
@@ -158,7 +159,7 @@ export class RxJS {
|
|
|
158
159
|
* Backward-compatible overload that accepts optional callback like tests expect
|
|
159
160
|
*/
|
|
160
161
|
putCompat(data, callback) {
|
|
161
|
-
return new Observable((subscriber) => {
|
|
162
|
+
return new rxjs_1.Observable((subscriber) => {
|
|
162
163
|
this.gun.put(data, (ack) => {
|
|
163
164
|
if (callback)
|
|
164
165
|
callback(ack);
|
|
@@ -179,7 +180,7 @@ export class RxJS {
|
|
|
179
180
|
* @returns Observable that completes when the set is acknowledged
|
|
180
181
|
*/
|
|
181
182
|
set(path, data) {
|
|
182
|
-
return new Observable((subscriber) => {
|
|
183
|
+
return new rxjs_1.Observable((subscriber) => {
|
|
183
184
|
const performSet = (target, value) => {
|
|
184
185
|
target.set(value, (ack) => {
|
|
185
186
|
if (ack.err) {
|
|
@@ -209,7 +210,7 @@ export class RxJS {
|
|
|
209
210
|
});
|
|
210
211
|
}
|
|
211
212
|
setCompat(data, callback) {
|
|
212
|
-
return new Observable((subscriber) => {
|
|
213
|
+
return new rxjs_1.Observable((subscriber) => {
|
|
213
214
|
this.gun.set(data, (ack) => {
|
|
214
215
|
if (callback)
|
|
215
216
|
callback(ack);
|
|
@@ -239,7 +240,7 @@ export class RxJS {
|
|
|
239
240
|
else {
|
|
240
241
|
node = this.gun;
|
|
241
242
|
}
|
|
242
|
-
return new Observable((subscriber) => {
|
|
243
|
+
return new rxjs_1.Observable((subscriber) => {
|
|
243
244
|
node.once((data) => {
|
|
244
245
|
if (data === undefined || data === null) {
|
|
245
246
|
subscriber.next(null);
|
|
@@ -267,7 +268,7 @@ export class RxJS {
|
|
|
267
268
|
return source;
|
|
268
269
|
});
|
|
269
270
|
// Combine the latest values from all sources
|
|
270
|
-
return new Observable((subscriber) => {
|
|
271
|
+
return new rxjs_1.Observable((subscriber) => {
|
|
271
272
|
let values = new Array(sources.length).fill(undefined);
|
|
272
273
|
let completed = new Array(sources.length).fill(false);
|
|
273
274
|
const subscriptions = observables.map((obs, index) => {
|
|
@@ -307,7 +308,7 @@ export class RxJS {
|
|
|
307
308
|
* @returns Observable that completes when the put is acknowledged
|
|
308
309
|
*/
|
|
309
310
|
userPut(dataOrPath, maybeData, callback) {
|
|
310
|
-
return new Observable((subscriber) => {
|
|
311
|
+
return new rxjs_1.Observable((subscriber) => {
|
|
311
312
|
const user = this.gun.user();
|
|
312
313
|
if (typeof dataOrPath === "string") {
|
|
313
314
|
user.get(dataOrPath).put(maybeData, (ack) => {
|
|
@@ -345,7 +346,7 @@ export class RxJS {
|
|
|
345
346
|
* @returns Observable that completes when the set is acknowledged
|
|
346
347
|
*/
|
|
347
348
|
userSet(dataOrPath, maybeData, callback) {
|
|
348
|
-
return new Observable((subscriber) => {
|
|
349
|
+
return new rxjs_1.Observable((subscriber) => {
|
|
349
350
|
const user = this.gun.user();
|
|
350
351
|
if (typeof dataOrPath === "string") {
|
|
351
352
|
user.get(dataOrPath).set(maybeData, (ack) => {
|
|
@@ -382,7 +383,7 @@ export class RxJS {
|
|
|
382
383
|
* @returns Observable that emits the data once
|
|
383
384
|
*/
|
|
384
385
|
userOnce(path, callback) {
|
|
385
|
-
return new Observable((subscriber) => {
|
|
386
|
+
return new rxjs_1.Observable((subscriber) => {
|
|
386
387
|
const user = this.gun.user();
|
|
387
388
|
const target = path ? user.get(path) : user;
|
|
388
389
|
target.once((data, ack) => {
|
|
@@ -443,3 +444,4 @@ export class RxJS {
|
|
|
443
444
|
return cleanObj;
|
|
444
445
|
}
|
|
445
446
|
}
|
|
447
|
+
exports.RxJS = RxJS;
|
package/dist/gundb/types.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,14 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.autoQuickStart = exports.AutoQuickStart = exports.createSimpleAPI = exports.quickStart = exports.QuickStart = exports.SimpleGunAPI = exports.DataBase = exports.GunErrors = exports.derive = exports.crypto = exports.RxJS = exports.SEA = exports.ShogunCore = exports.Gun = void 0;
|
|
21
|
+
const core_1 = require("./core");
|
|
22
|
+
Object.defineProperty(exports, "ShogunCore", { enumerable: true, get: function () { return core_1.ShogunCore; } });
|
|
23
|
+
const db_1 = require("./gundb/db");
|
|
24
|
+
Object.defineProperty(exports, "RxJS", { enumerable: true, get: function () { return db_1.RxJS; } });
|
|
25
|
+
Object.defineProperty(exports, "crypto", { enumerable: true, get: function () { return db_1.crypto; } });
|
|
26
|
+
Object.defineProperty(exports, "derive", { enumerable: true, get: function () { return db_1.derive; } });
|
|
27
|
+
Object.defineProperty(exports, "GunErrors", { enumerable: true, get: function () { return db_1.GunErrors; } });
|
|
28
|
+
Object.defineProperty(exports, "DataBase", { enumerable: true, get: function () { return db_1.DataBase; } });
|
|
3
29
|
// Import Simple API and improved types
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
30
|
+
const gundb_1 = require("./gundb");
|
|
31
|
+
Object.defineProperty(exports, "SimpleGunAPI", { enumerable: true, get: function () { return gundb_1.SimpleGunAPI; } });
|
|
32
|
+
Object.defineProperty(exports, "QuickStart", { enumerable: true, get: function () { return gundb_1.QuickStart; } });
|
|
33
|
+
Object.defineProperty(exports, "quickStart", { enumerable: true, get: function () { return gundb_1.quickStart; } });
|
|
34
|
+
Object.defineProperty(exports, "createSimpleAPI", { enumerable: true, get: function () { return gundb_1.createSimpleAPI; } });
|
|
35
|
+
Object.defineProperty(exports, "AutoQuickStart", { enumerable: true, get: function () { return gundb_1.AutoQuickStart; } });
|
|
36
|
+
Object.defineProperty(exports, "autoQuickStart", { enumerable: true, get: function () { return gundb_1.autoQuickStart; } });
|
|
37
|
+
const db_2 = require("./gundb/db");
|
|
38
|
+
Object.defineProperty(exports, "SEA", { enumerable: true, get: function () { return db_2.SEA; } });
|
|
39
|
+
const db_3 = __importDefault(require("./gundb/db"));
|
|
40
|
+
exports.Gun = db_3.default;
|
|
41
|
+
__exportStar(require("./utils/errorHandler"), exports);
|
|
42
|
+
__exportStar(require("./plugins"), exports);
|
|
43
|
+
__exportStar(require("./interfaces/shogun"), exports);
|
|
10
44
|
// Export simplified configuration
|
|
11
|
-
|
|
12
|
-
export { Gun, ShogunCore, SEA, RxJS, crypto, derive, GunErrors, DataBase,
|
|
13
|
-
// Simple API exports
|
|
14
|
-
SimpleGunAPI, QuickStart, quickStart, createSimpleAPI, AutoQuickStart, autoQuickStart, };
|
|
45
|
+
__exportStar(require("./config/simplified-config"), exports);
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ShogunEventEmitter = void 0;
|
|
4
|
+
const eventEmitter_1 = require("../utils/eventEmitter");
|
|
2
5
|
/**
|
|
3
6
|
* Extended EventEmitter class with typed events for Shogun
|
|
4
7
|
* @class ShogunEventEmitter
|
|
5
8
|
* @extends EventEmitter
|
|
6
9
|
*/
|
|
7
|
-
|
|
10
|
+
class ShogunEventEmitter extends eventEmitter_1.EventEmitter {
|
|
8
11
|
/**
|
|
9
12
|
* Emit a typed Shogun event
|
|
10
13
|
* @template K - Event key type
|
|
@@ -34,3 +37,4 @@ export class ShogunEventEmitter extends EventEmitter {
|
|
|
34
37
|
super.off(event, listener);
|
|
35
38
|
}
|
|
36
39
|
}
|
|
40
|
+
exports.ShogunEventEmitter = ShogunEventEmitter;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CorePlugins = exports.PluginCategory = void 0;
|
|
1
4
|
/**
|
|
2
5
|
* Standard plugin categories in ShogunCore
|
|
3
6
|
*/
|
|
4
|
-
|
|
7
|
+
var PluginCategory;
|
|
5
8
|
(function (PluginCategory) {
|
|
6
9
|
/** Authentication plugins (WebAuthn, MetaMask, Bitcoin) */
|
|
7
10
|
PluginCategory["Authentication"] = "authentication";
|
|
@@ -17,11 +20,11 @@ export var PluginCategory;
|
|
|
17
20
|
PluginCategory["Messages"] = "messages";
|
|
18
21
|
/** Messaging plugins */
|
|
19
22
|
PluginCategory["Other"] = "other";
|
|
20
|
-
})(PluginCategory || (PluginCategory = {}));
|
|
23
|
+
})(PluginCategory || (exports.PluginCategory = PluginCategory = {}));
|
|
21
24
|
/**
|
|
22
25
|
* Standard names for built-in plugins
|
|
23
26
|
*/
|
|
24
|
-
|
|
27
|
+
var CorePlugins;
|
|
25
28
|
(function (CorePlugins) {
|
|
26
29
|
/** WebAuthn plugin */
|
|
27
30
|
CorePlugins["WebAuthn"] = "webauthn";
|
|
@@ -31,4 +34,4 @@ export var CorePlugins;
|
|
|
31
34
|
CorePlugins["Nostr"] = "nostr";
|
|
32
35
|
/** OAuth plugin */
|
|
33
36
|
CorePlugins["OAuth"] = "oauth";
|
|
34
|
-
})(CorePlugins || (CorePlugins = {}));
|
|
37
|
+
})(CorePlugins || (exports.CorePlugins = CorePlugins = {}));
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthManager = void 0;
|
|
4
|
+
const errorHandler_1 = require("../utils/errorHandler");
|
|
2
5
|
/**
|
|
3
6
|
* Manages authentication operations for ShogunCore
|
|
4
7
|
*/
|
|
5
|
-
|
|
6
|
-
core;
|
|
7
|
-
currentAuthMethod;
|
|
8
|
+
class AuthManager {
|
|
8
9
|
constructor(core) {
|
|
9
10
|
this.core = core;
|
|
10
11
|
}
|
|
@@ -31,7 +32,7 @@ export class AuthManager {
|
|
|
31
32
|
this.core.emit("auth:logout");
|
|
32
33
|
}
|
|
33
34
|
catch (error) {
|
|
34
|
-
ErrorHandler.handle(ErrorType.AUTHENTICATION, "LOGOUT_FAILED", error instanceof Error ? error.message : "Error during logout", error);
|
|
35
|
+
errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.AUTHENTICATION, "LOGOUT_FAILED", error instanceof Error ? error.message : "Error during logout", error);
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
/**
|
|
@@ -67,7 +68,7 @@ export class AuthManager {
|
|
|
67
68
|
return result;
|
|
68
69
|
}
|
|
69
70
|
catch (error) {
|
|
70
|
-
ErrorHandler.handle(ErrorType.AUTHENTICATION, "LOGIN_FAILED", error.message ?? "Unknown error during login", error);
|
|
71
|
+
errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.AUTHENTICATION, "LOGIN_FAILED", error.message ?? "Unknown error during login", error);
|
|
71
72
|
return {
|
|
72
73
|
success: false,
|
|
73
74
|
error: error.message ?? "Unknown error during login",
|
|
@@ -110,7 +111,7 @@ export class AuthManager {
|
|
|
110
111
|
return result;
|
|
111
112
|
}
|
|
112
113
|
catch (error) {
|
|
113
|
-
ErrorHandler.handle(ErrorType.AUTHENTICATION, "PAIR_LOGIN_FAILED", error.message ?? "Unknown error during pair login", error);
|
|
114
|
+
errorHandler_1.ErrorHandler.handle(errorHandler_1.ErrorType.AUTHENTICATION, "PAIR_LOGIN_FAILED", error.message ?? "Unknown error during pair login", error);
|
|
114
115
|
return {
|
|
115
116
|
success: false,
|
|
116
117
|
error: error.message ?? "Unknown error during pair login",
|
|
@@ -223,3 +224,4 @@ export class AuthManager {
|
|
|
223
224
|
}
|
|
224
225
|
}
|
|
225
226
|
}
|
|
227
|
+
exports.AuthManager = AuthManager;
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CoreInitializer = void 0;
|
|
4
|
+
const storage_1 = require("../storage/storage");
|
|
5
|
+
const errorHandler_1 = require("../utils/errorHandler");
|
|
6
|
+
const webauthnPlugin_1 = require("../plugins/webauthn/webauthnPlugin");
|
|
7
|
+
const web3ConnectorPlugin_1 = require("../plugins/web3/web3ConnectorPlugin");
|
|
8
|
+
const nostrConnectorPlugin_1 = require("../plugins/nostr/nostrConnectorPlugin");
|
|
9
|
+
const oauthPlugin_1 = require("../plugins/oauth/oauthPlugin");
|
|
10
|
+
const gundb_1 = require("../gundb");
|
|
8
11
|
/**
|
|
9
12
|
* Handles initialization of ShogunCore components
|
|
10
13
|
*/
|
|
11
|
-
|
|
12
|
-
core;
|
|
14
|
+
class CoreInitializer {
|
|
13
15
|
constructor(core) {
|
|
14
16
|
this.core = core;
|
|
15
17
|
}
|
|
@@ -32,9 +34,9 @@ export class CoreInitializer {
|
|
|
32
34
|
};
|
|
33
35
|
}
|
|
34
36
|
// Initialize storage
|
|
35
|
-
this.core.storage = new ShogunStorage();
|
|
37
|
+
this.core.storage = new storage_1.ShogunStorage();
|
|
36
38
|
// Setup error handler
|
|
37
|
-
ErrorHandler.addListener((error) => {
|
|
39
|
+
errorHandler_1.ErrorHandler.addListener((error) => {
|
|
38
40
|
this.core.emit("error", {
|
|
39
41
|
action: error.code,
|
|
40
42
|
message: error.message,
|
|
@@ -50,7 +52,7 @@ export class CoreInitializer {
|
|
|
50
52
|
// Setup wallet derivation
|
|
51
53
|
this.setupWalletDerivation();
|
|
52
54
|
// Initialize RxJS
|
|
53
|
-
this.core.rx = new RxJS(this.core.gun);
|
|
55
|
+
this.core.rx = new gundb_1.RxJS(this.core.gun);
|
|
54
56
|
// Register built-in plugins
|
|
55
57
|
this.registerBuiltinPlugins(config);
|
|
56
58
|
// Initialize async components
|
|
@@ -68,7 +70,7 @@ export class CoreInitializer {
|
|
|
68
70
|
}
|
|
69
71
|
else if (config.gunOptions && config.gunInstance === undefined) {
|
|
70
72
|
console.log("Creating new Gun instance");
|
|
71
|
-
this.core._gun = createGun(config.gunOptions);
|
|
73
|
+
this.core._gun = (0, gundb_1.createGun)(config.gunOptions);
|
|
72
74
|
}
|
|
73
75
|
else if (config.gunInstance && config.gunOptions) {
|
|
74
76
|
// Both provided, prefer gunInstance
|
|
@@ -78,7 +80,7 @@ export class CoreInitializer {
|
|
|
78
80
|
else {
|
|
79
81
|
// Neither provided, create a default Gun instance for testing
|
|
80
82
|
console.log("No Gun instance or options provided, creating default instance");
|
|
81
|
-
this.core._gun = createGun({ peers: config.gunOptions?.peers || [] });
|
|
83
|
+
this.core._gun = (0, gundb_1.createGun)({ peers: config.gunOptions?.peers || [] });
|
|
82
84
|
}
|
|
83
85
|
}
|
|
84
86
|
catch (error) {
|
|
@@ -89,7 +91,7 @@ export class CoreInitializer {
|
|
|
89
91
|
}
|
|
90
92
|
try {
|
|
91
93
|
console.log("Initialize Gun instance", this.core.gun);
|
|
92
|
-
this.core.db = new DataBase(this.core._gun, config.gunOptions?.scope || "");
|
|
94
|
+
this.core.db = new gundb_1.DataBase(this.core._gun, config.gunOptions?.scope || "");
|
|
93
95
|
// Note: user is a getter that returns _user, so we don't need to assign it
|
|
94
96
|
}
|
|
95
97
|
catch (error) {
|
|
@@ -151,7 +153,7 @@ export class CoreInitializer {
|
|
|
151
153
|
return;
|
|
152
154
|
const priv = user._?.sea?.epriv;
|
|
153
155
|
const pub = user._?.sea?.epub;
|
|
154
|
-
this.core.wallets = await derive(priv, pub, {
|
|
156
|
+
this.core.wallets = await (0, gundb_1.derive)(priv, pub, {
|
|
155
157
|
includeSecp256k1Bitcoin: true,
|
|
156
158
|
includeSecp256k1Ethereum: true,
|
|
157
159
|
});
|
|
@@ -167,7 +169,7 @@ export class CoreInitializer {
|
|
|
167
169
|
if (typeof console !== "undefined" && console.warn) {
|
|
168
170
|
console.warn("OAuth plugin will be registered with provided configuration");
|
|
169
171
|
}
|
|
170
|
-
const oauthPlugin = new OAuthPlugin();
|
|
172
|
+
const oauthPlugin = new oauthPlugin_1.OAuthPlugin();
|
|
171
173
|
if (typeof oauthPlugin.configure === "function") {
|
|
172
174
|
oauthPlugin.configure(config.oauth);
|
|
173
175
|
}
|
|
@@ -178,7 +180,7 @@ export class CoreInitializer {
|
|
|
178
180
|
if (typeof console !== "undefined" && console.warn) {
|
|
179
181
|
console.warn("WebAuthn plugin will be registered with provided configuration");
|
|
180
182
|
}
|
|
181
|
-
const webauthnPlugin = new WebauthnPlugin();
|
|
183
|
+
const webauthnPlugin = new webauthnPlugin_1.WebauthnPlugin();
|
|
182
184
|
if (typeof webauthnPlugin.configure === "function") {
|
|
183
185
|
webauthnPlugin.configure(config.webauthn);
|
|
184
186
|
}
|
|
@@ -189,7 +191,7 @@ export class CoreInitializer {
|
|
|
189
191
|
if (typeof console !== "undefined" && console.warn) {
|
|
190
192
|
console.warn("Web3 plugin will be registered with provided configuration");
|
|
191
193
|
}
|
|
192
|
-
const web3Plugin = new Web3ConnectorPlugin();
|
|
194
|
+
const web3Plugin = new web3ConnectorPlugin_1.Web3ConnectorPlugin();
|
|
193
195
|
if (typeof web3Plugin.configure === "function") {
|
|
194
196
|
web3Plugin.configure(config.web3);
|
|
195
197
|
}
|
|
@@ -200,7 +202,7 @@ export class CoreInitializer {
|
|
|
200
202
|
if (typeof console !== "undefined" && console.warn) {
|
|
201
203
|
console.warn("Nostr plugin will be registered with provided configuration");
|
|
202
204
|
}
|
|
203
|
-
const nostrPlugin = new NostrConnectorPlugin();
|
|
205
|
+
const nostrPlugin = new nostrConnectorPlugin_1.NostrConnectorPlugin();
|
|
204
206
|
if (typeof nostrPlugin.configure === "function") {
|
|
205
207
|
nostrPlugin.configure(config.nostr);
|
|
206
208
|
}
|
|
@@ -232,3 +234,4 @@ export class CoreInitializer {
|
|
|
232
234
|
}
|
|
233
235
|
}
|
|
234
236
|
}
|
|
237
|
+
exports.CoreInitializer = CoreInitializer;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventManager = void 0;
|
|
4
|
+
const events_1 = require("../interfaces/events");
|
|
2
5
|
/**
|
|
3
6
|
* Manages event operations for ShogunCore
|
|
4
7
|
*/
|
|
5
|
-
|
|
6
|
-
eventEmitter;
|
|
8
|
+
class EventManager {
|
|
7
9
|
constructor() {
|
|
8
|
-
this.eventEmitter = new ShogunEventEmitter();
|
|
10
|
+
this.eventEmitter = new events_1.ShogunEventEmitter();
|
|
9
11
|
}
|
|
10
12
|
/**
|
|
11
13
|
* Emits an event through the core's event emitter.
|
|
@@ -65,3 +67,4 @@ export class EventManager {
|
|
|
65
67
|
return this.eventEmitter;
|
|
66
68
|
}
|
|
67
69
|
}
|
|
70
|
+
exports.EventManager = EventManager;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PluginManager = void 0;
|
|
1
4
|
/**
|
|
2
5
|
* Manages plugin registration, validation, and lifecycle
|
|
3
6
|
*/
|
|
4
|
-
|
|
5
|
-
plugins = new Map();
|
|
6
|
-
core;
|
|
7
|
+
class PluginManager {
|
|
7
8
|
constructor(core) {
|
|
9
|
+
this.plugins = new Map();
|
|
8
10
|
this.core = core;
|
|
9
11
|
}
|
|
10
12
|
/**
|
|
@@ -294,3 +296,4 @@ export class PluginManager {
|
|
|
294
296
|
return result;
|
|
295
297
|
}
|
|
296
298
|
}
|
|
299
|
+
exports.PluginManager = PluginManager;
|
package/dist/migration-test.js
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Migration test file to verify that the refactored ShogunCore
|
|
3
4
|
* maintains the same public API as the original implementation
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.testApiCompatibility = testApiCompatibility;
|
|
8
|
+
exports.testStaticProperties = testStaticProperties;
|
|
9
|
+
exports.runCompatibilityTests = runCompatibilityTests;
|
|
10
|
+
const core_1 = require("./core");
|
|
11
|
+
const core_2 = require("./core");
|
|
7
12
|
/**
|
|
8
13
|
* Test function to verify API compatibility
|
|
9
14
|
*/
|
|
10
|
-
|
|
15
|
+
function testApiCompatibility() {
|
|
11
16
|
const config = {
|
|
12
17
|
gunOptions: {
|
|
13
18
|
peers: ["https://gunjs.herokuapp.com/gun"],
|
|
14
19
|
},
|
|
15
20
|
};
|
|
16
21
|
// Test that both implementations can be instantiated with the same config
|
|
17
|
-
const originalCore = new
|
|
18
|
-
const refactoredCore = new ShogunCore(config);
|
|
22
|
+
const originalCore = new core_2.ShogunCore(config);
|
|
23
|
+
const refactoredCore = new core_1.ShogunCore(config);
|
|
19
24
|
// Test that all public methods exist on both implementations
|
|
20
25
|
const publicMethods = [
|
|
21
26
|
// Plugin management
|
|
@@ -69,8 +74,8 @@ export function testApiCompatibility() {
|
|
|
69
74
|
/**
|
|
70
75
|
* Test that the refactored implementation maintains the same static properties
|
|
71
76
|
*/
|
|
72
|
-
|
|
73
|
-
if (ShogunCore.API_VERSION !==
|
|
77
|
+
function testStaticProperties() {
|
|
78
|
+
if (core_1.ShogunCore.API_VERSION !== core_2.ShogunCore.API_VERSION) {
|
|
74
79
|
throw new Error("API_VERSION mismatch between implementations");
|
|
75
80
|
}
|
|
76
81
|
console.log("✅ Static properties test passed");
|
|
@@ -78,7 +83,7 @@ export function testStaticProperties() {
|
|
|
78
83
|
/**
|
|
79
84
|
* Run all compatibility tests
|
|
80
85
|
*/
|
|
81
|
-
|
|
86
|
+
function runCompatibilityTests() {
|
|
82
87
|
try {
|
|
83
88
|
testStaticProperties();
|
|
84
89
|
testApiCompatibility();
|
package/dist/plugins/base.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BasePlugin = void 0;
|
|
4
|
+
const eventEmitter_1 = require("../utils/eventEmitter");
|
|
2
5
|
/**
|
|
3
6
|
* Classe base per tutti i plugin di ShogunCore
|
|
4
7
|
* Fornisce funzionalità comuni e implementazione base dell'interfaccia ShogunPlugin
|
|
5
8
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
core = null;
|
|
9
|
+
class BasePlugin extends eventEmitter_1.EventEmitter {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
/** Riferimento all'istanza di ShogunCore */
|
|
13
|
+
this.core = null;
|
|
14
|
+
}
|
|
13
15
|
/**
|
|
14
16
|
* Inizializza il plugin con un'istanza di ShogunCore
|
|
15
17
|
* @param core Istanza di ShogunCore
|
|
@@ -45,3 +47,4 @@ export class BasePlugin extends EventEmitter {
|
|
|
45
47
|
return this.core;
|
|
46
48
|
}
|
|
47
49
|
}
|
|
50
|
+
exports.BasePlugin = BasePlugin;
|