@fenelabs/fene-sdk 0.3.7 → 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 +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +34 -0
- package/dist/index.mjs +33 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -310,4 +310,14 @@ declare function isAuthError(error: unknown): boolean;
|
|
|
310
310
|
*/
|
|
311
311
|
declare function isNotFoundError(error: unknown): boolean;
|
|
312
312
|
|
|
313
|
-
|
|
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
|
@@ -310,4 +310,14 @@ declare function isAuthError(error: unknown): boolean;
|
|
|
310
310
|
*/
|
|
311
311
|
declare function isNotFoundError(error: unknown): boolean;
|
|
312
312
|
|
|
313
|
-
|
|
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) {
|
|
@@ -430,6 +463,7 @@ function createResonanceClient(config) {
|
|
|
430
463
|
ResonanceClient,
|
|
431
464
|
ResonanceError,
|
|
432
465
|
createResonanceClient,
|
|
466
|
+
eventBus,
|
|
433
467
|
hasErrorCode,
|
|
434
468
|
isAuthError,
|
|
435
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) {
|
|
@@ -394,6 +426,7 @@ export {
|
|
|
394
426
|
ResonanceClient,
|
|
395
427
|
ResonanceError,
|
|
396
428
|
createResonanceClient,
|
|
429
|
+
eventBus,
|
|
397
430
|
hasErrorCode,
|
|
398
431
|
isAuthError,
|
|
399
432
|
isNetworkError,
|