@fenelabs/fene-sdk 0.3.6 → 0.3.8
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/index.d.mts +18 -5
- package/dist/index.d.ts +18 -5
- package/dist/index.js +40 -2
- package/dist/index.mjs +39 -2
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -9,14 +9,17 @@ interface PaginatedResponse<T> {
|
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
11
|
interface NonceResponse {
|
|
12
|
-
address: string;
|
|
13
12
|
nonce: string;
|
|
14
13
|
message: string;
|
|
15
14
|
}
|
|
15
|
+
interface AuthVerifyRequest {
|
|
16
|
+
address: Address;
|
|
17
|
+
signature: string;
|
|
18
|
+
nonce: string;
|
|
19
|
+
}
|
|
16
20
|
interface AuthResponse {
|
|
17
21
|
token: string;
|
|
18
|
-
|
|
19
|
-
role: 'validator' | 'delegator' | 'public';
|
|
22
|
+
role: 'validator' | 'delegator';
|
|
20
23
|
expires_at: number;
|
|
21
24
|
}
|
|
22
25
|
declare enum ValidatorStatus {
|
|
@@ -210,7 +213,7 @@ declare class ResonanceClient {
|
|
|
210
213
|
private request;
|
|
211
214
|
private executeRequest;
|
|
212
215
|
getNonce(address: Address): Promise<NonceResponse>;
|
|
213
|
-
verify(
|
|
216
|
+
verify(params: AuthVerifyRequest): Promise<AuthResponse>;
|
|
214
217
|
getValidators(): Promise<ValidatorSummary[]>;
|
|
215
218
|
getActiveValidators(): Promise<ValidatorSummary[]>;
|
|
216
219
|
getCandidates(): Promise<ValidatorSummary[]>;
|
|
@@ -307,4 +310,14 @@ declare function isAuthError(error: unknown): boolean;
|
|
|
307
310
|
*/
|
|
308
311
|
declare function isNotFoundError(error: unknown): boolean;
|
|
309
312
|
|
|
310
|
-
|
|
313
|
+
type EventCallback = (data?: any) => void;
|
|
314
|
+
declare class EventBus {
|
|
315
|
+
private listeners;
|
|
316
|
+
on(event: string, callback: EventCallback): void;
|
|
317
|
+
off(event: string, callback: EventCallback): void;
|
|
318
|
+
emit(event: string, data?: any): void;
|
|
319
|
+
clear(): void;
|
|
320
|
+
}
|
|
321
|
+
declare const eventBus: EventBus;
|
|
322
|
+
|
|
323
|
+
export { type APIErrorResponse, type Address, type AuthResponse, type AuthVerifyRequest, type AvatarResponse, type DailyBlockStats, type Delegator, type DelegatorRewards, type DelegatorStake, DelegatorStatus, type EpochInfo, ErrorCode, type ErrorCodeType, type GeoNode, type GeoStats, type GeoUpdateRequest, type NetworkAPR, type NetworkStats, type NonceResponse, type PaginatedResponse, type ReferralKey, type RequestContext, ResonanceClient, type ResonanceClientConfig, ResonanceError, type ResponseContext, type RewardHistory, type UploadResponse, type Validator, type ValidatorAPR, ValidatorStatus, type ValidatorSummary, type WhitelistCheckRequest, type WhitelistCheckResponse, createResonanceClient, eventBus, hasErrorCode, isAuthError, isNetworkError, isNotFoundError, isResonanceError };
|
package/dist/index.d.ts
CHANGED
|
@@ -9,14 +9,17 @@ interface PaginatedResponse<T> {
|
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
11
|
interface NonceResponse {
|
|
12
|
-
address: string;
|
|
13
12
|
nonce: string;
|
|
14
13
|
message: string;
|
|
15
14
|
}
|
|
15
|
+
interface AuthVerifyRequest {
|
|
16
|
+
address: Address;
|
|
17
|
+
signature: string;
|
|
18
|
+
nonce: string;
|
|
19
|
+
}
|
|
16
20
|
interface AuthResponse {
|
|
17
21
|
token: string;
|
|
18
|
-
|
|
19
|
-
role: 'validator' | 'delegator' | 'public';
|
|
22
|
+
role: 'validator' | 'delegator';
|
|
20
23
|
expires_at: number;
|
|
21
24
|
}
|
|
22
25
|
declare enum ValidatorStatus {
|
|
@@ -210,7 +213,7 @@ declare class ResonanceClient {
|
|
|
210
213
|
private request;
|
|
211
214
|
private executeRequest;
|
|
212
215
|
getNonce(address: Address): Promise<NonceResponse>;
|
|
213
|
-
verify(
|
|
216
|
+
verify(params: AuthVerifyRequest): Promise<AuthResponse>;
|
|
214
217
|
getValidators(): Promise<ValidatorSummary[]>;
|
|
215
218
|
getActiveValidators(): Promise<ValidatorSummary[]>;
|
|
216
219
|
getCandidates(): Promise<ValidatorSummary[]>;
|
|
@@ -307,4 +310,14 @@ declare function isAuthError(error: unknown): boolean;
|
|
|
307
310
|
*/
|
|
308
311
|
declare function isNotFoundError(error: unknown): boolean;
|
|
309
312
|
|
|
310
|
-
|
|
313
|
+
type EventCallback = (data?: any) => void;
|
|
314
|
+
declare class EventBus {
|
|
315
|
+
private listeners;
|
|
316
|
+
on(event: string, callback: EventCallback): void;
|
|
317
|
+
off(event: string, callback: EventCallback): void;
|
|
318
|
+
emit(event: string, data?: any): void;
|
|
319
|
+
clear(): void;
|
|
320
|
+
}
|
|
321
|
+
declare const eventBus: EventBus;
|
|
322
|
+
|
|
323
|
+
export { type APIErrorResponse, type Address, type AuthResponse, type AuthVerifyRequest, type AvatarResponse, type DailyBlockStats, type Delegator, type DelegatorRewards, type DelegatorStake, DelegatorStatus, type EpochInfo, ErrorCode, type ErrorCodeType, type GeoNode, type GeoStats, type GeoUpdateRequest, type NetworkAPR, type NetworkStats, type NonceResponse, type PaginatedResponse, type ReferralKey, type RequestContext, ResonanceClient, type ResonanceClientConfig, ResonanceError, type ResponseContext, type RewardHistory, type UploadResponse, type Validator, type ValidatorAPR, ValidatorStatus, type ValidatorSummary, type WhitelistCheckRequest, type WhitelistCheckResponse, createResonanceClient, eventBus, hasErrorCode, isAuthError, isNetworkError, isNotFoundError, isResonanceError };
|
package/dist/index.js
CHANGED
|
@@ -24,6 +24,7 @@ __export(index_exports, {
|
|
|
24
24
|
ResonanceClient: () => ResonanceClient,
|
|
25
25
|
ResonanceError: () => ResonanceError,
|
|
26
26
|
createResonanceClient: () => createResonanceClient,
|
|
27
|
+
eventBus: () => eventBus,
|
|
27
28
|
hasErrorCode: () => hasErrorCode,
|
|
28
29
|
isAuthError: () => isAuthError,
|
|
29
30
|
isNetworkError: () => isNetworkError,
|
|
@@ -112,6 +113,35 @@ function isNotFoundError(error) {
|
|
|
112
113
|
return false;
|
|
113
114
|
}
|
|
114
115
|
|
|
116
|
+
// src/eventBus.ts
|
|
117
|
+
var EventBus = class {
|
|
118
|
+
constructor() {
|
|
119
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
120
|
+
}
|
|
121
|
+
on(event, callback) {
|
|
122
|
+
if (!this.listeners.has(event)) {
|
|
123
|
+
this.listeners.set(event, /* @__PURE__ */ new Set());
|
|
124
|
+
}
|
|
125
|
+
this.listeners.get(event).add(callback);
|
|
126
|
+
}
|
|
127
|
+
off(event, callback) {
|
|
128
|
+
this.listeners.get(event)?.delete(callback);
|
|
129
|
+
}
|
|
130
|
+
emit(event, data) {
|
|
131
|
+
this.listeners.get(event)?.forEach((cb) => {
|
|
132
|
+
try {
|
|
133
|
+
cb(data);
|
|
134
|
+
} catch (error) {
|
|
135
|
+
console.error(`EventBus error in ${event} handler:`, error);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
clear() {
|
|
140
|
+
this.listeners.clear();
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
var eventBus = new EventBus();
|
|
144
|
+
|
|
115
145
|
// src/client.ts
|
|
116
146
|
var import_meta = {};
|
|
117
147
|
var DEFAULT_CONFIG = {
|
|
@@ -219,11 +249,14 @@ var ResonanceClient = class {
|
|
|
219
249
|
const response = await fetch(url, {
|
|
220
250
|
...options,
|
|
221
251
|
headers,
|
|
252
|
+
credentials: "include",
|
|
253
|
+
// ✅ Send httpOnly cookies automatically
|
|
222
254
|
signal: controller.signal
|
|
223
255
|
});
|
|
224
256
|
clearTimeout(timeoutId);
|
|
225
257
|
const duration = Date.now() - startTime;
|
|
226
258
|
if (response.status === 401) {
|
|
259
|
+
eventBus.emit("api:unauthorized", { url, method: options.method || "GET" });
|
|
227
260
|
this.onTokenExpired?.();
|
|
228
261
|
}
|
|
229
262
|
if (!response.ok) {
|
|
@@ -294,10 +327,14 @@ var ResonanceClient = class {
|
|
|
294
327
|
async getNonce(address) {
|
|
295
328
|
return this.request(`/eth/v1/auth/nonce?address=${address}`);
|
|
296
329
|
}
|
|
297
|
-
async verify(
|
|
330
|
+
async verify(params) {
|
|
298
331
|
const result = await this.request("/eth/v1/auth/verify", {
|
|
299
332
|
method: "POST",
|
|
300
|
-
body: JSON.stringify({
|
|
333
|
+
body: JSON.stringify({
|
|
334
|
+
address: params.address,
|
|
335
|
+
signature: params.signature,
|
|
336
|
+
nonce: params.nonce
|
|
337
|
+
})
|
|
301
338
|
});
|
|
302
339
|
this.token = result.token;
|
|
303
340
|
return result;
|
|
@@ -426,6 +463,7 @@ function createResonanceClient(config) {
|
|
|
426
463
|
ResonanceClient,
|
|
427
464
|
ResonanceError,
|
|
428
465
|
createResonanceClient,
|
|
466
|
+
eventBus,
|
|
429
467
|
hasErrorCode,
|
|
430
468
|
isAuthError,
|
|
431
469
|
isNetworkError,
|
package/dist/index.mjs
CHANGED
|
@@ -78,6 +78,35 @@ function isNotFoundError(error) {
|
|
|
78
78
|
return false;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
// src/eventBus.ts
|
|
82
|
+
var EventBus = class {
|
|
83
|
+
constructor() {
|
|
84
|
+
this.listeners = /* @__PURE__ */ new Map();
|
|
85
|
+
}
|
|
86
|
+
on(event, callback) {
|
|
87
|
+
if (!this.listeners.has(event)) {
|
|
88
|
+
this.listeners.set(event, /* @__PURE__ */ new Set());
|
|
89
|
+
}
|
|
90
|
+
this.listeners.get(event).add(callback);
|
|
91
|
+
}
|
|
92
|
+
off(event, callback) {
|
|
93
|
+
this.listeners.get(event)?.delete(callback);
|
|
94
|
+
}
|
|
95
|
+
emit(event, data) {
|
|
96
|
+
this.listeners.get(event)?.forEach((cb) => {
|
|
97
|
+
try {
|
|
98
|
+
cb(data);
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.error(`EventBus error in ${event} handler:`, error);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
clear() {
|
|
105
|
+
this.listeners.clear();
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
var eventBus = new EventBus();
|
|
109
|
+
|
|
81
110
|
// src/client.ts
|
|
82
111
|
var DEFAULT_CONFIG = {
|
|
83
112
|
timeout: 3e4,
|
|
@@ -184,11 +213,14 @@ var ResonanceClient = class {
|
|
|
184
213
|
const response = await fetch(url, {
|
|
185
214
|
...options,
|
|
186
215
|
headers,
|
|
216
|
+
credentials: "include",
|
|
217
|
+
// ✅ Send httpOnly cookies automatically
|
|
187
218
|
signal: controller.signal
|
|
188
219
|
});
|
|
189
220
|
clearTimeout(timeoutId);
|
|
190
221
|
const duration = Date.now() - startTime;
|
|
191
222
|
if (response.status === 401) {
|
|
223
|
+
eventBus.emit("api:unauthorized", { url, method: options.method || "GET" });
|
|
192
224
|
this.onTokenExpired?.();
|
|
193
225
|
}
|
|
194
226
|
if (!response.ok) {
|
|
@@ -259,10 +291,14 @@ var ResonanceClient = class {
|
|
|
259
291
|
async getNonce(address) {
|
|
260
292
|
return this.request(`/eth/v1/auth/nonce?address=${address}`);
|
|
261
293
|
}
|
|
262
|
-
async verify(
|
|
294
|
+
async verify(params) {
|
|
263
295
|
const result = await this.request("/eth/v1/auth/verify", {
|
|
264
296
|
method: "POST",
|
|
265
|
-
body: JSON.stringify({
|
|
297
|
+
body: JSON.stringify({
|
|
298
|
+
address: params.address,
|
|
299
|
+
signature: params.signature,
|
|
300
|
+
nonce: params.nonce
|
|
301
|
+
})
|
|
266
302
|
});
|
|
267
303
|
this.token = result.token;
|
|
268
304
|
return result;
|
|
@@ -390,6 +426,7 @@ export {
|
|
|
390
426
|
ResonanceClient,
|
|
391
427
|
ResonanceError,
|
|
392
428
|
createResonanceClient,
|
|
429
|
+
eventBus,
|
|
393
430
|
hasErrorCode,
|
|
394
431
|
isAuthError,
|
|
395
432
|
isNetworkError,
|
package/package.json
CHANGED