@ecency/sdk 1.5.1 → 1.5.3

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.
@@ -4,60 +4,11 @@ import hs from 'hivesigner';
4
4
  import * as R4 from 'remeda';
5
5
 
6
6
  var __defProp = Object.defineProperty;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
7
  var __export = (target, all) => {
9
8
  for (var name in all)
10
9
  __defProp(target, name, { get: all[name], enumerable: true });
11
10
  };
12
- var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
13
-
14
- // src/modules/keychain/keychain.ts
15
- var keychain_exports = {};
16
- __export(keychain_exports, {
17
- broadcast: () => broadcast,
18
- customJson: () => customJson,
19
- handshake: () => handshake
20
- });
21
- function handshake() {
22
- return new Promise((resolve) => {
23
- window.hive_keychain?.requestHandshake(() => {
24
- resolve();
25
- });
26
- });
27
- }
28
- var broadcast = (account, operations, key, rpc = null) => new Promise((resolve, reject) => {
29
- window.hive_keychain?.requestBroadcast(
30
- account,
31
- operations,
32
- key,
33
- (resp) => {
34
- if (!resp.success) {
35
- reject({ message: "Operation cancelled" });
36
- }
37
- resolve(resp);
38
- },
39
- rpc
40
- );
41
- });
42
- var customJson = (account, id, key, json, display_msg, rpc = null) => new Promise((resolve, reject) => {
43
- window.hive_keychain?.requestCustomJson(
44
- account,
45
- id,
46
- key,
47
- json,
48
- display_msg,
49
- (resp) => {
50
- if (!resp.success) {
51
- reject({ message: "Operation cancelled" });
52
- }
53
- resolve(resp);
54
- },
55
- rpc
56
- );
57
- });
58
-
59
- // src/modules/core/mutations/use-broadcast-mutation.ts
60
- function useBroadcastMutation(mutationKey = [], username, accessToken, operations, onSuccess = () => {
11
+ function useBroadcastMutation(mutationKey = [], username, operations, onSuccess = () => {
61
12
  }, auth) {
62
13
  return useMutation({
63
14
  onSuccess,
@@ -68,6 +19,9 @@ function useBroadcastMutation(mutationKey = [], username, accessToken, operation
68
19
  "[Core][Broadcast] Attempted to call broadcast API with anon user"
69
20
  );
70
21
  }
22
+ if (auth?.broadcast) {
23
+ return auth.broadcast(operations(payload), "posting");
24
+ }
71
25
  const postingKey = auth?.postingKey;
72
26
  if (postingKey) {
73
27
  const privateKey = PrivateKey.fromString(postingKey);
@@ -76,34 +30,12 @@ function useBroadcastMutation(mutationKey = [], username, accessToken, operation
76
30
  privateKey
77
31
  );
78
32
  }
79
- const loginType = auth?.loginType;
80
- if (loginType && loginType == "keychain") {
81
- return keychain_exports.broadcast(
82
- username,
83
- operations(payload),
84
- "Posting"
85
- ).then((r) => r.result);
86
- }
33
+ const accessToken = auth?.accessToken;
87
34
  if (accessToken) {
88
- const f = getBoundFetch();
89
- const res = await f("https://hivesigner.com/api/broadcast", {
90
- method: "POST",
91
- headers: {
92
- Authorization: accessToken,
93
- "Content-Type": "application/json",
94
- Accept: "application/json"
95
- },
96
- body: JSON.stringify({ operations: operations(payload) })
97
- });
98
- if (!res.ok) {
99
- const txt = await res.text().catch(() => "");
100
- throw new Error(`[Hivesigner] ${res.status} ${res.statusText} ${txt}`);
101
- }
102
- const json = await res.json();
103
- if (json?.errors) {
104
- throw new Error(`[Hivesigner] ${JSON.stringify(json.errors)}`);
105
- }
106
- return json.result;
35
+ const ops2 = operations(payload);
36
+ const client = new hs.Client({ accessToken });
37
+ const response = await client.broadcast(ops2);
38
+ return response.result;
107
39
  }
108
40
  throw new Error(
109
41
  "[SDK][Broadcast] \u2013 cannot broadcast w/o posting key or token"
@@ -111,33 +43,9 @@ function useBroadcastMutation(mutationKey = [], username, accessToken, operation
111
43
  }
112
44
  });
113
45
  }
114
-
115
- // src/modules/core/mock-storage.ts
116
- var MockStorage = class {
117
- constructor() {
118
- __publicField(this, "length", 0);
119
- }
120
- clear() {
121
- throw new Error("Method not implemented.");
122
- }
123
- getItem(key) {
124
- return this[key];
125
- }
126
- key(index) {
127
- return Object.keys(this)[index];
128
- }
129
- removeItem(key) {
130
- delete this[key];
131
- }
132
- setItem(key, value) {
133
- this[key] = value;
134
- }
135
- };
136
46
  var CONFIG = {
137
47
  privateApiHost: "https://ecency.com",
138
48
  imageHost: "https://images.ecency.com",
139
- storage: typeof window === "undefined" ? new MockStorage() : window.localStorage,
140
- storagePrefix: "ecency",
141
49
  hiveClient: new Client(
142
50
  [
143
51
  "https://api.hive.blog",
@@ -292,7 +200,7 @@ var ConfigManager;
292
200
  }
293
201
  ConfigManager2.setDmcaLists = setDmcaLists;
294
202
  })(ConfigManager || (ConfigManager = {}));
295
- async function broadcastJson(username, id, payload, accessToken, auth) {
203
+ async function broadcastJson(username, id, payload, auth) {
296
204
  if (!username) {
297
205
  throw new Error(
298
206
  "[Core][Broadcast] Attempted to call broadcast API with anon user"
@@ -304,6 +212,9 @@ async function broadcastJson(username, id, payload, accessToken, auth) {
304
212
  required_posting_auths: [username],
305
213
  json: JSON.stringify(payload)
306
214
  };
215
+ if (auth?.broadcast) {
216
+ return auth.broadcast([["custom_json", jjson]], "posting");
217
+ }
307
218
  const postingKey = auth?.postingKey;
308
219
  if (postingKey) {
309
220
  const privateKey = PrivateKey.fromString(postingKey);
@@ -312,10 +223,7 @@ async function broadcastJson(username, id, payload, accessToken, auth) {
312
223
  privateKey
313
224
  );
314
225
  }
315
- const loginType = auth?.loginType;
316
- if (loginType && loginType == "keychain") {
317
- return keychain_exports.broadcast(username, [["custom_json", jjson]], "Posting").then((r) => r.result);
318
- }
226
+ const accessToken = auth?.accessToken;
319
227
  if (accessToken) {
320
228
  const response = await new hs.Client({
321
229
  accessToken
@@ -326,6 +234,63 @@ async function broadcastJson(username, id, payload, accessToken, auth) {
326
234
  "[SDK][Broadcast] \u2013 cannot broadcast w/o posting key or token"
327
235
  );
328
236
  }
237
+ function makeQueryClient() {
238
+ return new QueryClient({
239
+ defaultOptions: {
240
+ queries: {
241
+ // With SSR, we usually want to set some default staleTime
242
+ // above 0 to avoid refetching immediately on the client
243
+ // staleTime: 60 * 1000,
244
+ refetchOnWindowFocus: false,
245
+ refetchOnMount: false
246
+ }
247
+ }
248
+ });
249
+ }
250
+ var getQueryClient = () => CONFIG.queryClient;
251
+ var EcencyQueriesManager;
252
+ ((EcencyQueriesManager2) => {
253
+ function getQueryData(queryKey) {
254
+ const queryClient = getQueryClient();
255
+ return queryClient.getQueryData(queryKey);
256
+ }
257
+ EcencyQueriesManager2.getQueryData = getQueryData;
258
+ function getInfiniteQueryData(queryKey) {
259
+ const queryClient = getQueryClient();
260
+ return queryClient.getQueryData(queryKey);
261
+ }
262
+ EcencyQueriesManager2.getInfiniteQueryData = getInfiniteQueryData;
263
+ async function prefetchQuery(options) {
264
+ const queryClient = getQueryClient();
265
+ await queryClient.prefetchQuery(options);
266
+ return getQueryData(options.queryKey);
267
+ }
268
+ EcencyQueriesManager2.prefetchQuery = prefetchQuery;
269
+ async function prefetchInfiniteQuery(options) {
270
+ const queryClient = getQueryClient();
271
+ await queryClient.prefetchInfiniteQuery(options);
272
+ return getInfiniteQueryData(options.queryKey);
273
+ }
274
+ EcencyQueriesManager2.prefetchInfiniteQuery = prefetchInfiniteQuery;
275
+ function generateClientServerQuery(options) {
276
+ return {
277
+ prefetch: () => prefetchQuery(options),
278
+ getData: () => getQueryData(options.queryKey),
279
+ useClientQuery: () => useQuery(options),
280
+ fetchAndGet: () => getQueryClient().fetchQuery(options)
281
+ };
282
+ }
283
+ EcencyQueriesManager2.generateClientServerQuery = generateClientServerQuery;
284
+ function generateClientServerInfiniteQuery(options) {
285
+ return {
286
+ prefetch: () => prefetchInfiniteQuery(options),
287
+ getData: () => getInfiniteQueryData(options.queryKey),
288
+ useClientQuery: () => useInfiniteQuery(options),
289
+ fetchAndGet: () => getQueryClient().fetchInfiniteQuery(options)
290
+ };
291
+ }
292
+ EcencyQueriesManager2.generateClientServerInfiniteQuery = generateClientServerInfiniteQuery;
293
+ })(EcencyQueriesManager || (EcencyQueriesManager = {}));
329
294
 
330
295
  // src/modules/core/utils/decoder-encoder.ts
331
296
  function encodeObj(o) {
@@ -387,79 +352,7 @@ function isCommunity(value) {
387
352
  return typeof value === "string" ? /^hive-\d+$/.test(value) : false;
388
353
  }
389
354
 
390
- // src/modules/core/storage.ts
391
- var getUser = (username) => {
392
- try {
393
- const raw = CONFIG.storage.getItem(
394
- CONFIG.storagePrefix + "_user_" + username
395
- );
396
- return decodeObj(JSON.parse(raw));
397
- } catch (e) {
398
- console.error(e);
399
- return void 0;
400
- }
401
- };
402
- var getAccessToken = (username) => getUser(username) && getUser(username).accessToken;
403
- var getPostingKey = (username) => getUser(username) && getUser(username).postingKey;
404
- var getLoginType = (username) => getUser(username) && getUser(username).loginType;
405
- var getRefreshToken = (username) => getUser(username) && getUser(username).refreshToken;
406
- function makeQueryClient() {
407
- return new QueryClient({
408
- defaultOptions: {
409
- queries: {
410
- // With SSR, we usually want to set some default staleTime
411
- // above 0 to avoid refetching immediately on the client
412
- // staleTime: 60 * 1000,
413
- refetchOnWindowFocus: false,
414
- refetchOnMount: false
415
- }
416
- }
417
- });
418
- }
419
- var getQueryClient = () => CONFIG.queryClient;
420
- var EcencyQueriesManager;
421
- ((EcencyQueriesManager2) => {
422
- function getQueryData(queryKey) {
423
- const queryClient = getQueryClient();
424
- return queryClient.getQueryData(queryKey);
425
- }
426
- EcencyQueriesManager2.getQueryData = getQueryData;
427
- function getInfiniteQueryData(queryKey) {
428
- const queryClient = getQueryClient();
429
- return queryClient.getQueryData(queryKey);
430
- }
431
- EcencyQueriesManager2.getInfiniteQueryData = getInfiniteQueryData;
432
- async function prefetchQuery(options) {
433
- const queryClient = getQueryClient();
434
- await queryClient.prefetchQuery(options);
435
- return getQueryData(options.queryKey);
436
- }
437
- EcencyQueriesManager2.prefetchQuery = prefetchQuery;
438
- async function prefetchInfiniteQuery(options) {
439
- const queryClient = getQueryClient();
440
- await queryClient.prefetchInfiniteQuery(options);
441
- return getInfiniteQueryData(options.queryKey);
442
- }
443
- EcencyQueriesManager2.prefetchInfiniteQuery = prefetchInfiniteQuery;
444
- function generateClientServerQuery(options) {
445
- return {
446
- prefetch: () => prefetchQuery(options),
447
- getData: () => getQueryData(options.queryKey),
448
- useClientQuery: () => useQuery(options),
449
- fetchAndGet: () => getQueryClient().fetchQuery(options)
450
- };
451
- }
452
- EcencyQueriesManager2.generateClientServerQuery = generateClientServerQuery;
453
- function generateClientServerInfiniteQuery(options) {
454
- return {
455
- prefetch: () => prefetchInfiniteQuery(options),
456
- getData: () => getInfiniteQueryData(options.queryKey),
457
- useClientQuery: () => useInfiniteQuery(options),
458
- fetchAndGet: () => getQueryClient().fetchInfiniteQuery(options)
459
- };
460
- }
461
- EcencyQueriesManager2.generateClientServerInfiniteQuery = generateClientServerInfiniteQuery;
462
- })(EcencyQueriesManager || (EcencyQueriesManager = {}));
355
+ // src/modules/core/queries/get-dynamic-props-query-options.ts
463
356
  function getDynamicPropsQueryOptions() {
464
357
  return queryOptions({
465
358
  queryKey: ["core", "dynamic-props"],
@@ -2388,13 +2281,12 @@ function getProfilesQueryOptions(accounts, observer, enabled = true) {
2388
2281
  }
2389
2282
 
2390
2283
  // src/modules/accounts/mutations/use-account-update.ts
2391
- function useAccountUpdate(username, accessToken, auth) {
2284
+ function useAccountUpdate(username, auth) {
2392
2285
  const queryClient = useQueryClient();
2393
2286
  const { data } = useQuery(getAccountFullQueryOptions(username));
2394
2287
  return useBroadcastMutation(
2395
2288
  ["accounts", "update"],
2396
2289
  username,
2397
- accessToken,
2398
2290
  (payload) => {
2399
2291
  if (!data) {
2400
2292
  throw new Error("[SDK][Accounts] \u2013 cannot update not existing account");
@@ -2436,7 +2328,7 @@ function useAccountUpdate(username, accessToken, auth) {
2436
2328
  auth
2437
2329
  );
2438
2330
  }
2439
- function useAccountRelationsUpdate(reference, target, onSuccess, onError) {
2331
+ function useAccountRelationsUpdate(reference, target, auth, onSuccess, onError) {
2440
2332
  return useMutation({
2441
2333
  mutationKey: ["accounts", "relation", "update", reference, target],
2442
2334
  mutationFn: async (kind) => {
@@ -2448,17 +2340,22 @@ function useAccountRelationsUpdate(reference, target, onSuccess, onError) {
2448
2340
  const actualRelation = getQueryClient().getQueryData(
2449
2341
  relationsQuery.queryKey
2450
2342
  );
2451
- await broadcastJson(reference, "follow", [
2343
+ await broadcastJson(
2344
+ reference,
2452
2345
  "follow",
2453
- {
2454
- follower: reference,
2455
- following: target,
2456
- what: [
2457
- ...kind === "toggle-ignore" && !actualRelation?.ignores ? ["ignore"] : [],
2458
- ...kind === "toggle-follow" && !actualRelation?.follows ? ["blog"] : []
2459
- ]
2460
- }
2461
- ]);
2346
+ [
2347
+ "follow",
2348
+ {
2349
+ follower: reference,
2350
+ following: target,
2351
+ what: [
2352
+ ...kind === "toggle-ignore" && !actualRelation?.ignores ? ["ignore"] : [],
2353
+ ...kind === "toggle-follow" && !actualRelation?.follows ? ["blog"] : []
2354
+ ]
2355
+ }
2356
+ ],
2357
+ auth
2358
+ );
2462
2359
  return {
2463
2360
  ...actualRelation,
2464
2361
  ignores: kind === "toggle-ignore" ? !actualRelation?.ignores : actualRelation?.ignores,
@@ -2685,7 +2582,7 @@ function useAccountUpdatePassword(username, options) {
2685
2582
  ...options
2686
2583
  });
2687
2584
  }
2688
- function useAccountRevokePosting(username, options) {
2585
+ function useAccountRevokePosting(username, options, auth) {
2689
2586
  const queryClient = useQueryClient();
2690
2587
  const { data } = useQuery(getAccountFullQueryOptions(username));
2691
2588
  return useMutation({
@@ -2712,11 +2609,10 @@ function useAccountRevokePosting(username, options) {
2712
2609
  if (type === "key" && key) {
2713
2610
  return CONFIG.hiveClient.broadcast.updateAccount(operationBody, key);
2714
2611
  } else if (type === "keychain") {
2715
- return keychain_exports.broadcast(
2716
- data.name,
2717
- [["account_update", operationBody]],
2718
- "Active"
2719
- );
2612
+ if (!auth?.broadcast) {
2613
+ throw new Error("[SDK][Accounts] \u2013 missing keychain broadcaster");
2614
+ }
2615
+ return auth.broadcast([["account_update", operationBody]], "active");
2720
2616
  } else {
2721
2617
  const params = {
2722
2618
  callback: `https://ecency.com/@${data.name}/permissions`
@@ -2747,7 +2643,7 @@ function useAccountRevokePosting(username, options) {
2747
2643
  }
2748
2644
  });
2749
2645
  }
2750
- function useAccountUpdateRecovery(username, code, options) {
2646
+ function useAccountUpdateRecovery(username, code, options, auth) {
2751
2647
  const { data } = useQuery(getAccountFullQueryOptions(username));
2752
2648
  return useMutation({
2753
2649
  mutationKey: ["accounts", "recovery", data?.name],
@@ -2786,11 +2682,10 @@ function useAccountUpdateRecovery(username, code, options) {
2786
2682
  key
2787
2683
  );
2788
2684
  } else if (type === "keychain") {
2789
- return keychain_exports.broadcast(
2790
- data.name,
2791
- [["change_recovery_account", operationBody]],
2792
- "Active"
2793
- );
2685
+ if (!auth?.broadcast) {
2686
+ throw new Error("[SDK][Accounts] \u2013 missing keychain broadcaster");
2687
+ }
2688
+ return auth.broadcast([["change_recovery_account", operationBody]], "owner");
2794
2689
  } else {
2795
2690
  const params = {
2796
2691
  callback: `https://ecency.com/@${data.name}/permissions`
@@ -3010,7 +2905,7 @@ function useSignOperationByKey(username) {
3010
2905
  }
3011
2906
  });
3012
2907
  }
3013
- function useSignOperationByKeychain(username, keyType = "Active") {
2908
+ function useSignOperationByKeychain(username, auth, keyType = "active") {
3014
2909
  return useMutation({
3015
2910
  mutationKey: ["operations", "sign-keychain", username],
3016
2911
  mutationFn: ({ operation }) => {
@@ -3019,7 +2914,10 @@ function useSignOperationByKeychain(username, keyType = "Active") {
3019
2914
  "[SDK][Keychain] \u2013\xA0cannot sign operation with anon user"
3020
2915
  );
3021
2916
  }
3022
- return keychain_exports.broadcast(username, [operation], keyType);
2917
+ if (!auth?.broadcast) {
2918
+ throw new Error("[SDK][Keychain] \u2013 missing keychain broadcaster");
2919
+ }
2920
+ return auth.broadcast([operation], keyType);
3023
2921
  }
3024
2922
  });
3025
2923
  }
@@ -3419,7 +3317,7 @@ function getStatsQueryOptions({
3419
3317
  queryKey: ["integrations", "plausible", url, dimensions, metrics],
3420
3318
  queryFn: async () => {
3421
3319
  const fetchApi = getBoundFetch();
3422
- const response = await fetchApi(`https://ecency.com/api/stats`, {
3320
+ const response = await fetchApi(`${CONFIG.privateApiHost}/api/stats`, {
3423
3321
  method: "POST",
3424
3322
  body: JSON.stringify({
3425
3323
  metrics,
@@ -4182,6 +4080,13 @@ async function getCurrencyRates() {
4182
4080
  const response = await fetchApi(CONFIG.privateApiHost + "/private-api/market-data/latest");
4183
4081
  return parseJsonResponse(response);
4184
4082
  }
4083
+ async function getHivePrice() {
4084
+ const fetchApi = getBoundFetch();
4085
+ const response = await fetchApi(
4086
+ "https://api.coingecko.com/api/v3/simple/price?ids=hive&vs_currencies=usd"
4087
+ );
4088
+ return parseJsonResponse(response);
4089
+ }
4185
4090
  function getPointsQueryOptions(username, filter = 0) {
4186
4091
  return queryOptions({
4187
4092
  queryKey: ["points", username, filter],
@@ -4910,6 +4815,279 @@ async function hsTokenRenew(code) {
4910
4815
  return data;
4911
4816
  }
4912
4817
 
4913
- export { ACCOUNT_OPERATION_GROUPS, ALL_ACCOUNT_OPERATIONS, ALL_NOTIFY_TYPES, CONFIG, ConfigManager, mutations_exports as EcencyAnalytics, EcencyQueriesManager, HiveSignerIntegration, keychain_exports as Keychain, NaiMap, NotificationFilter, NotificationViewType, NotifyTypes, ROLES, SortOrder, Symbol2 as Symbol, ThreeSpeakIntegration, addDraft, addImage, addSchedule, bridgeApiCall, broadcastJson, buildProfileMetadata, checkUsernameWalletsPendingQueryOptions, decodeObj, dedupeAndSortKeyAuths, deleteDraft, deleteImage, deleteSchedule, downVotingPower, encodeObj, extractAccountProfile, getAccessToken, getAccountFullQueryOptions, getAccountNotificationsInfiniteQueryOptions, getAccountPendingRecoveryQueryOptions, getAccountPosts, getAccountPostsInfiniteQueryOptions, getAccountPostsQueryOptions, getAccountRcQueryOptions, getAccountRecoveriesQueryOptions, getAccountReputationsQueryOptions, getAccountSubscriptionsQueryOptions, getAccountVoteHistoryInfiniteQueryOptions, getAccountsQueryOptions, getActiveAccountBookmarksQueryOptions, getActiveAccountFavouritesQueryOptions, getAnnouncementsQueryOptions, getBoostPlusAccountPricesQueryOptions, getBoostPlusPricesQueryOptions, getBotsQueryOptions, getBoundFetch, getChainPropertiesQueryOptions, getCollateralizedConversionRequestsQueryOptions, getCommentHistoryQueryOptions, getCommunities, getCommunitiesQueryOptions, getCommunity, getCommunityContextQueryOptions, getCommunityPermissions, getCommunityQueryOptions, getCommunitySubscribersQueryOptions, getCommunityType, getContentQueryOptions, getContentRepliesQueryOptions, getControversialRisingInfiniteQueryOptions, getConversionRequestsQueryOptions, getCurrencyRate, getCurrencyRates, getCurrencyTokenRate, getDeletedEntryQueryOptions, getDiscoverCurationQueryOptions, getDiscoverLeaderboardQueryOptions, getDiscussion, getDiscussionQueryOptions, getDiscussionsQueryOptions, getDraftsQueryOptions, getDynamicPropsQueryOptions, getEntryActiveVotesQueryOptions, getFollowCountQueryOptions, getFollowingQueryOptions, getFragmentsQueryOptions, getFriendsInfiniteQueryOptions, getGalleryImagesQueryOptions, getGameStatusCheckQueryOptions, getHiveHbdStatsQueryOptions, getHivePoshLinksQueryOptions, getImagesQueryOptions, getIncomingRcQueryOptions, getLoginType, getMarketData, getMarketDataQueryOptions, getMarketHistoryQueryOptions, getMarketStatisticsQueryOptions, getMutedUsersQueryOptions, getNormalizePostQueryOptions, getNotificationSetting, getNotifications, getNotificationsInfiniteQueryOptions, getNotificationsSettingsQueryOptions, getNotificationsUnreadCountQueryOptions, getOpenOrdersQueryOptions, getOrderBookQueryOptions, getOutgoingRcDelegationsInfiniteQueryOptions, getPageStatsQueryOptions, getPointsQueryOptions, getPost, getPostHeader, getPostHeaderQueryOptions, getPostQueryOptions, getPostTipsQueryOptions, getPostingKey, getPostsRanked, getPostsRankedInfiniteQueryOptions, getPostsRankedQueryOptions, getProfiles, getProfilesQueryOptions, getPromotePriceQueryOptions, getPromotedPost, getPromotedPostsQuery, getProposalQueryOptions, getProposalVotesInfiniteQueryOptions, getProposalsQueryOptions, getQueryClient, getRcStatsQueryOptions, getReblogsQueryOptions, getReceivedVestingSharesQueryOptions, getReferralsInfiniteQueryOptions, getReferralsStatsQueryOptions, getRefreshToken, getRelationshipBetweenAccounts, getRelationshipBetweenAccountsQueryOptions, getRewardedCommunitiesQueryOptions, getSavingsWithdrawFromQueryOptions, getSchedulesQueryOptions, getSearchAccountQueryOptions, getSearchAccountsByUsernameQueryOptions, getSearchApiInfiniteQueryOptions, getSearchFriendsQueryOptions, getSearchPathQueryOptions, getSearchTopicsQueryOptions, getSimilarEntriesQueryOptions, getStatsQueryOptions, getSubscribers, getSubscriptions, getTradeHistoryQueryOptions, getTransactionsInfiniteQueryOptions, getTrendingTagsQueryOptions, getTrendingTagsWithStatsQueryOptions, getUser, getUserProposalVotesQueryOptions, getVestingDelegationsQueryOptions, getVisibleFirstLevelThreadItems, getWavesByHostQueryOptions, getWavesByTagQueryOptions, getWavesFollowingQueryOptions, getWavesTrendingTagsQueryOptions, getWithdrawRoutesQueryOptions, getWitnessesInfiniteQueryOptions, hsTokenRenew, isCommunity, lookupAccountsQueryOptions, makeQueryClient, mapThreadItemsToWaveEntries, markNotifications, moveSchedule, normalizePost, normalizeWaveEntryFromApi, onboardEmail, parseAccounts, parseAsset, parseProfileMetadata, powerRechargeTime, rcPower, resolvePost, roleMap, saveNotificationSetting, search, searchAccount, searchPath, searchQueryOptions, searchTag, signUp, sortDiscussions, subscribeEmail, toEntryArray, updateDraft, uploadImage, useAccountFavouriteAdd, useAccountFavouriteDelete, useAccountRelationsUpdate, useAccountRevokeKey, useAccountRevokePosting, useAccountUpdate, useAccountUpdateKeyAuths, useAccountUpdatePassword, useAccountUpdateRecovery, useAddFragment, useBookmarkAdd, useBookmarkDelete, useBroadcastMutation, useEditFragment, useGameClaim, useRecordActivity, useRemoveFragment, useSignOperationByHivesigner, useSignOperationByKey, useSignOperationByKeychain, usrActivity, validatePostCreating, votingPower, votingValue };
4818
+ // src/modules/hive-engine/requests.ts
4819
+ var ENGINE_RPC_HEADERS = { "Content-type": "application/json" };
4820
+ async function engineRpc(payload) {
4821
+ const fetchApi = getBoundFetch();
4822
+ const response = await fetchApi(`${CONFIG.privateApiHost}/private-api/engine-api`, {
4823
+ method: "POST",
4824
+ body: JSON.stringify(payload),
4825
+ headers: ENGINE_RPC_HEADERS
4826
+ });
4827
+ if (!response.ok) {
4828
+ throw new Error(
4829
+ `[SDK][HiveEngine] \u2013 request failed with ${response.status}`
4830
+ );
4831
+ }
4832
+ const data = await response.json();
4833
+ return data.result;
4834
+ }
4835
+ async function engineRpcSafe(payload, fallback) {
4836
+ try {
4837
+ return await engineRpc(payload);
4838
+ } catch (e) {
4839
+ return fallback;
4840
+ }
4841
+ }
4842
+ async function getHiveEngineOrderBook(symbol, limit = 50) {
4843
+ const baseParams = {
4844
+ jsonrpc: "2.0",
4845
+ method: "find",
4846
+ params: {
4847
+ contract: "market",
4848
+ query: { symbol },
4849
+ limit,
4850
+ offset: 0
4851
+ },
4852
+ id: 1
4853
+ };
4854
+ const [buy, sell] = await Promise.all([
4855
+ engineRpcSafe(
4856
+ {
4857
+ ...baseParams,
4858
+ params: {
4859
+ ...baseParams.params,
4860
+ table: "buyBook",
4861
+ indexes: [{ index: "price", descending: true }]
4862
+ }
4863
+ },
4864
+ []
4865
+ ),
4866
+ engineRpcSafe(
4867
+ {
4868
+ ...baseParams,
4869
+ params: {
4870
+ ...baseParams.params,
4871
+ table: "sellBook",
4872
+ indexes: [{ index: "price", descending: false }]
4873
+ }
4874
+ },
4875
+ []
4876
+ )
4877
+ ]);
4878
+ const sortByPriceDesc = (items) => items.sort((a, b) => {
4879
+ const left = Number(a.price ?? 0);
4880
+ const right = Number(b.price ?? 0);
4881
+ return right - left;
4882
+ });
4883
+ const sortByPriceAsc = (items) => items.sort((a, b) => {
4884
+ const left = Number(a.price ?? 0);
4885
+ const right = Number(b.price ?? 0);
4886
+ return left - right;
4887
+ });
4888
+ return {
4889
+ buy: sortByPriceDesc(buy),
4890
+ sell: sortByPriceAsc(sell)
4891
+ };
4892
+ }
4893
+ async function getHiveEngineTradeHistory(symbol, limit = 50) {
4894
+ return engineRpcSafe(
4895
+ {
4896
+ jsonrpc: "2.0",
4897
+ method: "find",
4898
+ params: {
4899
+ contract: "market",
4900
+ table: "tradesHistory",
4901
+ query: { symbol },
4902
+ limit,
4903
+ offset: 0,
4904
+ indexes: [{ index: "timestamp", descending: true }]
4905
+ },
4906
+ id: 1
4907
+ },
4908
+ []
4909
+ );
4910
+ }
4911
+ async function getHiveEngineOpenOrders(account, symbol, limit = 100) {
4912
+ const baseParams = {
4913
+ jsonrpc: "2.0",
4914
+ method: "find",
4915
+ params: {
4916
+ contract: "market",
4917
+ query: { symbol, account },
4918
+ limit,
4919
+ offset: 0
4920
+ },
4921
+ id: 1
4922
+ };
4923
+ const [buyRaw, sellRaw] = await Promise.all([
4924
+ engineRpcSafe(
4925
+ {
4926
+ ...baseParams,
4927
+ params: {
4928
+ ...baseParams.params,
4929
+ table: "buyBook",
4930
+ indexes: [{ index: "timestamp", descending: true }]
4931
+ }
4932
+ },
4933
+ []
4934
+ ),
4935
+ engineRpcSafe(
4936
+ {
4937
+ ...baseParams,
4938
+ params: {
4939
+ ...baseParams.params,
4940
+ table: "sellBook",
4941
+ indexes: [{ index: "timestamp", descending: true }]
4942
+ }
4943
+ },
4944
+ []
4945
+ )
4946
+ ]);
4947
+ const formatTotal = (quantity, price) => (Number(quantity || 0) * Number(price || 0)).toFixed(8);
4948
+ const buy = buyRaw.map((order) => ({
4949
+ id: order.txId,
4950
+ type: "buy",
4951
+ account: order.account,
4952
+ symbol: order.symbol,
4953
+ quantity: order.quantity,
4954
+ price: order.price,
4955
+ total: order.tokensLocked ?? formatTotal(order.quantity, order.price),
4956
+ timestamp: Number(order.timestamp ?? 0)
4957
+ }));
4958
+ const sell = sellRaw.map((order) => ({
4959
+ id: order.txId,
4960
+ type: "sell",
4961
+ account: order.account,
4962
+ symbol: order.symbol,
4963
+ quantity: order.quantity,
4964
+ price: order.price,
4965
+ total: formatTotal(order.quantity, order.price),
4966
+ timestamp: Number(order.timestamp ?? 0)
4967
+ }));
4968
+ return [...buy, ...sell].sort((a, b) => b.timestamp - a.timestamp);
4969
+ }
4970
+ async function getHiveEngineMetrics(symbol, account) {
4971
+ return engineRpcSafe(
4972
+ {
4973
+ jsonrpc: "2.0",
4974
+ method: "find",
4975
+ params: {
4976
+ contract: "market",
4977
+ table: "metrics",
4978
+ query: {
4979
+ ...symbol ? { symbol } : {},
4980
+ ...account ? { account } : {}
4981
+ }
4982
+ },
4983
+ id: 1
4984
+ },
4985
+ []
4986
+ );
4987
+ }
4988
+ async function getHiveEngineTokensMarket(account, symbol) {
4989
+ return getHiveEngineMetrics(symbol, account);
4990
+ }
4991
+ async function getHiveEngineTokensBalances(username) {
4992
+ return engineRpcSafe(
4993
+ {
4994
+ jsonrpc: "2.0",
4995
+ method: "find",
4996
+ params: {
4997
+ contract: "tokens",
4998
+ table: "balances",
4999
+ query: {
5000
+ account: username
5001
+ }
5002
+ },
5003
+ id: 1
5004
+ },
5005
+ []
5006
+ );
5007
+ }
5008
+ async function getHiveEngineTokensMetadata(tokens) {
5009
+ return engineRpcSafe(
5010
+ {
5011
+ jsonrpc: "2.0",
5012
+ method: "find",
5013
+ params: {
5014
+ contract: "tokens",
5015
+ table: "tokens",
5016
+ query: {
5017
+ symbol: { $in: tokens }
5018
+ }
5019
+ },
5020
+ id: 2
5021
+ },
5022
+ []
5023
+ );
5024
+ }
5025
+ async function getHiveEngineTokenTransactions(username, symbol, limit, offset) {
5026
+ const fetchApi = getBoundFetch();
5027
+ const url = new URL(
5028
+ `${CONFIG.privateApiHost}/private-api/engine-account-history`
5029
+ );
5030
+ url.searchParams.set("account", username);
5031
+ url.searchParams.set("symbol", symbol);
5032
+ url.searchParams.set("limit", limit.toString());
5033
+ url.searchParams.set("offset", offset.toString());
5034
+ const response = await fetchApi(url.toString(), {
5035
+ method: "GET",
5036
+ headers: { "Content-type": "application/json" }
5037
+ });
5038
+ if (!response.ok) {
5039
+ throw new Error(
5040
+ `[SDK][HiveEngine] \u2013 account history failed with ${response.status}`
5041
+ );
5042
+ }
5043
+ return await response.json();
5044
+ }
5045
+ async function getHiveEngineTokenMetrics(symbol, interval = "daily") {
5046
+ const fetchApi = getBoundFetch();
5047
+ const url = new URL(`${CONFIG.privateApiHost}/private-api/engine-chart-api`);
5048
+ url.searchParams.set("symbol", symbol);
5049
+ url.searchParams.set("interval", interval);
5050
+ const response = await fetchApi(url.toString(), {
5051
+ headers: { "Content-type": "application/json" }
5052
+ });
5053
+ if (!response.ok) {
5054
+ throw new Error(
5055
+ `[SDK][HiveEngine] \u2013 chart failed with ${response.status}`
5056
+ );
5057
+ }
5058
+ return await response.json();
5059
+ }
5060
+ async function getHiveEngineUnclaimedRewards(username) {
5061
+ const fetchApi = getBoundFetch();
5062
+ const response = await fetchApi(
5063
+ `${CONFIG.privateApiHost}/private-api/engine-reward-api/${username}?hive=1`
5064
+ );
5065
+ if (!response.ok) {
5066
+ throw new Error(
5067
+ `[SDK][HiveEngine] \u2013 rewards failed with ${response.status}`
5068
+ );
5069
+ }
5070
+ return await response.json();
5071
+ }
5072
+
5073
+ // src/modules/spk/requests.ts
5074
+ async function getSpkWallet(username) {
5075
+ const fetchApi = getBoundFetch();
5076
+ const response = await fetchApi(`${CONFIG.spkNode}/@${username}`);
5077
+ if (!response.ok) {
5078
+ throw new Error(`[SDK][SPK] \u2013 wallet failed with ${response.status}`);
5079
+ }
5080
+ return await response.json();
5081
+ }
5082
+ async function getSpkMarkets() {
5083
+ const fetchApi = getBoundFetch();
5084
+ const response = await fetchApi(`${CONFIG.spkNode}/markets`);
5085
+ if (!response.ok) {
5086
+ throw new Error(`[SDK][SPK] \u2013 markets failed with ${response.status}`);
5087
+ }
5088
+ return await response.json();
5089
+ }
5090
+
5091
+ export { ACCOUNT_OPERATION_GROUPS, ALL_ACCOUNT_OPERATIONS, ALL_NOTIFY_TYPES, CONFIG, ConfigManager, mutations_exports as EcencyAnalytics, EcencyQueriesManager, HiveSignerIntegration, NaiMap, NotificationFilter, NotificationViewType, NotifyTypes, ROLES, SortOrder, Symbol2 as Symbol, ThreeSpeakIntegration, addDraft, addImage, addSchedule, bridgeApiCall, broadcastJson, buildProfileMetadata, checkUsernameWalletsPendingQueryOptions, decodeObj, dedupeAndSortKeyAuths, deleteDraft, deleteImage, deleteSchedule, downVotingPower, encodeObj, extractAccountProfile, getAccountFullQueryOptions, getAccountNotificationsInfiniteQueryOptions, getAccountPendingRecoveryQueryOptions, getAccountPosts, getAccountPostsInfiniteQueryOptions, getAccountPostsQueryOptions, getAccountRcQueryOptions, getAccountRecoveriesQueryOptions, getAccountReputationsQueryOptions, getAccountSubscriptionsQueryOptions, getAccountVoteHistoryInfiniteQueryOptions, getAccountsQueryOptions, getActiveAccountBookmarksQueryOptions, getActiveAccountFavouritesQueryOptions, getAnnouncementsQueryOptions, getBoostPlusAccountPricesQueryOptions, getBoostPlusPricesQueryOptions, getBotsQueryOptions, getBoundFetch, getChainPropertiesQueryOptions, getCollateralizedConversionRequestsQueryOptions, getCommentHistoryQueryOptions, getCommunities, getCommunitiesQueryOptions, getCommunity, getCommunityContextQueryOptions, getCommunityPermissions, getCommunityQueryOptions, getCommunitySubscribersQueryOptions, getCommunityType, getContentQueryOptions, getContentRepliesQueryOptions, getControversialRisingInfiniteQueryOptions, getConversionRequestsQueryOptions, getCurrencyRate, getCurrencyRates, getCurrencyTokenRate, getDeletedEntryQueryOptions, getDiscoverCurationQueryOptions, getDiscoverLeaderboardQueryOptions, getDiscussion, getDiscussionQueryOptions, getDiscussionsQueryOptions, getDraftsQueryOptions, getDynamicPropsQueryOptions, getEntryActiveVotesQueryOptions, getFollowCountQueryOptions, getFollowingQueryOptions, getFragmentsQueryOptions, getFriendsInfiniteQueryOptions, getGalleryImagesQueryOptions, getGameStatusCheckQueryOptions, getHiveEngineMetrics, getHiveEngineOpenOrders, getHiveEngineOrderBook, getHiveEngineTokenMetrics, getHiveEngineTokenTransactions, getHiveEngineTokensBalances, getHiveEngineTokensMarket, getHiveEngineTokensMetadata, getHiveEngineTradeHistory, getHiveEngineUnclaimedRewards, getHiveHbdStatsQueryOptions, getHivePoshLinksQueryOptions, getHivePrice, getImagesQueryOptions, getIncomingRcQueryOptions, getMarketData, getMarketDataQueryOptions, getMarketHistoryQueryOptions, getMarketStatisticsQueryOptions, getMutedUsersQueryOptions, getNormalizePostQueryOptions, getNotificationSetting, getNotifications, getNotificationsInfiniteQueryOptions, getNotificationsSettingsQueryOptions, getNotificationsUnreadCountQueryOptions, getOpenOrdersQueryOptions, getOrderBookQueryOptions, getOutgoingRcDelegationsInfiniteQueryOptions, getPageStatsQueryOptions, getPointsQueryOptions, getPost, getPostHeader, getPostHeaderQueryOptions, getPostQueryOptions, getPostTipsQueryOptions, getPostsRanked, getPostsRankedInfiniteQueryOptions, getPostsRankedQueryOptions, getProfiles, getProfilesQueryOptions, getPromotePriceQueryOptions, getPromotedPost, getPromotedPostsQuery, getProposalQueryOptions, getProposalVotesInfiniteQueryOptions, getProposalsQueryOptions, getQueryClient, getRcStatsQueryOptions, getReblogsQueryOptions, getReceivedVestingSharesQueryOptions, getReferralsInfiniteQueryOptions, getReferralsStatsQueryOptions, getRelationshipBetweenAccounts, getRelationshipBetweenAccountsQueryOptions, getRewardedCommunitiesQueryOptions, getSavingsWithdrawFromQueryOptions, getSchedulesQueryOptions, getSearchAccountQueryOptions, getSearchAccountsByUsernameQueryOptions, getSearchApiInfiniteQueryOptions, getSearchFriendsQueryOptions, getSearchPathQueryOptions, getSearchTopicsQueryOptions, getSimilarEntriesQueryOptions, getSpkMarkets, getSpkWallet, getStatsQueryOptions, getSubscribers, getSubscriptions, getTradeHistoryQueryOptions, getTransactionsInfiniteQueryOptions, getTrendingTagsQueryOptions, getTrendingTagsWithStatsQueryOptions, getUserProposalVotesQueryOptions, getVestingDelegationsQueryOptions, getVisibleFirstLevelThreadItems, getWavesByHostQueryOptions, getWavesByTagQueryOptions, getWavesFollowingQueryOptions, getWavesTrendingTagsQueryOptions, getWithdrawRoutesQueryOptions, getWitnessesInfiniteQueryOptions, hsTokenRenew, isCommunity, lookupAccountsQueryOptions, makeQueryClient, mapThreadItemsToWaveEntries, markNotifications, moveSchedule, normalizePost, normalizeWaveEntryFromApi, onboardEmail, parseAccounts, parseAsset, parseProfileMetadata, powerRechargeTime, rcPower, resolvePost, roleMap, saveNotificationSetting, search, searchAccount, searchPath, searchQueryOptions, searchTag, signUp, sortDiscussions, subscribeEmail, toEntryArray, updateDraft, uploadImage, useAccountFavouriteAdd, useAccountFavouriteDelete, useAccountRelationsUpdate, useAccountRevokeKey, useAccountRevokePosting, useAccountUpdate, useAccountUpdateKeyAuths, useAccountUpdatePassword, useAccountUpdateRecovery, useAddFragment, useBookmarkAdd, useBookmarkDelete, useBroadcastMutation, useEditFragment, useGameClaim, useRecordActivity, useRemoveFragment, useSignOperationByHivesigner, useSignOperationByKey, useSignOperationByKeychain, usrActivity, validatePostCreating, votingPower, votingValue };
4914
5092
  //# sourceMappingURL=index.js.map
4915
5093
  //# sourceMappingURL=index.js.map