@ecency/sdk 1.5.1 → 1.5.2
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 +145 -10
- package/dist/browser/index.d.ts +73 -69
- package/dist/browser/index.js +385 -207
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +397 -208
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +385 -203
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.cjs
CHANGED
|
@@ -33,54 +33,7 @@ var __export = (target, all) => {
|
|
|
33
33
|
for (var name in all)
|
|
34
34
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
35
35
|
};
|
|
36
|
-
|
|
37
|
-
// src/modules/keychain/keychain.ts
|
|
38
|
-
var keychain_exports = {};
|
|
39
|
-
__export(keychain_exports, {
|
|
40
|
-
broadcast: () => broadcast,
|
|
41
|
-
customJson: () => customJson,
|
|
42
|
-
handshake: () => handshake
|
|
43
|
-
});
|
|
44
|
-
function handshake() {
|
|
45
|
-
return new Promise((resolve) => {
|
|
46
|
-
window.hive_keychain?.requestHandshake(() => {
|
|
47
|
-
resolve();
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
var broadcast = (account, operations, key, rpc = null) => new Promise((resolve, reject) => {
|
|
52
|
-
window.hive_keychain?.requestBroadcast(
|
|
53
|
-
account,
|
|
54
|
-
operations,
|
|
55
|
-
key,
|
|
56
|
-
(resp) => {
|
|
57
|
-
if (!resp.success) {
|
|
58
|
-
reject({ message: "Operation cancelled" });
|
|
59
|
-
}
|
|
60
|
-
resolve(resp);
|
|
61
|
-
},
|
|
62
|
-
rpc
|
|
63
|
-
);
|
|
64
|
-
});
|
|
65
|
-
var customJson = (account, id, key, json, display_msg, rpc = null) => new Promise((resolve, reject) => {
|
|
66
|
-
window.hive_keychain?.requestCustomJson(
|
|
67
|
-
account,
|
|
68
|
-
id,
|
|
69
|
-
key,
|
|
70
|
-
json,
|
|
71
|
-
display_msg,
|
|
72
|
-
(resp) => {
|
|
73
|
-
if (!resp.success) {
|
|
74
|
-
reject({ message: "Operation cancelled" });
|
|
75
|
-
}
|
|
76
|
-
resolve(resp);
|
|
77
|
-
},
|
|
78
|
-
rpc
|
|
79
|
-
);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
// src/modules/core/mutations/use-broadcast-mutation.ts
|
|
83
|
-
function useBroadcastMutation(mutationKey = [], username, accessToken, operations, onSuccess = () => {
|
|
36
|
+
function useBroadcastMutation(mutationKey = [], username, operations, onSuccess = () => {
|
|
84
37
|
}, auth) {
|
|
85
38
|
return reactQuery.useMutation({
|
|
86
39
|
onSuccess,
|
|
@@ -91,6 +44,9 @@ function useBroadcastMutation(mutationKey = [], username, accessToken, operation
|
|
|
91
44
|
"[Core][Broadcast] Attempted to call broadcast API with anon user"
|
|
92
45
|
);
|
|
93
46
|
}
|
|
47
|
+
if (auth?.broadcast) {
|
|
48
|
+
return auth.broadcast(operations(payload), "posting");
|
|
49
|
+
}
|
|
94
50
|
const postingKey = auth?.postingKey;
|
|
95
51
|
if (postingKey) {
|
|
96
52
|
const privateKey = dhive.PrivateKey.fromString(postingKey);
|
|
@@ -99,34 +55,12 @@ function useBroadcastMutation(mutationKey = [], username, accessToken, operation
|
|
|
99
55
|
privateKey
|
|
100
56
|
);
|
|
101
57
|
}
|
|
102
|
-
const
|
|
103
|
-
if (loginType && loginType == "keychain") {
|
|
104
|
-
return keychain_exports.broadcast(
|
|
105
|
-
username,
|
|
106
|
-
operations(payload),
|
|
107
|
-
"Posting"
|
|
108
|
-
).then((r) => r.result);
|
|
109
|
-
}
|
|
58
|
+
const accessToken = auth?.accessToken;
|
|
110
59
|
if (accessToken) {
|
|
111
|
-
const
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
Authorization: accessToken,
|
|
116
|
-
"Content-Type": "application/json",
|
|
117
|
-
Accept: "application/json"
|
|
118
|
-
},
|
|
119
|
-
body: JSON.stringify({ operations: operations(payload) })
|
|
120
|
-
});
|
|
121
|
-
if (!res.ok) {
|
|
122
|
-
const txt = await res.text().catch(() => "");
|
|
123
|
-
throw new Error(`[Hivesigner] ${res.status} ${res.statusText} ${txt}`);
|
|
124
|
-
}
|
|
125
|
-
const json = await res.json();
|
|
126
|
-
if (json?.errors) {
|
|
127
|
-
throw new Error(`[Hivesigner] ${JSON.stringify(json.errors)}`);
|
|
128
|
-
}
|
|
129
|
-
return json.result;
|
|
60
|
+
const ops2 = operations(payload);
|
|
61
|
+
const client = new hs__default.default.Client({ accessToken });
|
|
62
|
+
const response = await client.broadcast(ops2);
|
|
63
|
+
return response.result;
|
|
130
64
|
}
|
|
131
65
|
throw new Error(
|
|
132
66
|
"[SDK][Broadcast] \u2013 cannot broadcast w/o posting key or token"
|
|
@@ -134,31 +68,9 @@ function useBroadcastMutation(mutationKey = [], username, accessToken, operation
|
|
|
134
68
|
}
|
|
135
69
|
});
|
|
136
70
|
}
|
|
137
|
-
|
|
138
|
-
// src/modules/core/mock-storage.ts
|
|
139
|
-
var MockStorage = class {
|
|
140
|
-
length = 0;
|
|
141
|
-
clear() {
|
|
142
|
-
throw new Error("Method not implemented.");
|
|
143
|
-
}
|
|
144
|
-
getItem(key) {
|
|
145
|
-
return this[key];
|
|
146
|
-
}
|
|
147
|
-
key(index) {
|
|
148
|
-
return Object.keys(this)[index];
|
|
149
|
-
}
|
|
150
|
-
removeItem(key) {
|
|
151
|
-
delete this[key];
|
|
152
|
-
}
|
|
153
|
-
setItem(key, value) {
|
|
154
|
-
this[key] = value;
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
71
|
var CONFIG = {
|
|
158
72
|
privateApiHost: "https://ecency.com",
|
|
159
73
|
imageHost: "https://images.ecency.com",
|
|
160
|
-
storage: typeof window === "undefined" ? new MockStorage() : window.localStorage,
|
|
161
|
-
storagePrefix: "ecency",
|
|
162
74
|
hiveClient: new dhive.Client(
|
|
163
75
|
[
|
|
164
76
|
"https://api.hive.blog",
|
|
@@ -313,7 +225,7 @@ exports.ConfigManager = void 0;
|
|
|
313
225
|
}
|
|
314
226
|
ConfigManager2.setDmcaLists = setDmcaLists;
|
|
315
227
|
})(exports.ConfigManager || (exports.ConfigManager = {}));
|
|
316
|
-
async function broadcastJson(username, id, payload,
|
|
228
|
+
async function broadcastJson(username, id, payload, auth) {
|
|
317
229
|
if (!username) {
|
|
318
230
|
throw new Error(
|
|
319
231
|
"[Core][Broadcast] Attempted to call broadcast API with anon user"
|
|
@@ -325,6 +237,9 @@ async function broadcastJson(username, id, payload, accessToken, auth) {
|
|
|
325
237
|
required_posting_auths: [username],
|
|
326
238
|
json: JSON.stringify(payload)
|
|
327
239
|
};
|
|
240
|
+
if (auth?.broadcast) {
|
|
241
|
+
return auth.broadcast([["custom_json", jjson]], "posting");
|
|
242
|
+
}
|
|
328
243
|
const postingKey = auth?.postingKey;
|
|
329
244
|
if (postingKey) {
|
|
330
245
|
const privateKey = dhive.PrivateKey.fromString(postingKey);
|
|
@@ -333,10 +248,7 @@ async function broadcastJson(username, id, payload, accessToken, auth) {
|
|
|
333
248
|
privateKey
|
|
334
249
|
);
|
|
335
250
|
}
|
|
336
|
-
const
|
|
337
|
-
if (loginType && loginType == "keychain") {
|
|
338
|
-
return keychain_exports.broadcast(username, [["custom_json", jjson]], "Posting").then((r) => r.result);
|
|
339
|
-
}
|
|
251
|
+
const accessToken = auth?.accessToken;
|
|
340
252
|
if (accessToken) {
|
|
341
253
|
const response = await new hs__default.default.Client({
|
|
342
254
|
accessToken
|
|
@@ -347,6 +259,63 @@ async function broadcastJson(username, id, payload, accessToken, auth) {
|
|
|
347
259
|
"[SDK][Broadcast] \u2013 cannot broadcast w/o posting key or token"
|
|
348
260
|
);
|
|
349
261
|
}
|
|
262
|
+
function makeQueryClient() {
|
|
263
|
+
return new reactQuery.QueryClient({
|
|
264
|
+
defaultOptions: {
|
|
265
|
+
queries: {
|
|
266
|
+
// With SSR, we usually want to set some default staleTime
|
|
267
|
+
// above 0 to avoid refetching immediately on the client
|
|
268
|
+
// staleTime: 60 * 1000,
|
|
269
|
+
refetchOnWindowFocus: false,
|
|
270
|
+
refetchOnMount: false
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
var getQueryClient = () => CONFIG.queryClient;
|
|
276
|
+
exports.EcencyQueriesManager = void 0;
|
|
277
|
+
((EcencyQueriesManager2) => {
|
|
278
|
+
function getQueryData(queryKey) {
|
|
279
|
+
const queryClient = getQueryClient();
|
|
280
|
+
return queryClient.getQueryData(queryKey);
|
|
281
|
+
}
|
|
282
|
+
EcencyQueriesManager2.getQueryData = getQueryData;
|
|
283
|
+
function getInfiniteQueryData(queryKey) {
|
|
284
|
+
const queryClient = getQueryClient();
|
|
285
|
+
return queryClient.getQueryData(queryKey);
|
|
286
|
+
}
|
|
287
|
+
EcencyQueriesManager2.getInfiniteQueryData = getInfiniteQueryData;
|
|
288
|
+
async function prefetchQuery(options) {
|
|
289
|
+
const queryClient = getQueryClient();
|
|
290
|
+
await queryClient.prefetchQuery(options);
|
|
291
|
+
return getQueryData(options.queryKey);
|
|
292
|
+
}
|
|
293
|
+
EcencyQueriesManager2.prefetchQuery = prefetchQuery;
|
|
294
|
+
async function prefetchInfiniteQuery(options) {
|
|
295
|
+
const queryClient = getQueryClient();
|
|
296
|
+
await queryClient.prefetchInfiniteQuery(options);
|
|
297
|
+
return getInfiniteQueryData(options.queryKey);
|
|
298
|
+
}
|
|
299
|
+
EcencyQueriesManager2.prefetchInfiniteQuery = prefetchInfiniteQuery;
|
|
300
|
+
function generateClientServerQuery(options) {
|
|
301
|
+
return {
|
|
302
|
+
prefetch: () => prefetchQuery(options),
|
|
303
|
+
getData: () => getQueryData(options.queryKey),
|
|
304
|
+
useClientQuery: () => reactQuery.useQuery(options),
|
|
305
|
+
fetchAndGet: () => getQueryClient().fetchQuery(options)
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
EcencyQueriesManager2.generateClientServerQuery = generateClientServerQuery;
|
|
309
|
+
function generateClientServerInfiniteQuery(options) {
|
|
310
|
+
return {
|
|
311
|
+
prefetch: () => prefetchInfiniteQuery(options),
|
|
312
|
+
getData: () => getInfiniteQueryData(options.queryKey),
|
|
313
|
+
useClientQuery: () => reactQuery.useInfiniteQuery(options),
|
|
314
|
+
fetchAndGet: () => getQueryClient().fetchInfiniteQuery(options)
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
EcencyQueriesManager2.generateClientServerInfiniteQuery = generateClientServerInfiniteQuery;
|
|
318
|
+
})(exports.EcencyQueriesManager || (exports.EcencyQueriesManager = {}));
|
|
350
319
|
|
|
351
320
|
// src/modules/core/utils/decoder-encoder.ts
|
|
352
321
|
function encodeObj(o) {
|
|
@@ -408,79 +377,7 @@ function isCommunity(value) {
|
|
|
408
377
|
return typeof value === "string" ? /^hive-\d+$/.test(value) : false;
|
|
409
378
|
}
|
|
410
379
|
|
|
411
|
-
// src/modules/core/
|
|
412
|
-
var getUser = (username) => {
|
|
413
|
-
try {
|
|
414
|
-
const raw = CONFIG.storage.getItem(
|
|
415
|
-
CONFIG.storagePrefix + "_user_" + username
|
|
416
|
-
);
|
|
417
|
-
return decodeObj(JSON.parse(raw));
|
|
418
|
-
} catch (e) {
|
|
419
|
-
console.error(e);
|
|
420
|
-
return void 0;
|
|
421
|
-
}
|
|
422
|
-
};
|
|
423
|
-
var getAccessToken = (username) => getUser(username) && getUser(username).accessToken;
|
|
424
|
-
var getPostingKey = (username) => getUser(username) && getUser(username).postingKey;
|
|
425
|
-
var getLoginType = (username) => getUser(username) && getUser(username).loginType;
|
|
426
|
-
var getRefreshToken = (username) => getUser(username) && getUser(username).refreshToken;
|
|
427
|
-
function makeQueryClient() {
|
|
428
|
-
return new reactQuery.QueryClient({
|
|
429
|
-
defaultOptions: {
|
|
430
|
-
queries: {
|
|
431
|
-
// With SSR, we usually want to set some default staleTime
|
|
432
|
-
// above 0 to avoid refetching immediately on the client
|
|
433
|
-
// staleTime: 60 * 1000,
|
|
434
|
-
refetchOnWindowFocus: false,
|
|
435
|
-
refetchOnMount: false
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
var getQueryClient = () => CONFIG.queryClient;
|
|
441
|
-
exports.EcencyQueriesManager = void 0;
|
|
442
|
-
((EcencyQueriesManager2) => {
|
|
443
|
-
function getQueryData(queryKey) {
|
|
444
|
-
const queryClient = getQueryClient();
|
|
445
|
-
return queryClient.getQueryData(queryKey);
|
|
446
|
-
}
|
|
447
|
-
EcencyQueriesManager2.getQueryData = getQueryData;
|
|
448
|
-
function getInfiniteQueryData(queryKey) {
|
|
449
|
-
const queryClient = getQueryClient();
|
|
450
|
-
return queryClient.getQueryData(queryKey);
|
|
451
|
-
}
|
|
452
|
-
EcencyQueriesManager2.getInfiniteQueryData = getInfiniteQueryData;
|
|
453
|
-
async function prefetchQuery(options) {
|
|
454
|
-
const queryClient = getQueryClient();
|
|
455
|
-
await queryClient.prefetchQuery(options);
|
|
456
|
-
return getQueryData(options.queryKey);
|
|
457
|
-
}
|
|
458
|
-
EcencyQueriesManager2.prefetchQuery = prefetchQuery;
|
|
459
|
-
async function prefetchInfiniteQuery(options) {
|
|
460
|
-
const queryClient = getQueryClient();
|
|
461
|
-
await queryClient.prefetchInfiniteQuery(options);
|
|
462
|
-
return getInfiniteQueryData(options.queryKey);
|
|
463
|
-
}
|
|
464
|
-
EcencyQueriesManager2.prefetchInfiniteQuery = prefetchInfiniteQuery;
|
|
465
|
-
function generateClientServerQuery(options) {
|
|
466
|
-
return {
|
|
467
|
-
prefetch: () => prefetchQuery(options),
|
|
468
|
-
getData: () => getQueryData(options.queryKey),
|
|
469
|
-
useClientQuery: () => reactQuery.useQuery(options),
|
|
470
|
-
fetchAndGet: () => getQueryClient().fetchQuery(options)
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
EcencyQueriesManager2.generateClientServerQuery = generateClientServerQuery;
|
|
474
|
-
function generateClientServerInfiniteQuery(options) {
|
|
475
|
-
return {
|
|
476
|
-
prefetch: () => prefetchInfiniteQuery(options),
|
|
477
|
-
getData: () => getInfiniteQueryData(options.queryKey),
|
|
478
|
-
useClientQuery: () => reactQuery.useInfiniteQuery(options),
|
|
479
|
-
fetchAndGet: () => getQueryClient().fetchInfiniteQuery(options)
|
|
480
|
-
};
|
|
481
|
-
}
|
|
482
|
-
EcencyQueriesManager2.generateClientServerInfiniteQuery = generateClientServerInfiniteQuery;
|
|
483
|
-
})(exports.EcencyQueriesManager || (exports.EcencyQueriesManager = {}));
|
|
380
|
+
// src/modules/core/queries/get-dynamic-props-query-options.ts
|
|
484
381
|
function getDynamicPropsQueryOptions() {
|
|
485
382
|
return reactQuery.queryOptions({
|
|
486
383
|
queryKey: ["core", "dynamic-props"],
|
|
@@ -2409,13 +2306,12 @@ function getProfilesQueryOptions(accounts, observer, enabled = true) {
|
|
|
2409
2306
|
}
|
|
2410
2307
|
|
|
2411
2308
|
// src/modules/accounts/mutations/use-account-update.ts
|
|
2412
|
-
function useAccountUpdate(username,
|
|
2309
|
+
function useAccountUpdate(username, auth) {
|
|
2413
2310
|
const queryClient = reactQuery.useQueryClient();
|
|
2414
2311
|
const { data } = reactQuery.useQuery(getAccountFullQueryOptions(username));
|
|
2415
2312
|
return useBroadcastMutation(
|
|
2416
2313
|
["accounts", "update"],
|
|
2417
2314
|
username,
|
|
2418
|
-
accessToken,
|
|
2419
2315
|
(payload) => {
|
|
2420
2316
|
if (!data) {
|
|
2421
2317
|
throw new Error("[SDK][Accounts] \u2013 cannot update not existing account");
|
|
@@ -2457,7 +2353,7 @@ function useAccountUpdate(username, accessToken, auth) {
|
|
|
2457
2353
|
auth
|
|
2458
2354
|
);
|
|
2459
2355
|
}
|
|
2460
|
-
function useAccountRelationsUpdate(reference, target, onSuccess, onError) {
|
|
2356
|
+
function useAccountRelationsUpdate(reference, target, auth, onSuccess, onError) {
|
|
2461
2357
|
return reactQuery.useMutation({
|
|
2462
2358
|
mutationKey: ["accounts", "relation", "update", reference, target],
|
|
2463
2359
|
mutationFn: async (kind) => {
|
|
@@ -2469,17 +2365,22 @@ function useAccountRelationsUpdate(reference, target, onSuccess, onError) {
|
|
|
2469
2365
|
const actualRelation = getQueryClient().getQueryData(
|
|
2470
2366
|
relationsQuery.queryKey
|
|
2471
2367
|
);
|
|
2472
|
-
await broadcastJson(
|
|
2368
|
+
await broadcastJson(
|
|
2369
|
+
reference,
|
|
2473
2370
|
"follow",
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2371
|
+
[
|
|
2372
|
+
"follow",
|
|
2373
|
+
{
|
|
2374
|
+
follower: reference,
|
|
2375
|
+
following: target,
|
|
2376
|
+
what: [
|
|
2377
|
+
...kind === "toggle-ignore" && !actualRelation?.ignores ? ["ignore"] : [],
|
|
2378
|
+
...kind === "toggle-follow" && !actualRelation?.follows ? ["blog"] : []
|
|
2379
|
+
]
|
|
2380
|
+
}
|
|
2381
|
+
],
|
|
2382
|
+
auth
|
|
2383
|
+
);
|
|
2483
2384
|
return {
|
|
2484
2385
|
...actualRelation,
|
|
2485
2386
|
ignores: kind === "toggle-ignore" ? !actualRelation?.ignores : actualRelation?.ignores,
|
|
@@ -2706,7 +2607,7 @@ function useAccountUpdatePassword(username, options) {
|
|
|
2706
2607
|
...options
|
|
2707
2608
|
});
|
|
2708
2609
|
}
|
|
2709
|
-
function useAccountRevokePosting(username, options) {
|
|
2610
|
+
function useAccountRevokePosting(username, options, auth) {
|
|
2710
2611
|
const queryClient = reactQuery.useQueryClient();
|
|
2711
2612
|
const { data } = reactQuery.useQuery(getAccountFullQueryOptions(username));
|
|
2712
2613
|
return reactQuery.useMutation({
|
|
@@ -2733,11 +2634,10 @@ function useAccountRevokePosting(username, options) {
|
|
|
2733
2634
|
if (type === "key" && key) {
|
|
2734
2635
|
return CONFIG.hiveClient.broadcast.updateAccount(operationBody, key);
|
|
2735
2636
|
} else if (type === "keychain") {
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
);
|
|
2637
|
+
if (!auth?.broadcast) {
|
|
2638
|
+
throw new Error("[SDK][Accounts] \u2013 missing keychain broadcaster");
|
|
2639
|
+
}
|
|
2640
|
+
return auth.broadcast([["account_update", operationBody]], "active");
|
|
2741
2641
|
} else {
|
|
2742
2642
|
const params = {
|
|
2743
2643
|
callback: `https://ecency.com/@${data.name}/permissions`
|
|
@@ -2768,7 +2668,7 @@ function useAccountRevokePosting(username, options) {
|
|
|
2768
2668
|
}
|
|
2769
2669
|
});
|
|
2770
2670
|
}
|
|
2771
|
-
function useAccountUpdateRecovery(username, code, options) {
|
|
2671
|
+
function useAccountUpdateRecovery(username, code, options, auth) {
|
|
2772
2672
|
const { data } = reactQuery.useQuery(getAccountFullQueryOptions(username));
|
|
2773
2673
|
return reactQuery.useMutation({
|
|
2774
2674
|
mutationKey: ["accounts", "recovery", data?.name],
|
|
@@ -2807,11 +2707,10 @@ function useAccountUpdateRecovery(username, code, options) {
|
|
|
2807
2707
|
key
|
|
2808
2708
|
);
|
|
2809
2709
|
} else if (type === "keychain") {
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
);
|
|
2710
|
+
if (!auth?.broadcast) {
|
|
2711
|
+
throw new Error("[SDK][Accounts] \u2013 missing keychain broadcaster");
|
|
2712
|
+
}
|
|
2713
|
+
return auth.broadcast([["change_recovery_account", operationBody]], "owner");
|
|
2815
2714
|
} else {
|
|
2816
2715
|
const params = {
|
|
2817
2716
|
callback: `https://ecency.com/@${data.name}/permissions`
|
|
@@ -3031,7 +2930,7 @@ function useSignOperationByKey(username) {
|
|
|
3031
2930
|
}
|
|
3032
2931
|
});
|
|
3033
2932
|
}
|
|
3034
|
-
function useSignOperationByKeychain(username, keyType = "
|
|
2933
|
+
function useSignOperationByKeychain(username, auth, keyType = "active") {
|
|
3035
2934
|
return reactQuery.useMutation({
|
|
3036
2935
|
mutationKey: ["operations", "sign-keychain", username],
|
|
3037
2936
|
mutationFn: ({ operation }) => {
|
|
@@ -3040,7 +2939,10 @@ function useSignOperationByKeychain(username, keyType = "Active") {
|
|
|
3040
2939
|
"[SDK][Keychain] \u2013\xA0cannot sign operation with anon user"
|
|
3041
2940
|
);
|
|
3042
2941
|
}
|
|
3043
|
-
|
|
2942
|
+
if (!auth?.broadcast) {
|
|
2943
|
+
throw new Error("[SDK][Keychain] \u2013 missing keychain broadcaster");
|
|
2944
|
+
}
|
|
2945
|
+
return auth.broadcast([operation], keyType);
|
|
3044
2946
|
}
|
|
3045
2947
|
});
|
|
3046
2948
|
}
|
|
@@ -4203,6 +4105,13 @@ async function getCurrencyRates() {
|
|
|
4203
4105
|
const response = await fetchApi(CONFIG.privateApiHost + "/private-api/market-data/latest");
|
|
4204
4106
|
return parseJsonResponse(response);
|
|
4205
4107
|
}
|
|
4108
|
+
async function getHivePrice() {
|
|
4109
|
+
const fetchApi = getBoundFetch();
|
|
4110
|
+
const response = await fetchApi(
|
|
4111
|
+
"https://api.coingecko.com/api/v3/simple/price?ids=hive&vs_currencies=usd"
|
|
4112
|
+
);
|
|
4113
|
+
return parseJsonResponse(response);
|
|
4114
|
+
}
|
|
4206
4115
|
function getPointsQueryOptions(username, filter = 0) {
|
|
4207
4116
|
return reactQuery.queryOptions({
|
|
4208
4117
|
queryKey: ["points", username, filter],
|
|
@@ -4931,13 +4840,285 @@ async function hsTokenRenew(code) {
|
|
|
4931
4840
|
return data;
|
|
4932
4841
|
}
|
|
4933
4842
|
|
|
4843
|
+
// src/modules/hive-engine/requests.ts
|
|
4844
|
+
var ENGINE_RPC_HEADERS = { "Content-type": "application/json" };
|
|
4845
|
+
async function engineRpc(payload) {
|
|
4846
|
+
const fetchApi = getBoundFetch();
|
|
4847
|
+
const response = await fetchApi(`${CONFIG.privateApiHost}/private-api/engine-api`, {
|
|
4848
|
+
method: "POST",
|
|
4849
|
+
body: JSON.stringify(payload),
|
|
4850
|
+
headers: ENGINE_RPC_HEADERS
|
|
4851
|
+
});
|
|
4852
|
+
if (!response.ok) {
|
|
4853
|
+
throw new Error(
|
|
4854
|
+
`[SDK][HiveEngine] \u2013 request failed with ${response.status}`
|
|
4855
|
+
);
|
|
4856
|
+
}
|
|
4857
|
+
const data = await response.json();
|
|
4858
|
+
return data.result;
|
|
4859
|
+
}
|
|
4860
|
+
async function engineRpcSafe(payload, fallback) {
|
|
4861
|
+
try {
|
|
4862
|
+
return await engineRpc(payload);
|
|
4863
|
+
} catch (e) {
|
|
4864
|
+
return fallback;
|
|
4865
|
+
}
|
|
4866
|
+
}
|
|
4867
|
+
async function getHiveEngineOrderBook(symbol, limit = 50) {
|
|
4868
|
+
const baseParams = {
|
|
4869
|
+
jsonrpc: "2.0",
|
|
4870
|
+
method: "find",
|
|
4871
|
+
params: {
|
|
4872
|
+
contract: "market",
|
|
4873
|
+
query: { symbol },
|
|
4874
|
+
limit,
|
|
4875
|
+
offset: 0
|
|
4876
|
+
},
|
|
4877
|
+
id: 1
|
|
4878
|
+
};
|
|
4879
|
+
const [buy, sell] = await Promise.all([
|
|
4880
|
+
engineRpcSafe(
|
|
4881
|
+
{
|
|
4882
|
+
...baseParams,
|
|
4883
|
+
params: {
|
|
4884
|
+
...baseParams.params,
|
|
4885
|
+
table: "buyBook",
|
|
4886
|
+
indexes: [{ index: "price", descending: true }]
|
|
4887
|
+
}
|
|
4888
|
+
},
|
|
4889
|
+
[]
|
|
4890
|
+
),
|
|
4891
|
+
engineRpcSafe(
|
|
4892
|
+
{
|
|
4893
|
+
...baseParams,
|
|
4894
|
+
params: {
|
|
4895
|
+
...baseParams.params,
|
|
4896
|
+
table: "sellBook",
|
|
4897
|
+
indexes: [{ index: "price", descending: false }]
|
|
4898
|
+
}
|
|
4899
|
+
},
|
|
4900
|
+
[]
|
|
4901
|
+
)
|
|
4902
|
+
]);
|
|
4903
|
+
const sortByPriceDesc = (items) => items.sort((a, b) => {
|
|
4904
|
+
const left = Number(a.price ?? 0);
|
|
4905
|
+
const right = Number(b.price ?? 0);
|
|
4906
|
+
return right - left;
|
|
4907
|
+
});
|
|
4908
|
+
const sortByPriceAsc = (items) => items.sort((a, b) => {
|
|
4909
|
+
const left = Number(a.price ?? 0);
|
|
4910
|
+
const right = Number(b.price ?? 0);
|
|
4911
|
+
return left - right;
|
|
4912
|
+
});
|
|
4913
|
+
return {
|
|
4914
|
+
buy: sortByPriceDesc(buy),
|
|
4915
|
+
sell: sortByPriceAsc(sell)
|
|
4916
|
+
};
|
|
4917
|
+
}
|
|
4918
|
+
async function getHiveEngineTradeHistory(symbol, limit = 50) {
|
|
4919
|
+
return engineRpcSafe(
|
|
4920
|
+
{
|
|
4921
|
+
jsonrpc: "2.0",
|
|
4922
|
+
method: "find",
|
|
4923
|
+
params: {
|
|
4924
|
+
contract: "market",
|
|
4925
|
+
table: "tradesHistory",
|
|
4926
|
+
query: { symbol },
|
|
4927
|
+
limit,
|
|
4928
|
+
offset: 0,
|
|
4929
|
+
indexes: [{ index: "timestamp", descending: true }]
|
|
4930
|
+
},
|
|
4931
|
+
id: 1
|
|
4932
|
+
},
|
|
4933
|
+
[]
|
|
4934
|
+
);
|
|
4935
|
+
}
|
|
4936
|
+
async function getHiveEngineOpenOrders(account, symbol, limit = 100) {
|
|
4937
|
+
const baseParams = {
|
|
4938
|
+
jsonrpc: "2.0",
|
|
4939
|
+
method: "find",
|
|
4940
|
+
params: {
|
|
4941
|
+
contract: "market",
|
|
4942
|
+
query: { symbol, account },
|
|
4943
|
+
limit,
|
|
4944
|
+
offset: 0
|
|
4945
|
+
},
|
|
4946
|
+
id: 1
|
|
4947
|
+
};
|
|
4948
|
+
const [buyRaw, sellRaw] = await Promise.all([
|
|
4949
|
+
engineRpcSafe(
|
|
4950
|
+
{
|
|
4951
|
+
...baseParams,
|
|
4952
|
+
params: {
|
|
4953
|
+
...baseParams.params,
|
|
4954
|
+
table: "buyBook",
|
|
4955
|
+
indexes: [{ index: "timestamp", descending: true }]
|
|
4956
|
+
}
|
|
4957
|
+
},
|
|
4958
|
+
[]
|
|
4959
|
+
),
|
|
4960
|
+
engineRpcSafe(
|
|
4961
|
+
{
|
|
4962
|
+
...baseParams,
|
|
4963
|
+
params: {
|
|
4964
|
+
...baseParams.params,
|
|
4965
|
+
table: "sellBook",
|
|
4966
|
+
indexes: [{ index: "timestamp", descending: true }]
|
|
4967
|
+
}
|
|
4968
|
+
},
|
|
4969
|
+
[]
|
|
4970
|
+
)
|
|
4971
|
+
]);
|
|
4972
|
+
const formatTotal = (quantity, price) => (Number(quantity || 0) * Number(price || 0)).toFixed(8);
|
|
4973
|
+
const buy = buyRaw.map((order) => ({
|
|
4974
|
+
id: order.txId,
|
|
4975
|
+
type: "buy",
|
|
4976
|
+
account: order.account,
|
|
4977
|
+
symbol: order.symbol,
|
|
4978
|
+
quantity: order.quantity,
|
|
4979
|
+
price: order.price,
|
|
4980
|
+
total: order.tokensLocked ?? formatTotal(order.quantity, order.price),
|
|
4981
|
+
timestamp: Number(order.timestamp ?? 0)
|
|
4982
|
+
}));
|
|
4983
|
+
const sell = sellRaw.map((order) => ({
|
|
4984
|
+
id: order.txId,
|
|
4985
|
+
type: "sell",
|
|
4986
|
+
account: order.account,
|
|
4987
|
+
symbol: order.symbol,
|
|
4988
|
+
quantity: order.quantity,
|
|
4989
|
+
price: order.price,
|
|
4990
|
+
total: formatTotal(order.quantity, order.price),
|
|
4991
|
+
timestamp: Number(order.timestamp ?? 0)
|
|
4992
|
+
}));
|
|
4993
|
+
return [...buy, ...sell].sort((a, b) => b.timestamp - a.timestamp);
|
|
4994
|
+
}
|
|
4995
|
+
async function getHiveEngineMetrics(symbol, account) {
|
|
4996
|
+
return engineRpcSafe(
|
|
4997
|
+
{
|
|
4998
|
+
jsonrpc: "2.0",
|
|
4999
|
+
method: "find",
|
|
5000
|
+
params: {
|
|
5001
|
+
contract: "market",
|
|
5002
|
+
table: "metrics",
|
|
5003
|
+
query: {
|
|
5004
|
+
...symbol ? { symbol } : {},
|
|
5005
|
+
...account ? { account } : {}
|
|
5006
|
+
}
|
|
5007
|
+
},
|
|
5008
|
+
id: 1
|
|
5009
|
+
},
|
|
5010
|
+
[]
|
|
5011
|
+
);
|
|
5012
|
+
}
|
|
5013
|
+
async function getHiveEngineTokensMarket(account, symbol) {
|
|
5014
|
+
return getHiveEngineMetrics(symbol, account);
|
|
5015
|
+
}
|
|
5016
|
+
async function getHiveEngineTokensBalances(username) {
|
|
5017
|
+
return engineRpcSafe(
|
|
5018
|
+
{
|
|
5019
|
+
jsonrpc: "2.0",
|
|
5020
|
+
method: "find",
|
|
5021
|
+
params: {
|
|
5022
|
+
contract: "tokens",
|
|
5023
|
+
table: "balances",
|
|
5024
|
+
query: {
|
|
5025
|
+
account: username
|
|
5026
|
+
}
|
|
5027
|
+
},
|
|
5028
|
+
id: 1
|
|
5029
|
+
},
|
|
5030
|
+
[]
|
|
5031
|
+
);
|
|
5032
|
+
}
|
|
5033
|
+
async function getHiveEngineTokensMetadata(tokens) {
|
|
5034
|
+
return engineRpcSafe(
|
|
5035
|
+
{
|
|
5036
|
+
jsonrpc: "2.0",
|
|
5037
|
+
method: "find",
|
|
5038
|
+
params: {
|
|
5039
|
+
contract: "tokens",
|
|
5040
|
+
table: "tokens",
|
|
5041
|
+
query: {
|
|
5042
|
+
symbol: { $in: tokens }
|
|
5043
|
+
}
|
|
5044
|
+
},
|
|
5045
|
+
id: 2
|
|
5046
|
+
},
|
|
5047
|
+
[]
|
|
5048
|
+
);
|
|
5049
|
+
}
|
|
5050
|
+
async function getHiveEngineTokenTransactions(username, symbol, limit, offset) {
|
|
5051
|
+
const fetchApi = getBoundFetch();
|
|
5052
|
+
const url = new URL(
|
|
5053
|
+
`${CONFIG.privateApiHost}/private-api/engine-account-history`
|
|
5054
|
+
);
|
|
5055
|
+
url.searchParams.set("account", username);
|
|
5056
|
+
url.searchParams.set("symbol", symbol);
|
|
5057
|
+
url.searchParams.set("limit", limit.toString());
|
|
5058
|
+
url.searchParams.set("offset", offset.toString());
|
|
5059
|
+
const response = await fetchApi(url.toString(), {
|
|
5060
|
+
method: "GET",
|
|
5061
|
+
headers: { "Content-type": "application/json" }
|
|
5062
|
+
});
|
|
5063
|
+
if (!response.ok) {
|
|
5064
|
+
throw new Error(
|
|
5065
|
+
`[SDK][HiveEngine] \u2013 account history failed with ${response.status}`
|
|
5066
|
+
);
|
|
5067
|
+
}
|
|
5068
|
+
return await response.json();
|
|
5069
|
+
}
|
|
5070
|
+
async function getHiveEngineTokenMetrics(symbol, interval = "daily") {
|
|
5071
|
+
const fetchApi = getBoundFetch();
|
|
5072
|
+
const url = new URL(`${CONFIG.privateApiHost}/private-api/engine-chart-api`);
|
|
5073
|
+
url.searchParams.set("symbol", symbol);
|
|
5074
|
+
url.searchParams.set("interval", interval);
|
|
5075
|
+
const response = await fetchApi(url.toString(), {
|
|
5076
|
+
headers: { "Content-type": "application/json" }
|
|
5077
|
+
});
|
|
5078
|
+
if (!response.ok) {
|
|
5079
|
+
throw new Error(
|
|
5080
|
+
`[SDK][HiveEngine] \u2013 chart failed with ${response.status}`
|
|
5081
|
+
);
|
|
5082
|
+
}
|
|
5083
|
+
return await response.json();
|
|
5084
|
+
}
|
|
5085
|
+
async function getHiveEngineUnclaimedRewards(username) {
|
|
5086
|
+
const fetchApi = getBoundFetch();
|
|
5087
|
+
const response = await fetchApi(
|
|
5088
|
+
`${CONFIG.privateApiHost}/private-api/engine-reward-api/${username}?hive=1`
|
|
5089
|
+
);
|
|
5090
|
+
if (!response.ok) {
|
|
5091
|
+
throw new Error(
|
|
5092
|
+
`[SDK][HiveEngine] \u2013 rewards failed with ${response.status}`
|
|
5093
|
+
);
|
|
5094
|
+
}
|
|
5095
|
+
return await response.json();
|
|
5096
|
+
}
|
|
5097
|
+
|
|
5098
|
+
// src/modules/spk/requests.ts
|
|
5099
|
+
async function getSpkWallet(username) {
|
|
5100
|
+
const fetchApi = getBoundFetch();
|
|
5101
|
+
const response = await fetchApi(`${CONFIG.spkNode}/@${username}`);
|
|
5102
|
+
if (!response.ok) {
|
|
5103
|
+
throw new Error(`[SDK][SPK] \u2013 wallet failed with ${response.status}`);
|
|
5104
|
+
}
|
|
5105
|
+
return await response.json();
|
|
5106
|
+
}
|
|
5107
|
+
async function getSpkMarkets() {
|
|
5108
|
+
const fetchApi = getBoundFetch();
|
|
5109
|
+
const response = await fetchApi(`${CONFIG.spkNode}/markets`);
|
|
5110
|
+
if (!response.ok) {
|
|
5111
|
+
throw new Error(`[SDK][SPK] \u2013 markets failed with ${response.status}`);
|
|
5112
|
+
}
|
|
5113
|
+
return await response.json();
|
|
5114
|
+
}
|
|
5115
|
+
|
|
4934
5116
|
exports.ACCOUNT_OPERATION_GROUPS = ACCOUNT_OPERATION_GROUPS;
|
|
4935
5117
|
exports.ALL_ACCOUNT_OPERATIONS = ALL_ACCOUNT_OPERATIONS;
|
|
4936
5118
|
exports.ALL_NOTIFY_TYPES = ALL_NOTIFY_TYPES;
|
|
4937
5119
|
exports.CONFIG = CONFIG;
|
|
4938
5120
|
exports.EcencyAnalytics = mutations_exports;
|
|
4939
5121
|
exports.HiveSignerIntegration = HiveSignerIntegration;
|
|
4940
|
-
exports.Keychain = keychain_exports;
|
|
4941
5122
|
exports.NaiMap = NaiMap;
|
|
4942
5123
|
exports.NotificationFilter = NotificationFilter;
|
|
4943
5124
|
exports.NotificationViewType = NotificationViewType;
|
|
@@ -4961,7 +5142,6 @@ exports.deleteSchedule = deleteSchedule;
|
|
|
4961
5142
|
exports.downVotingPower = downVotingPower;
|
|
4962
5143
|
exports.encodeObj = encodeObj;
|
|
4963
5144
|
exports.extractAccountProfile = extractAccountProfile;
|
|
4964
|
-
exports.getAccessToken = getAccessToken;
|
|
4965
5145
|
exports.getAccountFullQueryOptions = getAccountFullQueryOptions;
|
|
4966
5146
|
exports.getAccountNotificationsInfiniteQueryOptions = getAccountNotificationsInfiniteQueryOptions;
|
|
4967
5147
|
exports.getAccountPendingRecoveryQueryOptions = getAccountPendingRecoveryQueryOptions;
|
|
@@ -5014,11 +5194,21 @@ exports.getFragmentsQueryOptions = getFragmentsQueryOptions;
|
|
|
5014
5194
|
exports.getFriendsInfiniteQueryOptions = getFriendsInfiniteQueryOptions;
|
|
5015
5195
|
exports.getGalleryImagesQueryOptions = getGalleryImagesQueryOptions;
|
|
5016
5196
|
exports.getGameStatusCheckQueryOptions = getGameStatusCheckQueryOptions;
|
|
5197
|
+
exports.getHiveEngineMetrics = getHiveEngineMetrics;
|
|
5198
|
+
exports.getHiveEngineOpenOrders = getHiveEngineOpenOrders;
|
|
5199
|
+
exports.getHiveEngineOrderBook = getHiveEngineOrderBook;
|
|
5200
|
+
exports.getHiveEngineTokenMetrics = getHiveEngineTokenMetrics;
|
|
5201
|
+
exports.getHiveEngineTokenTransactions = getHiveEngineTokenTransactions;
|
|
5202
|
+
exports.getHiveEngineTokensBalances = getHiveEngineTokensBalances;
|
|
5203
|
+
exports.getHiveEngineTokensMarket = getHiveEngineTokensMarket;
|
|
5204
|
+
exports.getHiveEngineTokensMetadata = getHiveEngineTokensMetadata;
|
|
5205
|
+
exports.getHiveEngineTradeHistory = getHiveEngineTradeHistory;
|
|
5206
|
+
exports.getHiveEngineUnclaimedRewards = getHiveEngineUnclaimedRewards;
|
|
5017
5207
|
exports.getHiveHbdStatsQueryOptions = getHiveHbdStatsQueryOptions;
|
|
5018
5208
|
exports.getHivePoshLinksQueryOptions = getHivePoshLinksQueryOptions;
|
|
5209
|
+
exports.getHivePrice = getHivePrice;
|
|
5019
5210
|
exports.getImagesQueryOptions = getImagesQueryOptions;
|
|
5020
5211
|
exports.getIncomingRcQueryOptions = getIncomingRcQueryOptions;
|
|
5021
|
-
exports.getLoginType = getLoginType;
|
|
5022
5212
|
exports.getMarketData = getMarketData;
|
|
5023
5213
|
exports.getMarketDataQueryOptions = getMarketDataQueryOptions;
|
|
5024
5214
|
exports.getMarketHistoryQueryOptions = getMarketHistoryQueryOptions;
|
|
@@ -5040,7 +5230,6 @@ exports.getPostHeader = getPostHeader;
|
|
|
5040
5230
|
exports.getPostHeaderQueryOptions = getPostHeaderQueryOptions;
|
|
5041
5231
|
exports.getPostQueryOptions = getPostQueryOptions;
|
|
5042
5232
|
exports.getPostTipsQueryOptions = getPostTipsQueryOptions;
|
|
5043
|
-
exports.getPostingKey = getPostingKey;
|
|
5044
5233
|
exports.getPostsRanked = getPostsRanked;
|
|
5045
5234
|
exports.getPostsRankedInfiniteQueryOptions = getPostsRankedInfiniteQueryOptions;
|
|
5046
5235
|
exports.getPostsRankedQueryOptions = getPostsRankedQueryOptions;
|
|
@@ -5058,7 +5247,6 @@ exports.getReblogsQueryOptions = getReblogsQueryOptions;
|
|
|
5058
5247
|
exports.getReceivedVestingSharesQueryOptions = getReceivedVestingSharesQueryOptions;
|
|
5059
5248
|
exports.getReferralsInfiniteQueryOptions = getReferralsInfiniteQueryOptions;
|
|
5060
5249
|
exports.getReferralsStatsQueryOptions = getReferralsStatsQueryOptions;
|
|
5061
|
-
exports.getRefreshToken = getRefreshToken;
|
|
5062
5250
|
exports.getRelationshipBetweenAccounts = getRelationshipBetweenAccounts;
|
|
5063
5251
|
exports.getRelationshipBetweenAccountsQueryOptions = getRelationshipBetweenAccountsQueryOptions;
|
|
5064
5252
|
exports.getRewardedCommunitiesQueryOptions = getRewardedCommunitiesQueryOptions;
|
|
@@ -5071,6 +5259,8 @@ exports.getSearchFriendsQueryOptions = getSearchFriendsQueryOptions;
|
|
|
5071
5259
|
exports.getSearchPathQueryOptions = getSearchPathQueryOptions;
|
|
5072
5260
|
exports.getSearchTopicsQueryOptions = getSearchTopicsQueryOptions;
|
|
5073
5261
|
exports.getSimilarEntriesQueryOptions = getSimilarEntriesQueryOptions;
|
|
5262
|
+
exports.getSpkMarkets = getSpkMarkets;
|
|
5263
|
+
exports.getSpkWallet = getSpkWallet;
|
|
5074
5264
|
exports.getStatsQueryOptions = getStatsQueryOptions;
|
|
5075
5265
|
exports.getSubscribers = getSubscribers;
|
|
5076
5266
|
exports.getSubscriptions = getSubscriptions;
|
|
@@ -5078,7 +5268,6 @@ exports.getTradeHistoryQueryOptions = getTradeHistoryQueryOptions;
|
|
|
5078
5268
|
exports.getTransactionsInfiniteQueryOptions = getTransactionsInfiniteQueryOptions;
|
|
5079
5269
|
exports.getTrendingTagsQueryOptions = getTrendingTagsQueryOptions;
|
|
5080
5270
|
exports.getTrendingTagsWithStatsQueryOptions = getTrendingTagsWithStatsQueryOptions;
|
|
5081
|
-
exports.getUser = getUser;
|
|
5082
5271
|
exports.getUserProposalVotesQueryOptions = getUserProposalVotesQueryOptions;
|
|
5083
5272
|
exports.getVestingDelegationsQueryOptions = getVestingDelegationsQueryOptions;
|
|
5084
5273
|
exports.getVisibleFirstLevelThreadItems = getVisibleFirstLevelThreadItems;
|