@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.
@@ -8,54 +8,7 @@ var __export = (target, all) => {
8
8
  for (var name in all)
9
9
  __defProp(target, name, { get: all[name], enumerable: true });
10
10
  };
11
-
12
- // src/modules/keychain/keychain.ts
13
- var keychain_exports = {};
14
- __export(keychain_exports, {
15
- broadcast: () => broadcast,
16
- customJson: () => customJson,
17
- handshake: () => handshake
18
- });
19
- function handshake() {
20
- return new Promise((resolve) => {
21
- window.hive_keychain?.requestHandshake(() => {
22
- resolve();
23
- });
24
- });
25
- }
26
- var broadcast = (account, operations, key, rpc = null) => new Promise((resolve, reject) => {
27
- window.hive_keychain?.requestBroadcast(
28
- account,
29
- operations,
30
- key,
31
- (resp) => {
32
- if (!resp.success) {
33
- reject({ message: "Operation cancelled" });
34
- }
35
- resolve(resp);
36
- },
37
- rpc
38
- );
39
- });
40
- var customJson = (account, id, key, json, display_msg, rpc = null) => new Promise((resolve, reject) => {
41
- window.hive_keychain?.requestCustomJson(
42
- account,
43
- id,
44
- key,
45
- json,
46
- display_msg,
47
- (resp) => {
48
- if (!resp.success) {
49
- reject({ message: "Operation cancelled" });
50
- }
51
- resolve(resp);
52
- },
53
- rpc
54
- );
55
- });
56
-
57
- // src/modules/core/mutations/use-broadcast-mutation.ts
58
- function useBroadcastMutation(mutationKey = [], username, accessToken, operations, onSuccess = () => {
11
+ function useBroadcastMutation(mutationKey = [], username, operations, onSuccess = () => {
59
12
  }, auth) {
60
13
  return useMutation({
61
14
  onSuccess,
@@ -66,6 +19,9 @@ function useBroadcastMutation(mutationKey = [], username, accessToken, operation
66
19
  "[Core][Broadcast] Attempted to call broadcast API with anon user"
67
20
  );
68
21
  }
22
+ if (auth?.broadcast) {
23
+ return auth.broadcast(operations(payload), "posting");
24
+ }
69
25
  const postingKey = auth?.postingKey;
70
26
  if (postingKey) {
71
27
  const privateKey = PrivateKey.fromString(postingKey);
@@ -74,34 +30,12 @@ function useBroadcastMutation(mutationKey = [], username, accessToken, operation
74
30
  privateKey
75
31
  );
76
32
  }
77
- const loginType = auth?.loginType;
78
- if (loginType && loginType == "keychain") {
79
- return keychain_exports.broadcast(
80
- username,
81
- operations(payload),
82
- "Posting"
83
- ).then((r) => r.result);
84
- }
33
+ const accessToken = auth?.accessToken;
85
34
  if (accessToken) {
86
- const f = getBoundFetch();
87
- const res = await f("https://hivesigner.com/api/broadcast", {
88
- method: "POST",
89
- headers: {
90
- Authorization: accessToken,
91
- "Content-Type": "application/json",
92
- Accept: "application/json"
93
- },
94
- body: JSON.stringify({ operations: operations(payload) })
95
- });
96
- if (!res.ok) {
97
- const txt = await res.text().catch(() => "");
98
- throw new Error(`[Hivesigner] ${res.status} ${res.statusText} ${txt}`);
99
- }
100
- const json = await res.json();
101
- if (json?.errors) {
102
- throw new Error(`[Hivesigner] ${JSON.stringify(json.errors)}`);
103
- }
104
- 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;
105
39
  }
106
40
  throw new Error(
107
41
  "[SDK][Broadcast] \u2013 cannot broadcast w/o posting key or token"
@@ -109,31 +43,9 @@ function useBroadcastMutation(mutationKey = [], username, accessToken, operation
109
43
  }
110
44
  });
111
45
  }
112
-
113
- // src/modules/core/mock-storage.ts
114
- var MockStorage = class {
115
- length = 0;
116
- clear() {
117
- throw new Error("Method not implemented.");
118
- }
119
- getItem(key) {
120
- return this[key];
121
- }
122
- key(index) {
123
- return Object.keys(this)[index];
124
- }
125
- removeItem(key) {
126
- delete this[key];
127
- }
128
- setItem(key, value) {
129
- this[key] = value;
130
- }
131
- };
132
46
  var CONFIG = {
133
47
  privateApiHost: "https://ecency.com",
134
48
  imageHost: "https://images.ecency.com",
135
- storage: typeof window === "undefined" ? new MockStorage() : window.localStorage,
136
- storagePrefix: "ecency",
137
49
  hiveClient: new Client(
138
50
  [
139
51
  "https://api.hive.blog",
@@ -288,7 +200,7 @@ var ConfigManager;
288
200
  }
289
201
  ConfigManager2.setDmcaLists = setDmcaLists;
290
202
  })(ConfigManager || (ConfigManager = {}));
291
- async function broadcastJson(username, id, payload, accessToken, auth) {
203
+ async function broadcastJson(username, id, payload, auth) {
292
204
  if (!username) {
293
205
  throw new Error(
294
206
  "[Core][Broadcast] Attempted to call broadcast API with anon user"
@@ -300,6 +212,9 @@ async function broadcastJson(username, id, payload, accessToken, auth) {
300
212
  required_posting_auths: [username],
301
213
  json: JSON.stringify(payload)
302
214
  };
215
+ if (auth?.broadcast) {
216
+ return auth.broadcast([["custom_json", jjson]], "posting");
217
+ }
303
218
  const postingKey = auth?.postingKey;
304
219
  if (postingKey) {
305
220
  const privateKey = PrivateKey.fromString(postingKey);
@@ -308,10 +223,7 @@ async function broadcastJson(username, id, payload, accessToken, auth) {
308
223
  privateKey
309
224
  );
310
225
  }
311
- const loginType = auth?.loginType;
312
- if (loginType && loginType == "keychain") {
313
- return keychain_exports.broadcast(username, [["custom_json", jjson]], "Posting").then((r) => r.result);
314
- }
226
+ const accessToken = auth?.accessToken;
315
227
  if (accessToken) {
316
228
  const response = await new hs.Client({
317
229
  accessToken
@@ -322,6 +234,63 @@ async function broadcastJson(username, id, payload, accessToken, auth) {
322
234
  "[SDK][Broadcast] \u2013 cannot broadcast w/o posting key or token"
323
235
  );
324
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 = {}));
325
294
 
326
295
  // src/modules/core/utils/decoder-encoder.ts
327
296
  function encodeObj(o) {
@@ -383,79 +352,7 @@ function isCommunity(value) {
383
352
  return typeof value === "string" ? /^hive-\d+$/.test(value) : false;
384
353
  }
385
354
 
386
- // src/modules/core/storage.ts
387
- var getUser = (username) => {
388
- try {
389
- const raw = CONFIG.storage.getItem(
390
- CONFIG.storagePrefix + "_user_" + username
391
- );
392
- return decodeObj(JSON.parse(raw));
393
- } catch (e) {
394
- console.error(e);
395
- return void 0;
396
- }
397
- };
398
- var getAccessToken = (username) => getUser(username) && getUser(username).accessToken;
399
- var getPostingKey = (username) => getUser(username) && getUser(username).postingKey;
400
- var getLoginType = (username) => getUser(username) && getUser(username).loginType;
401
- var getRefreshToken = (username) => getUser(username) && getUser(username).refreshToken;
402
- function makeQueryClient() {
403
- return new QueryClient({
404
- defaultOptions: {
405
- queries: {
406
- // With SSR, we usually want to set some default staleTime
407
- // above 0 to avoid refetching immediately on the client
408
- // staleTime: 60 * 1000,
409
- refetchOnWindowFocus: false,
410
- refetchOnMount: false
411
- }
412
- }
413
- });
414
- }
415
- var getQueryClient = () => CONFIG.queryClient;
416
- var EcencyQueriesManager;
417
- ((EcencyQueriesManager2) => {
418
- function getQueryData(queryKey) {
419
- const queryClient = getQueryClient();
420
- return queryClient.getQueryData(queryKey);
421
- }
422
- EcencyQueriesManager2.getQueryData = getQueryData;
423
- function getInfiniteQueryData(queryKey) {
424
- const queryClient = getQueryClient();
425
- return queryClient.getQueryData(queryKey);
426
- }
427
- EcencyQueriesManager2.getInfiniteQueryData = getInfiniteQueryData;
428
- async function prefetchQuery(options) {
429
- const queryClient = getQueryClient();
430
- await queryClient.prefetchQuery(options);
431
- return getQueryData(options.queryKey);
432
- }
433
- EcencyQueriesManager2.prefetchQuery = prefetchQuery;
434
- async function prefetchInfiniteQuery(options) {
435
- const queryClient = getQueryClient();
436
- await queryClient.prefetchInfiniteQuery(options);
437
- return getInfiniteQueryData(options.queryKey);
438
- }
439
- EcencyQueriesManager2.prefetchInfiniteQuery = prefetchInfiniteQuery;
440
- function generateClientServerQuery(options) {
441
- return {
442
- prefetch: () => prefetchQuery(options),
443
- getData: () => getQueryData(options.queryKey),
444
- useClientQuery: () => useQuery(options),
445
- fetchAndGet: () => getQueryClient().fetchQuery(options)
446
- };
447
- }
448
- EcencyQueriesManager2.generateClientServerQuery = generateClientServerQuery;
449
- function generateClientServerInfiniteQuery(options) {
450
- return {
451
- prefetch: () => prefetchInfiniteQuery(options),
452
- getData: () => getInfiniteQueryData(options.queryKey),
453
- useClientQuery: () => useInfiniteQuery(options),
454
- fetchAndGet: () => getQueryClient().fetchInfiniteQuery(options)
455
- };
456
- }
457
- EcencyQueriesManager2.generateClientServerInfiniteQuery = generateClientServerInfiniteQuery;
458
- })(EcencyQueriesManager || (EcencyQueriesManager = {}));
355
+ // src/modules/core/queries/get-dynamic-props-query-options.ts
459
356
  function getDynamicPropsQueryOptions() {
460
357
  return queryOptions({
461
358
  queryKey: ["core", "dynamic-props"],
@@ -2384,13 +2281,12 @@ function getProfilesQueryOptions(accounts, observer, enabled = true) {
2384
2281
  }
2385
2282
 
2386
2283
  // src/modules/accounts/mutations/use-account-update.ts
2387
- function useAccountUpdate(username, accessToken, auth) {
2284
+ function useAccountUpdate(username, auth) {
2388
2285
  const queryClient = useQueryClient();
2389
2286
  const { data } = useQuery(getAccountFullQueryOptions(username));
2390
2287
  return useBroadcastMutation(
2391
2288
  ["accounts", "update"],
2392
2289
  username,
2393
- accessToken,
2394
2290
  (payload) => {
2395
2291
  if (!data) {
2396
2292
  throw new Error("[SDK][Accounts] \u2013 cannot update not existing account");
@@ -2432,7 +2328,7 @@ function useAccountUpdate(username, accessToken, auth) {
2432
2328
  auth
2433
2329
  );
2434
2330
  }
2435
- function useAccountRelationsUpdate(reference, target, onSuccess, onError) {
2331
+ function useAccountRelationsUpdate(reference, target, auth, onSuccess, onError) {
2436
2332
  return useMutation({
2437
2333
  mutationKey: ["accounts", "relation", "update", reference, target],
2438
2334
  mutationFn: async (kind) => {
@@ -2444,17 +2340,22 @@ function useAccountRelationsUpdate(reference, target, onSuccess, onError) {
2444
2340
  const actualRelation = getQueryClient().getQueryData(
2445
2341
  relationsQuery.queryKey
2446
2342
  );
2447
- await broadcastJson(reference, "follow", [
2343
+ await broadcastJson(
2344
+ reference,
2448
2345
  "follow",
2449
- {
2450
- follower: reference,
2451
- following: target,
2452
- what: [
2453
- ...kind === "toggle-ignore" && !actualRelation?.ignores ? ["ignore"] : [],
2454
- ...kind === "toggle-follow" && !actualRelation?.follows ? ["blog"] : []
2455
- ]
2456
- }
2457
- ]);
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
+ );
2458
2359
  return {
2459
2360
  ...actualRelation,
2460
2361
  ignores: kind === "toggle-ignore" ? !actualRelation?.ignores : actualRelation?.ignores,
@@ -2681,7 +2582,7 @@ function useAccountUpdatePassword(username, options) {
2681
2582
  ...options
2682
2583
  });
2683
2584
  }
2684
- function useAccountRevokePosting(username, options) {
2585
+ function useAccountRevokePosting(username, options, auth) {
2685
2586
  const queryClient = useQueryClient();
2686
2587
  const { data } = useQuery(getAccountFullQueryOptions(username));
2687
2588
  return useMutation({
@@ -2708,11 +2609,10 @@ function useAccountRevokePosting(username, options) {
2708
2609
  if (type === "key" && key) {
2709
2610
  return CONFIG.hiveClient.broadcast.updateAccount(operationBody, key);
2710
2611
  } else if (type === "keychain") {
2711
- return keychain_exports.broadcast(
2712
- data.name,
2713
- [["account_update", operationBody]],
2714
- "Active"
2715
- );
2612
+ if (!auth?.broadcast) {
2613
+ throw new Error("[SDK][Accounts] \u2013 missing keychain broadcaster");
2614
+ }
2615
+ return auth.broadcast([["account_update", operationBody]], "active");
2716
2616
  } else {
2717
2617
  const params = {
2718
2618
  callback: `https://ecency.com/@${data.name}/permissions`
@@ -2743,7 +2643,7 @@ function useAccountRevokePosting(username, options) {
2743
2643
  }
2744
2644
  });
2745
2645
  }
2746
- function useAccountUpdateRecovery(username, code, options) {
2646
+ function useAccountUpdateRecovery(username, code, options, auth) {
2747
2647
  const { data } = useQuery(getAccountFullQueryOptions(username));
2748
2648
  return useMutation({
2749
2649
  mutationKey: ["accounts", "recovery", data?.name],
@@ -2782,11 +2682,10 @@ function useAccountUpdateRecovery(username, code, options) {
2782
2682
  key
2783
2683
  );
2784
2684
  } else if (type === "keychain") {
2785
- return keychain_exports.broadcast(
2786
- data.name,
2787
- [["change_recovery_account", operationBody]],
2788
- "Active"
2789
- );
2685
+ if (!auth?.broadcast) {
2686
+ throw new Error("[SDK][Accounts] \u2013 missing keychain broadcaster");
2687
+ }
2688
+ return auth.broadcast([["change_recovery_account", operationBody]], "owner");
2790
2689
  } else {
2791
2690
  const params = {
2792
2691
  callback: `https://ecency.com/@${data.name}/permissions`
@@ -3006,7 +2905,7 @@ function useSignOperationByKey(username) {
3006
2905
  }
3007
2906
  });
3008
2907
  }
3009
- function useSignOperationByKeychain(username, keyType = "Active") {
2908
+ function useSignOperationByKeychain(username, auth, keyType = "active") {
3010
2909
  return useMutation({
3011
2910
  mutationKey: ["operations", "sign-keychain", username],
3012
2911
  mutationFn: ({ operation }) => {
@@ -3015,7 +2914,10 @@ function useSignOperationByKeychain(username, keyType = "Active") {
3015
2914
  "[SDK][Keychain] \u2013\xA0cannot sign operation with anon user"
3016
2915
  );
3017
2916
  }
3018
- 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);
3019
2921
  }
3020
2922
  });
3021
2923
  }
@@ -4178,6 +4080,13 @@ async function getCurrencyRates() {
4178
4080
  const response = await fetchApi(CONFIG.privateApiHost + "/private-api/market-data/latest");
4179
4081
  return parseJsonResponse(response);
4180
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
+ }
4181
4090
  function getPointsQueryOptions(username, filter = 0) {
4182
4091
  return queryOptions({
4183
4092
  queryKey: ["points", username, filter],
@@ -4906,6 +4815,279 @@ async function hsTokenRenew(code) {
4906
4815
  return data;
4907
4816
  }
4908
4817
 
4909
- 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 };
4910
5092
  //# sourceMappingURL=index.mjs.map
4911
5093
  //# sourceMappingURL=index.mjs.map