@ecency/sdk 1.1.21 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1671 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1075 -0
- package/dist/index.d.ts +1075 -10
- package/dist/index.mjs +1589 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +29 -16
- package/dist/ecency-sdk.es.js +0 -1435
- package/dist/modules/accounts/index.d.ts +0 -3
- package/dist/modules/accounts/mutations/bookmarks/index.d.ts +0 -2
- package/dist/modules/accounts/mutations/bookmarks/use-account-bookmark-add.d.ts +0 -6
- package/dist/modules/accounts/mutations/bookmarks/use-account-bookmark-delete.d.ts +0 -1
- package/dist/modules/accounts/mutations/favourites/index.d.ts +0 -2
- package/dist/modules/accounts/mutations/favourites/use-account-favourite-add.d.ts +0 -1
- package/dist/modules/accounts/mutations/favourites/use-account-favourite-delete.d.ts +0 -1
- package/dist/modules/accounts/mutations/index.d.ts +0 -9
- package/dist/modules/accounts/mutations/use-account-relations-update.d.ts +0 -9
- package/dist/modules/accounts/mutations/use-account-revoke-key.d.ts +0 -19
- package/dist/modules/accounts/mutations/use-account-revoke-posting.d.ts +0 -10
- package/dist/modules/accounts/mutations/use-account-update-key-auths.d.ts +0 -19
- package/dist/modules/accounts/mutations/use-account-update-password.d.ts +0 -12
- package/dist/modules/accounts/mutations/use-account-update-recovery.d.ts +0 -11
- package/dist/modules/accounts/mutations/use-account-update.d.ts +0 -7
- package/dist/modules/accounts/queries/check-username-wallets-pending-query-options.d.ts +0 -16
- package/dist/modules/accounts/queries/get-account-full-query-options.d.ts +0 -245
- package/dist/modules/accounts/queries/get-account-pending-recovery-query-options.d.ts +0 -8
- package/dist/modules/accounts/queries/get-account-recoveries-query-options.d.ts +0 -9
- package/dist/modules/accounts/queries/get-account-subscriptions-query-options.d.ts +0 -10
- package/dist/modules/accounts/queries/get-active-account-bookmarks-query-options.d.ts +0 -9
- package/dist/modules/accounts/queries/get-active-account-favourites-query-options.d.ts +0 -9
- package/dist/modules/accounts/queries/get-relationship-between-accounts-query-options.d.ts +0 -9
- package/dist/modules/accounts/queries/index.d.ts +0 -9
- package/dist/modules/accounts/queries/search-accounts-by-username-query-options.d.ts +0 -8
- package/dist/modules/accounts/types/account-bookmark.d.ts +0 -7
- package/dist/modules/accounts/types/account-favourite.d.ts +0 -5
- package/dist/modules/accounts/types/account-follow-stats.d.ts +0 -5
- package/dist/modules/accounts/types/account-profile.d.ts +0 -19
- package/dist/modules/accounts/types/account-recovery.d.ts +0 -8
- package/dist/modules/accounts/types/account-relationship.d.ts +0 -6
- package/dist/modules/accounts/types/account-reputation.d.ts +0 -4
- package/dist/modules/accounts/types/full-account.d.ts +0 -52
- package/dist/modules/accounts/types/index.d.ts +0 -8
- package/dist/modules/analytics/index.d.ts +0 -2
- package/dist/modules/analytics/mutations/index.d.ts +0 -1
- package/dist/modules/analytics/mutations/use-record-activity.d.ts +0 -3
- package/dist/modules/communities/index.d.ts +0 -3
- package/dist/modules/communities/queries/get-communities-query-options.d.ts +0 -9
- package/dist/modules/communities/queries/get-community-context-query-options.d.ts +0 -20
- package/dist/modules/communities/queries/index.d.ts +0 -2
- package/dist/modules/communities/types/community.d.ts +0 -33
- package/dist/modules/communities/types/index.d.ts +0 -1
- package/dist/modules/communities/utils/index.d.ts +0 -11
- package/dist/modules/core/config.d.ts +0 -15
- package/dist/modules/core/entities/index.d.ts +0 -1
- package/dist/modules/core/entities/user.d.ts +0 -9
- package/dist/modules/core/index.d.ts +0 -7
- package/dist/modules/core/mock-storage.d.ts +0 -9
- package/dist/modules/core/mutations/broadcast-json.d.ts +0 -1
- package/dist/modules/core/mutations/index.d.ts +0 -2
- package/dist/modules/core/mutations/use-broadcast-mutation.d.ts +0 -3
- package/dist/modules/core/queries/get-dynamic-props-query-options.d.ts +0 -9
- package/dist/modules/core/queries/index.d.ts +0 -1
- package/dist/modules/core/queries-manager.d.ts +0 -21
- package/dist/modules/core/storage.d.ts +0 -6
- package/dist/modules/core/types/dynamic-props.d.ts +0 -15
- package/dist/modules/core/types/index.d.ts +0 -1
- package/dist/modules/core/utils/decoder-encoder.d.ts +0 -2
- package/dist/modules/core/utils/index.d.ts +0 -2
- package/dist/modules/core/utils/parse-asset.d.ts +0 -17
- package/dist/modules/games/index.d.ts +0 -3
- package/dist/modules/games/mutations/game-claim.d.ts +0 -2
- package/dist/modules/games/mutations/index.d.ts +0 -1
- package/dist/modules/games/queries/game-status-check-query-options.d.ts +0 -9
- package/dist/modules/games/queries/index.d.ts +0 -1
- package/dist/modules/games/types/game-claim.d.ts +0 -3
- package/dist/modules/games/types/get-game-status.d.ts +0 -7
- package/dist/modules/games/types/index.d.ts +0 -2
- package/dist/modules/integrations/3speak/index.d.ts +0 -6
- package/dist/modules/integrations/3speak/queries/get-account-token-query-options.d.ts +0 -8
- package/dist/modules/integrations/3speak/queries/get-account-videos-query-options.d.ts +0 -9
- package/dist/modules/integrations/3speak/queries/index.d.ts +0 -2
- package/dist/modules/integrations/3speak/types/index.d.ts +0 -1
- package/dist/modules/integrations/3speak/types/three-speak-video.d.ts +0 -52
- package/dist/modules/integrations/hiveposh/index.d.ts +0 -1
- package/dist/modules/integrations/hiveposh/queries/get-hiveposh-links-query-options.d.ts +0 -44
- package/dist/modules/integrations/hiveposh/queries/index.d.ts +0 -1
- package/dist/modules/integrations/hivesigner/index.d.ts +0 -5
- package/dist/modules/integrations/hivesigner/queries/get-decode-memo-query-options.d.ts +0 -8
- package/dist/modules/integrations/hivesigner/queries/index.d.ts +0 -1
- package/dist/modules/integrations/index.d.ts +0 -3
- package/dist/modules/keychain/index.d.ts +0 -2
- package/dist/modules/keychain/keychain.d.ts +0 -10
- package/dist/modules/operations/index.d.ts +0 -2
- package/dist/modules/operations/mutations/index.d.ts +0 -3
- package/dist/modules/operations/mutations/sign-operation-by-hivesigner.d.ts +0 -4
- package/dist/modules/operations/mutations/sign-operation-by-key.d.ts +0 -5
- package/dist/modules/operations/mutations/sign-operation-by-keychain.d.ts +0 -5
- package/dist/modules/operations/queries/get-chain-properties-query-options.d.ts +0 -8
- package/dist/modules/operations/queries/index.d.ts +0 -1
- package/dist/modules/posts/index.d.ts +0 -3
- package/dist/modules/posts/mutations/add-fragment.d.ts +0 -5
- package/dist/modules/posts/mutations/edit-fragment.d.ts +0 -5
- package/dist/modules/posts/mutations/index.d.ts +0 -3
- package/dist/modules/posts/mutations/remove-fragment.d.ts +0 -1
- package/dist/modules/posts/queries/get-fragments-query-options.d.ts +0 -9
- package/dist/modules/posts/queries/get-promoted-posts-query-options.d.ts +0 -8
- package/dist/modules/posts/queries/get-trending-tags-query-options.d.ts +0 -12
- package/dist/modules/posts/queries/index.d.ts +0 -3
- package/dist/modules/posts/types/fragment.d.ts +0 -7
- package/dist/modules/posts/types/index.d.ts +0 -2
- package/dist/modules/posts/types/trending-tag.d.ts +0 -6
- package/dist/modules/resource-credits/index.d.ts +0 -2
- package/dist/modules/resource-credits/queries/get-account-rc-query-options.d.ts +0 -8
- package/dist/modules/resource-credits/queries/get-rc-stats-query-options.d.ts +0 -8
- package/dist/modules/resource-credits/queries/index.d.ts +0 -2
- package/dist/modules/resource-credits/types/index.d.ts +0 -1
- package/dist/modules/resource-credits/types/stats.d.ts +0 -67
package/dist/index.cjs
ADDED
@@ -0,0 +1,1671 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var reactQuery = require('@tanstack/react-query');
|
4
|
+
var dhive = require('@hiveio/dhive');
|
5
|
+
var hs = require('hivesigner');
|
6
|
+
var R = require('remeda');
|
7
|
+
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
9
|
+
|
10
|
+
function _interopNamespace(e) {
|
11
|
+
if (e && e.__esModule) return e;
|
12
|
+
var n = Object.create(null);
|
13
|
+
if (e) {
|
14
|
+
Object.keys(e).forEach(function (k) {
|
15
|
+
if (k !== 'default') {
|
16
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
18
|
+
enumerable: true,
|
19
|
+
get: function () { return e[k]; }
|
20
|
+
});
|
21
|
+
}
|
22
|
+
});
|
23
|
+
}
|
24
|
+
n.default = e;
|
25
|
+
return Object.freeze(n);
|
26
|
+
}
|
27
|
+
|
28
|
+
var hs__default = /*#__PURE__*/_interopDefault(hs);
|
29
|
+
var R__namespace = /*#__PURE__*/_interopNamespace(R);
|
30
|
+
|
31
|
+
var __defProp = Object.defineProperty;
|
32
|
+
var __export = (target, all) => {
|
33
|
+
for (var name in all)
|
34
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
35
|
+
};
|
36
|
+
|
37
|
+
// src/modules/core/mock-storage.ts
|
38
|
+
var MockStorage = class {
|
39
|
+
length = 0;
|
40
|
+
clear() {
|
41
|
+
throw new Error("Method not implemented.");
|
42
|
+
}
|
43
|
+
getItem(key) {
|
44
|
+
return this[key];
|
45
|
+
}
|
46
|
+
key(index) {
|
47
|
+
return Object.keys(this)[index];
|
48
|
+
}
|
49
|
+
removeItem(key) {
|
50
|
+
delete this[key];
|
51
|
+
}
|
52
|
+
setItem(key, value) {
|
53
|
+
this[key] = value;
|
54
|
+
}
|
55
|
+
};
|
56
|
+
var CONFIG = {
|
57
|
+
privateApiHost: "https://ecency.com",
|
58
|
+
storage: typeof window === "undefined" ? new MockStorage() : window.localStorage,
|
59
|
+
storagePrefix: "ecency",
|
60
|
+
hiveClient: new dhive.Client(
|
61
|
+
[
|
62
|
+
"https://api.hive.blog",
|
63
|
+
"https://api.deathwing.me",
|
64
|
+
"https://rpc.mahdiyari.info",
|
65
|
+
"https://api.openhive.network",
|
66
|
+
"https://techcoderx.com",
|
67
|
+
"https://hive-api.arcange.eu",
|
68
|
+
"https://api.syncad.com",
|
69
|
+
"https://anyx.io",
|
70
|
+
"https://api.c0ff33a.uk",
|
71
|
+
"https://hiveapi.actifit.io",
|
72
|
+
"https://hive-api.3speak.tv"
|
73
|
+
],
|
74
|
+
{
|
75
|
+
timeout: 2e3,
|
76
|
+
failoverThreshold: 2,
|
77
|
+
consoleOnFailover: true
|
78
|
+
}
|
79
|
+
),
|
80
|
+
heliusApiKey: process.env.VITE_HELIUS_API_KEY,
|
81
|
+
queryClient: new reactQuery.QueryClient(),
|
82
|
+
plausibleHost: "https://pl.ecency.com",
|
83
|
+
spkNode: "https://spk.good-karma.xyz"
|
84
|
+
};
|
85
|
+
exports.ConfigManager = void 0;
|
86
|
+
((ConfigManager2) => {
|
87
|
+
function setQueryClient(client) {
|
88
|
+
CONFIG.queryClient = client;
|
89
|
+
}
|
90
|
+
ConfigManager2.setQueryClient = setQueryClient;
|
91
|
+
})(exports.ConfigManager || (exports.ConfigManager = {}));
|
92
|
+
|
93
|
+
// src/modules/core/utils/decoder-encoder.ts
|
94
|
+
function decodeObj(o) {
|
95
|
+
let dataToParse = atob(o);
|
96
|
+
if (dataToParse[0] !== "{") {
|
97
|
+
return void 0;
|
98
|
+
}
|
99
|
+
return JSON.parse(dataToParse);
|
100
|
+
}
|
101
|
+
|
102
|
+
// src/modules/core/utils/parse-asset.ts
|
103
|
+
var Symbol2 = /* @__PURE__ */ ((Symbol3) => {
|
104
|
+
Symbol3["HIVE"] = "HIVE";
|
105
|
+
Symbol3["HBD"] = "HBD";
|
106
|
+
Symbol3["VESTS"] = "VESTS";
|
107
|
+
Symbol3["SPK"] = "SPK";
|
108
|
+
return Symbol3;
|
109
|
+
})(Symbol2 || {});
|
110
|
+
var NaiMap = /* @__PURE__ */ ((NaiMap2) => {
|
111
|
+
NaiMap2["@@000000021"] = "HIVE";
|
112
|
+
NaiMap2["@@000000013"] = "HBD";
|
113
|
+
NaiMap2["@@000000037"] = "VESTS";
|
114
|
+
return NaiMap2;
|
115
|
+
})(NaiMap || {});
|
116
|
+
function parseAsset(sval) {
|
117
|
+
if (typeof sval === "string") {
|
118
|
+
const sp = sval.split(" ");
|
119
|
+
return {
|
120
|
+
amount: parseFloat(sp[0]),
|
121
|
+
// @ts-ignore
|
122
|
+
symbol: Symbol2[sp[1]]
|
123
|
+
};
|
124
|
+
} else {
|
125
|
+
return {
|
126
|
+
amount: parseFloat(sval.amount.toString()) / Math.pow(10, sval.precision),
|
127
|
+
// @ts-ignore
|
128
|
+
symbol: NaiMap[sval.nai]
|
129
|
+
};
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
// src/modules/core/storage.ts
|
134
|
+
var getUser = (username) => {
|
135
|
+
try {
|
136
|
+
const raw = CONFIG.storage.getItem(
|
137
|
+
CONFIG.storagePrefix + "_user_" + username
|
138
|
+
);
|
139
|
+
return decodeObj(JSON.parse(raw));
|
140
|
+
} catch (e) {
|
141
|
+
console.error(e);
|
142
|
+
return void 0;
|
143
|
+
}
|
144
|
+
};
|
145
|
+
var getAccessToken = (username) => getUser(username) && getUser(username).accessToken;
|
146
|
+
var getPostingKey = (username) => getUser(username) && getUser(username).postingKey;
|
147
|
+
var getLoginType = (username) => getUser(username) && getUser(username).loginType;
|
148
|
+
var getRefreshToken = (username) => getUser(username) && getUser(username).refreshToken;
|
149
|
+
|
150
|
+
// src/modules/keychain/keychain.ts
|
151
|
+
var keychain_exports = {};
|
152
|
+
__export(keychain_exports, {
|
153
|
+
broadcast: () => broadcast,
|
154
|
+
customJson: () => customJson,
|
155
|
+
handshake: () => handshake
|
156
|
+
});
|
157
|
+
function handshake() {
|
158
|
+
return new Promise((resolve) => {
|
159
|
+
window.hive_keychain?.requestHandshake(() => {
|
160
|
+
resolve();
|
161
|
+
});
|
162
|
+
});
|
163
|
+
}
|
164
|
+
var broadcast = (account, operations, key, rpc = null) => new Promise((resolve, reject) => {
|
165
|
+
window.hive_keychain?.requestBroadcast(
|
166
|
+
account,
|
167
|
+
operations,
|
168
|
+
key,
|
169
|
+
(resp) => {
|
170
|
+
if (!resp.success) {
|
171
|
+
reject({ message: "Operation cancelled" });
|
172
|
+
}
|
173
|
+
resolve(resp);
|
174
|
+
},
|
175
|
+
rpc
|
176
|
+
);
|
177
|
+
});
|
178
|
+
var customJson = (account, id, key, json, display_msg, rpc = null) => new Promise((resolve, reject) => {
|
179
|
+
window.hive_keychain?.requestCustomJson(
|
180
|
+
account,
|
181
|
+
id,
|
182
|
+
key,
|
183
|
+
json,
|
184
|
+
display_msg,
|
185
|
+
(resp) => {
|
186
|
+
if (!resp.success) {
|
187
|
+
reject({ message: "Operation cancelled" });
|
188
|
+
}
|
189
|
+
resolve(resp);
|
190
|
+
},
|
191
|
+
rpc
|
192
|
+
);
|
193
|
+
});
|
194
|
+
|
195
|
+
// src/modules/core/mutations/use-broadcast-mutation.ts
|
196
|
+
function useBroadcastMutation(mutationKey = [], username, operations, onSuccess = () => {
|
197
|
+
}) {
|
198
|
+
return reactQuery.useMutation({
|
199
|
+
onSuccess,
|
200
|
+
mutationKey: [...mutationKey, username],
|
201
|
+
mutationFn: async (payload) => {
|
202
|
+
if (!username) {
|
203
|
+
throw new Error(
|
204
|
+
"[Core][Broadcast] Attempted to call broadcast API with anon user"
|
205
|
+
);
|
206
|
+
}
|
207
|
+
const postingKey = getPostingKey(username);
|
208
|
+
if (postingKey) {
|
209
|
+
const privateKey = dhive.PrivateKey.fromString(postingKey);
|
210
|
+
return CONFIG.hiveClient.broadcast.sendOperations(
|
211
|
+
operations(payload),
|
212
|
+
privateKey
|
213
|
+
);
|
214
|
+
}
|
215
|
+
const loginType = getLoginType(username);
|
216
|
+
if (loginType && loginType == "keychain") {
|
217
|
+
return keychain_exports.broadcast(
|
218
|
+
username,
|
219
|
+
operations(payload),
|
220
|
+
"Posting"
|
221
|
+
).then((r) => r.result);
|
222
|
+
}
|
223
|
+
let token = getAccessToken(username);
|
224
|
+
if (token) {
|
225
|
+
const response = await new hs__default.default.Client({
|
226
|
+
accessToken: token
|
227
|
+
}).broadcast(operations(payload));
|
228
|
+
return response.result;
|
229
|
+
}
|
230
|
+
throw new Error(
|
231
|
+
"[SDK][Broadcast] \u2013 cannot broadcast w/o posting key or token"
|
232
|
+
);
|
233
|
+
}
|
234
|
+
});
|
235
|
+
}
|
236
|
+
async function broadcastJson(username, id, payload) {
|
237
|
+
if (!username) {
|
238
|
+
throw new Error(
|
239
|
+
"[Core][Broadcast] Attempted to call broadcast API with anon user"
|
240
|
+
);
|
241
|
+
}
|
242
|
+
const jjson = {
|
243
|
+
id,
|
244
|
+
required_auths: [],
|
245
|
+
required_posting_auths: [username],
|
246
|
+
json: JSON.stringify(payload)
|
247
|
+
};
|
248
|
+
const postingKey = getPostingKey(username);
|
249
|
+
if (postingKey) {
|
250
|
+
const privateKey = dhive.PrivateKey.fromString(postingKey);
|
251
|
+
return CONFIG.hiveClient.broadcast.json(
|
252
|
+
jjson,
|
253
|
+
privateKey
|
254
|
+
);
|
255
|
+
}
|
256
|
+
const loginType = getLoginType(username);
|
257
|
+
if (loginType && loginType == "keychain") {
|
258
|
+
return keychain_exports.broadcast(username, [["custom_json", jjson]], "Posting").then((r) => r.result);
|
259
|
+
}
|
260
|
+
let token = getAccessToken(username);
|
261
|
+
if (token) {
|
262
|
+
const response = await new hs__default.default.Client({
|
263
|
+
accessToken: token
|
264
|
+
}).customJson([], [username], id, JSON.stringify(payload));
|
265
|
+
return response.result;
|
266
|
+
}
|
267
|
+
throw new Error(
|
268
|
+
"[SDK][Broadcast] \u2013 cannot broadcast w/o posting key or token"
|
269
|
+
);
|
270
|
+
}
|
271
|
+
function makeQueryClient() {
|
272
|
+
return new reactQuery.QueryClient({
|
273
|
+
defaultOptions: {
|
274
|
+
queries: {
|
275
|
+
// With SSR, we usually want to set some default staleTime
|
276
|
+
// above 0 to avoid refetching immediately on the client
|
277
|
+
// staleTime: 60 * 1000,
|
278
|
+
refetchOnWindowFocus: false,
|
279
|
+
refetchOnMount: false
|
280
|
+
}
|
281
|
+
}
|
282
|
+
});
|
283
|
+
}
|
284
|
+
var getQueryClient = () => CONFIG.queryClient;
|
285
|
+
exports.EcencyQueriesManager = void 0;
|
286
|
+
((EcencyQueriesManager2) => {
|
287
|
+
function getQueryData(queryKey) {
|
288
|
+
const queryClient = getQueryClient();
|
289
|
+
return queryClient.getQueryData(queryKey);
|
290
|
+
}
|
291
|
+
EcencyQueriesManager2.getQueryData = getQueryData;
|
292
|
+
function getInfiniteQueryData(queryKey) {
|
293
|
+
const queryClient = getQueryClient();
|
294
|
+
return queryClient.getQueryData(queryKey);
|
295
|
+
}
|
296
|
+
EcencyQueriesManager2.getInfiniteQueryData = getInfiniteQueryData;
|
297
|
+
async function prefetchQuery(options) {
|
298
|
+
const queryClient = getQueryClient();
|
299
|
+
await queryClient.prefetchQuery(options);
|
300
|
+
return getQueryData(options.queryKey);
|
301
|
+
}
|
302
|
+
EcencyQueriesManager2.prefetchQuery = prefetchQuery;
|
303
|
+
async function prefetchInfiniteQuery(options) {
|
304
|
+
const queryClient = getQueryClient();
|
305
|
+
await queryClient.prefetchInfiniteQuery(options);
|
306
|
+
return getInfiniteQueryData(options.queryKey);
|
307
|
+
}
|
308
|
+
EcencyQueriesManager2.prefetchInfiniteQuery = prefetchInfiniteQuery;
|
309
|
+
function generateClientServerQuery(options) {
|
310
|
+
return {
|
311
|
+
prefetch: () => prefetchQuery(options),
|
312
|
+
getData: () => getQueryData(options.queryKey),
|
313
|
+
useClientQuery: () => reactQuery.useQuery(options),
|
314
|
+
fetchAndGet: () => getQueryClient().fetchQuery(options)
|
315
|
+
};
|
316
|
+
}
|
317
|
+
EcencyQueriesManager2.generateClientServerQuery = generateClientServerQuery;
|
318
|
+
function generateClientServerInfiniteQuery(options) {
|
319
|
+
return {
|
320
|
+
prefetch: () => prefetchInfiniteQuery(options),
|
321
|
+
getData: () => getInfiniteQueryData(options.queryKey),
|
322
|
+
useClientQuery: () => reactQuery.useInfiniteQuery(options),
|
323
|
+
fetchAndGet: () => getQueryClient().fetchInfiniteQuery(options)
|
324
|
+
};
|
325
|
+
}
|
326
|
+
EcencyQueriesManager2.generateClientServerInfiniteQuery = generateClientServerInfiniteQuery;
|
327
|
+
})(exports.EcencyQueriesManager || (exports.EcencyQueriesManager = {}));
|
328
|
+
function getDynamicPropsQueryOptions() {
|
329
|
+
return reactQuery.queryOptions({
|
330
|
+
queryKey: ["core", "dynamic-props"],
|
331
|
+
refetchInterval: 6e4,
|
332
|
+
staleTime: 6e4,
|
333
|
+
refetchOnMount: true,
|
334
|
+
queryFn: async () => {
|
335
|
+
const globalDynamic = await CONFIG.hiveClient.database.getDynamicGlobalProperties().then((r) => ({
|
336
|
+
total_vesting_fund_hive: r.total_vesting_fund_hive || r.total_vesting_fund_steem,
|
337
|
+
total_vesting_shares: r.total_vesting_shares,
|
338
|
+
hbd_print_rate: r.hbd_print_rate || r.sbd_print_rate,
|
339
|
+
hbd_interest_rate: r.hbd_interest_rate,
|
340
|
+
head_block_number: r.head_block_number,
|
341
|
+
vesting_reward_percent: r.vesting_reward_percent,
|
342
|
+
virtual_supply: r.virtual_supply
|
343
|
+
}));
|
344
|
+
const feedHistory = await CONFIG.hiveClient.database.call("get_feed_history");
|
345
|
+
const chainProps = await CONFIG.hiveClient.database.call(
|
346
|
+
"get_chain_properties"
|
347
|
+
);
|
348
|
+
const rewardFund = await CONFIG.hiveClient.database.call(
|
349
|
+
"get_reward_fund",
|
350
|
+
["post"]
|
351
|
+
);
|
352
|
+
const hivePerMVests = parseAsset(globalDynamic.total_vesting_fund_hive).amount / parseAsset(globalDynamic.total_vesting_shares).amount * 1e6;
|
353
|
+
const base = parseAsset(feedHistory.current_median_history.base).amount;
|
354
|
+
const quote = parseAsset(feedHistory.current_median_history.quote).amount;
|
355
|
+
const fundRecentClaims = parseFloat(rewardFund.recent_claims);
|
356
|
+
const fundRewardBalance = parseAsset(rewardFund.reward_balance).amount;
|
357
|
+
const hbdPrintRate = globalDynamic.hbd_print_rate;
|
358
|
+
const hbdInterestRate = globalDynamic.hbd_interest_rate;
|
359
|
+
const headBlock = globalDynamic.head_block_number;
|
360
|
+
const totalVestingFund = parseAsset(
|
361
|
+
globalDynamic.total_vesting_fund_hive
|
362
|
+
).amount;
|
363
|
+
const totalVestingShares = parseAsset(
|
364
|
+
globalDynamic.total_vesting_shares
|
365
|
+
).amount;
|
366
|
+
const virtualSupply = parseAsset(globalDynamic.virtual_supply).amount;
|
367
|
+
const vestingRewardPercent = globalDynamic.vesting_reward_percent;
|
368
|
+
const accountCreationFee = chainProps.account_creation_fee;
|
369
|
+
return {
|
370
|
+
hivePerMVests,
|
371
|
+
base,
|
372
|
+
quote,
|
373
|
+
fundRecentClaims,
|
374
|
+
fundRewardBalance,
|
375
|
+
hbdPrintRate,
|
376
|
+
hbdInterestRate,
|
377
|
+
headBlock,
|
378
|
+
totalVestingFund,
|
379
|
+
totalVestingShares,
|
380
|
+
virtualSupply,
|
381
|
+
vestingRewardPercent,
|
382
|
+
accountCreationFee
|
383
|
+
};
|
384
|
+
}
|
385
|
+
});
|
386
|
+
}
|
387
|
+
function getAccountFullQueryOptions(username) {
|
388
|
+
return reactQuery.queryOptions({
|
389
|
+
queryKey: ["get-account-full", username],
|
390
|
+
queryFn: async () => {
|
391
|
+
if (!username) {
|
392
|
+
throw new Error("[SDK] Username is empty");
|
393
|
+
}
|
394
|
+
const response = await CONFIG.hiveClient.database.getAccounts([
|
395
|
+
username
|
396
|
+
]);
|
397
|
+
if (!response[0]) {
|
398
|
+
throw new Error("[SDK] No account with given username");
|
399
|
+
}
|
400
|
+
const profile = JSON.parse(response[0].posting_json_metadata).profile;
|
401
|
+
let follow_stats;
|
402
|
+
try {
|
403
|
+
follow_stats = await CONFIG.hiveClient.database.call(
|
404
|
+
"get_follow_count",
|
405
|
+
[username]
|
406
|
+
);
|
407
|
+
} catch (e) {
|
408
|
+
}
|
409
|
+
const reputation = await CONFIG.hiveClient.call(
|
410
|
+
"condenser_api",
|
411
|
+
"get_account_reputations",
|
412
|
+
[username, 1]
|
413
|
+
);
|
414
|
+
return {
|
415
|
+
name: response[0].name,
|
416
|
+
owner: response[0].owner,
|
417
|
+
active: response[0].active,
|
418
|
+
posting: response[0].posting,
|
419
|
+
memo_key: response[0].memo_key,
|
420
|
+
post_count: response[0].post_count,
|
421
|
+
created: response[0].created,
|
422
|
+
posting_json_metadata: response[0].posting_json_metadata,
|
423
|
+
last_vote_time: response[0].last_vote_time,
|
424
|
+
last_post: response[0].last_post,
|
425
|
+
json_metadata: response[0].json_metadata,
|
426
|
+
reward_hive_balance: response[0].reward_hive_balance,
|
427
|
+
reward_hbd_balance: response[0].reward_hbd_balance,
|
428
|
+
reward_vesting_hive: response[0].reward_vesting_hive,
|
429
|
+
reward_vesting_balance: response[0].reward_vesting_balance,
|
430
|
+
balance: response[0].balance,
|
431
|
+
hbd_balance: response[0].hbd_balance,
|
432
|
+
savings_balance: response[0].savings_balance,
|
433
|
+
savings_hbd_balance: response[0].savings_hbd_balance,
|
434
|
+
savings_hbd_last_interest_payment: response[0].savings_hbd_last_interest_payment,
|
435
|
+
savings_hbd_seconds_last_update: response[0].savings_hbd_seconds_last_update,
|
436
|
+
savings_hbd_seconds: response[0].savings_hbd_seconds,
|
437
|
+
next_vesting_withdrawal: response[0].next_vesting_withdrawal,
|
438
|
+
pending_claimed_accounts: response[0].pending_claimed_accounts,
|
439
|
+
vesting_shares: response[0].vesting_shares,
|
440
|
+
delegated_vesting_shares: response[0].delegated_vesting_shares,
|
441
|
+
received_vesting_shares: response[0].received_vesting_shares,
|
442
|
+
vesting_withdraw_rate: response[0].vesting_withdraw_rate,
|
443
|
+
to_withdraw: response[0].to_withdraw,
|
444
|
+
withdrawn: response[0].withdrawn,
|
445
|
+
witness_votes: response[0].witness_votes,
|
446
|
+
proxy: response[0].proxy,
|
447
|
+
recovery_account: response[0].recovery_account,
|
448
|
+
proxied_vsf_votes: response[0].proxied_vsf_votes,
|
449
|
+
voting_manabar: response[0].voting_manabar,
|
450
|
+
voting_power: response[0].voting_power,
|
451
|
+
downvote_manabar: response[0].downvote_manabar,
|
452
|
+
follow_stats,
|
453
|
+
reputation: reputation[0].reputation,
|
454
|
+
profile: {
|
455
|
+
...profile,
|
456
|
+
reputation: reputation[0].reputation
|
457
|
+
}
|
458
|
+
};
|
459
|
+
},
|
460
|
+
enabled: !!username,
|
461
|
+
staleTime: 6e4
|
462
|
+
});
|
463
|
+
}
|
464
|
+
function getSearchAccountsByUsernameQueryOptions(query, limit = 5, excludeList = []) {
|
465
|
+
return reactQuery.queryOptions({
|
466
|
+
queryKey: ["accounts", "search", query, excludeList],
|
467
|
+
enabled: !!query,
|
468
|
+
queryFn: async () => {
|
469
|
+
const response = await CONFIG.hiveClient.database.call(
|
470
|
+
"lookup_accounts",
|
471
|
+
[query, limit]
|
472
|
+
);
|
473
|
+
return response.filter(
|
474
|
+
(item) => excludeList.length > 0 ? !excludeList.includes(item) : true
|
475
|
+
);
|
476
|
+
}
|
477
|
+
});
|
478
|
+
}
|
479
|
+
function checkUsernameWalletsPendingQueryOptions(username) {
|
480
|
+
return reactQuery.queryOptions({
|
481
|
+
queryKey: ["accounts", "check-wallet-pending", username],
|
482
|
+
queryFn: async () => {
|
483
|
+
const response = await fetch(
|
484
|
+
CONFIG.privateApiHost + "/private-api/wallets-chkuser",
|
485
|
+
{
|
486
|
+
method: "POST",
|
487
|
+
headers: {
|
488
|
+
"Content-Type": "application/json"
|
489
|
+
},
|
490
|
+
body: JSON.stringify({
|
491
|
+
username
|
492
|
+
})
|
493
|
+
}
|
494
|
+
);
|
495
|
+
return await response.json();
|
496
|
+
},
|
497
|
+
enabled: !!username,
|
498
|
+
refetchOnMount: true
|
499
|
+
});
|
500
|
+
}
|
501
|
+
function getRelationshipBetweenAccountsQueryOptions(reference, target) {
|
502
|
+
return reactQuery.queryOptions({
|
503
|
+
queryKey: ["accounts", "relations", reference, target],
|
504
|
+
enabled: !!reference && !!target,
|
505
|
+
refetchOnMount: false,
|
506
|
+
refetchInterval: 36e5,
|
507
|
+
queryFn: async () => {
|
508
|
+
return await CONFIG.hiveClient.call(
|
509
|
+
"bridge",
|
510
|
+
"get_relationship_between_accounts",
|
511
|
+
[reference, target]
|
512
|
+
);
|
513
|
+
}
|
514
|
+
});
|
515
|
+
}
|
516
|
+
function getAccountSubscriptionsQueryOptions(username) {
|
517
|
+
return reactQuery.queryOptions({
|
518
|
+
queryKey: ["accounts", "subscriptions", username],
|
519
|
+
enabled: !!username,
|
520
|
+
queryFn: async () => {
|
521
|
+
const response = await CONFIG.hiveClient.call(
|
522
|
+
"bridge",
|
523
|
+
"list_all_subscriptions",
|
524
|
+
{
|
525
|
+
account: username
|
526
|
+
}
|
527
|
+
);
|
528
|
+
return response ?? [];
|
529
|
+
}
|
530
|
+
});
|
531
|
+
}
|
532
|
+
function getActiveAccountBookmarksQueryOptions(activeUsername) {
|
533
|
+
return reactQuery.queryOptions({
|
534
|
+
queryKey: ["accounts", "bookmarks", activeUsername],
|
535
|
+
enabled: !!activeUsername,
|
536
|
+
queryFn: async () => {
|
537
|
+
if (!activeUsername) {
|
538
|
+
throw new Error("[SDK][Accounts][Bookmarks] \u2013 no active user");
|
539
|
+
}
|
540
|
+
const response = await fetch(
|
541
|
+
CONFIG.privateApiHost + "/private-api/bookmarks",
|
542
|
+
{
|
543
|
+
method: "POST",
|
544
|
+
headers: {
|
545
|
+
"Content-Type": "application/json"
|
546
|
+
},
|
547
|
+
body: JSON.stringify({ code: getAccessToken(activeUsername) })
|
548
|
+
}
|
549
|
+
);
|
550
|
+
return await response.json();
|
551
|
+
}
|
552
|
+
});
|
553
|
+
}
|
554
|
+
function getActiveAccountFavouritesQueryOptions(activeUsername) {
|
555
|
+
return reactQuery.queryOptions({
|
556
|
+
queryKey: ["accounts", "favourites", activeUsername],
|
557
|
+
enabled: !!activeUsername,
|
558
|
+
queryFn: async () => {
|
559
|
+
if (!activeUsername) {
|
560
|
+
throw new Error("[SDK][Accounts][Favourites] \u2013 no active user");
|
561
|
+
}
|
562
|
+
const response = await fetch(
|
563
|
+
CONFIG.privateApiHost + "/private-api/favorites",
|
564
|
+
{
|
565
|
+
method: "POST",
|
566
|
+
headers: {
|
567
|
+
"Content-Type": "application/json"
|
568
|
+
},
|
569
|
+
body: JSON.stringify({ code: getAccessToken(activeUsername) })
|
570
|
+
}
|
571
|
+
);
|
572
|
+
return await response.json();
|
573
|
+
}
|
574
|
+
});
|
575
|
+
}
|
576
|
+
function getAccountRecoveriesQueryOptions(username) {
|
577
|
+
return reactQuery.queryOptions({
|
578
|
+
enabled: !!username,
|
579
|
+
queryKey: ["accounts", "recoveries", username],
|
580
|
+
queryFn: async () => {
|
581
|
+
const response = await fetch(
|
582
|
+
CONFIG.privateApiHost + "/private-api/recoveries",
|
583
|
+
{
|
584
|
+
method: "POST",
|
585
|
+
headers: {
|
586
|
+
"Content-Type": "application/json"
|
587
|
+
},
|
588
|
+
body: JSON.stringify({ code: getAccessToken(username) })
|
589
|
+
}
|
590
|
+
);
|
591
|
+
return response.json();
|
592
|
+
}
|
593
|
+
});
|
594
|
+
}
|
595
|
+
function getAccountPendingRecoveryQueryOptions(username) {
|
596
|
+
return reactQuery.queryOptions({
|
597
|
+
enabled: !!username,
|
598
|
+
queryKey: ["accounts", "recoveries", username, "pending-request"],
|
599
|
+
queryFn: () => CONFIG.hiveClient.call(
|
600
|
+
"database_api",
|
601
|
+
"find_change_recovery_account_requests",
|
602
|
+
{ accounts: [username] }
|
603
|
+
)
|
604
|
+
});
|
605
|
+
}
|
606
|
+
function sanitizeTokens(tokens) {
|
607
|
+
return tokens?.map(({ meta, ...rest }) => {
|
608
|
+
if (!meta || typeof meta !== "object") {
|
609
|
+
return { ...rest, meta };
|
610
|
+
}
|
611
|
+
const { privateKey, username, ...safeMeta } = meta;
|
612
|
+
return { ...rest, meta: safeMeta };
|
613
|
+
});
|
614
|
+
}
|
615
|
+
function getBuiltProfile({
|
616
|
+
profile,
|
617
|
+
tokens,
|
618
|
+
data
|
619
|
+
}) {
|
620
|
+
const metadata = R__namespace.pipe(
|
621
|
+
JSON.parse(data?.posting_json_metadata || "{}").profile,
|
622
|
+
R__namespace.mergeDeep(profile ?? {})
|
623
|
+
);
|
624
|
+
if (tokens && tokens.length > 0) {
|
625
|
+
metadata.tokens = tokens;
|
626
|
+
}
|
627
|
+
metadata.tokens = sanitizeTokens(metadata.tokens);
|
628
|
+
return metadata;
|
629
|
+
}
|
630
|
+
function useAccountUpdate(username) {
|
631
|
+
const queryClient = reactQuery.useQueryClient();
|
632
|
+
const { data } = reactQuery.useQuery(getAccountFullQueryOptions(username));
|
633
|
+
return useBroadcastMutation(
|
634
|
+
["accounts", "update"],
|
635
|
+
username,
|
636
|
+
(payload) => {
|
637
|
+
if (!data) {
|
638
|
+
throw new Error("[SDK][Accounts] \u2013 cannot update not existing account");
|
639
|
+
}
|
640
|
+
return [
|
641
|
+
[
|
642
|
+
"account_update2",
|
643
|
+
{
|
644
|
+
account: username,
|
645
|
+
json_metadata: "",
|
646
|
+
extensions: [],
|
647
|
+
posting_json_metadata: JSON.stringify({
|
648
|
+
profile: getBuiltProfile({ ...payload, data })
|
649
|
+
})
|
650
|
+
}
|
651
|
+
]
|
652
|
+
];
|
653
|
+
},
|
654
|
+
(_, variables) => queryClient.setQueryData(
|
655
|
+
getAccountFullQueryOptions(username).queryKey,
|
656
|
+
(data2) => {
|
657
|
+
if (!data2) {
|
658
|
+
return data2;
|
659
|
+
}
|
660
|
+
const obj = R__namespace.clone(data2);
|
661
|
+
obj.profile = getBuiltProfile({ ...variables, data: data2 });
|
662
|
+
return obj;
|
663
|
+
}
|
664
|
+
)
|
665
|
+
);
|
666
|
+
}
|
667
|
+
function useAccountRelationsUpdate(reference, target, onSuccess, onError) {
|
668
|
+
return reactQuery.useMutation({
|
669
|
+
mutationKey: ["accounts", "relation", "update", reference, target],
|
670
|
+
mutationFn: async (kind) => {
|
671
|
+
const relationsQuery = getRelationshipBetweenAccountsQueryOptions(
|
672
|
+
reference,
|
673
|
+
target
|
674
|
+
);
|
675
|
+
await getQueryClient().prefetchQuery(relationsQuery);
|
676
|
+
const actualRelation = getQueryClient().getQueryData(
|
677
|
+
relationsQuery.queryKey
|
678
|
+
);
|
679
|
+
await broadcastJson(reference, "follow", [
|
680
|
+
"follow",
|
681
|
+
{
|
682
|
+
follower: reference,
|
683
|
+
following: target,
|
684
|
+
what: [
|
685
|
+
...kind === "toggle-ignore" && !actualRelation?.ignores ? ["ignore"] : [],
|
686
|
+
...kind === "toggle-follow" && !actualRelation?.follows ? ["blog"] : []
|
687
|
+
]
|
688
|
+
}
|
689
|
+
]);
|
690
|
+
return {
|
691
|
+
...actualRelation,
|
692
|
+
ignores: kind === "toggle-ignore" ? !actualRelation?.ignores : actualRelation?.ignores,
|
693
|
+
follows: kind === "toggle-follow" ? !actualRelation?.follows : actualRelation?.follows
|
694
|
+
};
|
695
|
+
},
|
696
|
+
onError,
|
697
|
+
onSuccess(data) {
|
698
|
+
onSuccess(data);
|
699
|
+
getQueryClient().setQueryData(
|
700
|
+
["accounts", "relations", reference, target],
|
701
|
+
data
|
702
|
+
);
|
703
|
+
}
|
704
|
+
});
|
705
|
+
}
|
706
|
+
function useBookmarkAdd(username, onSuccess, onError) {
|
707
|
+
return reactQuery.useMutation({
|
708
|
+
mutationKey: ["accounts", "bookmarks", "add", username],
|
709
|
+
mutationFn: async ({ author, permlink }) => {
|
710
|
+
if (!username) {
|
711
|
+
throw new Error("[SDK][Account][Bookmarks] \u2013 no active user");
|
712
|
+
}
|
713
|
+
const response = await fetch(
|
714
|
+
CONFIG.privateApiHost + "/private-api/bookmarks-add",
|
715
|
+
{
|
716
|
+
method: "POST",
|
717
|
+
headers: {
|
718
|
+
"Content-Type": "application/json"
|
719
|
+
},
|
720
|
+
body: JSON.stringify({
|
721
|
+
author,
|
722
|
+
permlink,
|
723
|
+
code: getAccessToken(username)
|
724
|
+
})
|
725
|
+
}
|
726
|
+
);
|
727
|
+
return response.json();
|
728
|
+
},
|
729
|
+
onSuccess: () => {
|
730
|
+
onSuccess();
|
731
|
+
getQueryClient().invalidateQueries({
|
732
|
+
queryKey: ["accounts", "bookmarks", username]
|
733
|
+
});
|
734
|
+
},
|
735
|
+
onError
|
736
|
+
});
|
737
|
+
}
|
738
|
+
function useBookmarkDelete(username, onSuccess, onError) {
|
739
|
+
return reactQuery.useMutation({
|
740
|
+
mutationKey: ["accounts", "bookmarks", "delete", username],
|
741
|
+
mutationFn: async (bookmarkId) => {
|
742
|
+
if (!username) {
|
743
|
+
throw new Error("[SDK][Account][Bookmarks] \u2013 no active user");
|
744
|
+
}
|
745
|
+
const response = await fetch(
|
746
|
+
CONFIG.privateApiHost + "/private-api/bookmarks-delete",
|
747
|
+
{
|
748
|
+
method: "POST",
|
749
|
+
headers: {
|
750
|
+
"Content-Type": "application/json"
|
751
|
+
},
|
752
|
+
body: JSON.stringify({
|
753
|
+
id: bookmarkId,
|
754
|
+
code: getAccessToken(username)
|
755
|
+
})
|
756
|
+
}
|
757
|
+
);
|
758
|
+
return response.json();
|
759
|
+
},
|
760
|
+
onSuccess: () => {
|
761
|
+
onSuccess();
|
762
|
+
getQueryClient().invalidateQueries({
|
763
|
+
queryKey: ["accounts", "bookmarks", username]
|
764
|
+
});
|
765
|
+
},
|
766
|
+
onError
|
767
|
+
});
|
768
|
+
}
|
769
|
+
function useAccountFavouriteAdd(username, onSuccess, onError) {
|
770
|
+
return reactQuery.useMutation({
|
771
|
+
mutationKey: ["accounts", "favourites", "add", username],
|
772
|
+
mutationFn: async (account) => {
|
773
|
+
if (!username) {
|
774
|
+
throw new Error("[SDK][Account][Bookmarks] \u2013 no active user");
|
775
|
+
}
|
776
|
+
const response = await fetch(
|
777
|
+
CONFIG.privateApiHost + "/private-api/favorites-add",
|
778
|
+
{
|
779
|
+
method: "POST",
|
780
|
+
headers: {
|
781
|
+
"Content-Type": "application/json"
|
782
|
+
},
|
783
|
+
body: JSON.stringify({
|
784
|
+
account,
|
785
|
+
code: getAccessToken(username)
|
786
|
+
})
|
787
|
+
}
|
788
|
+
);
|
789
|
+
return response.json();
|
790
|
+
},
|
791
|
+
onSuccess: () => {
|
792
|
+
onSuccess();
|
793
|
+
getQueryClient().invalidateQueries({
|
794
|
+
queryKey: ["accounts", "favourites", username]
|
795
|
+
});
|
796
|
+
},
|
797
|
+
onError
|
798
|
+
});
|
799
|
+
}
|
800
|
+
function useAccountFavouriteDelete(username, onSuccess, onError) {
|
801
|
+
return reactQuery.useMutation({
|
802
|
+
mutationKey: ["accounts", "favourites", "add", username],
|
803
|
+
mutationFn: async (account) => {
|
804
|
+
if (!username) {
|
805
|
+
throw new Error("[SDK][Account][Bookmarks] \u2013 no active user");
|
806
|
+
}
|
807
|
+
const response = await fetch(
|
808
|
+
CONFIG.privateApiHost + "/private-api/favorites-delete",
|
809
|
+
{
|
810
|
+
method: "POST",
|
811
|
+
headers: {
|
812
|
+
"Content-Type": "application/json"
|
813
|
+
},
|
814
|
+
body: JSON.stringify({
|
815
|
+
account,
|
816
|
+
code: getAccessToken(username)
|
817
|
+
})
|
818
|
+
}
|
819
|
+
);
|
820
|
+
return response.json();
|
821
|
+
},
|
822
|
+
onSuccess: () => {
|
823
|
+
onSuccess();
|
824
|
+
getQueryClient().invalidateQueries({
|
825
|
+
queryKey: ["accounts", "favourites", username]
|
826
|
+
});
|
827
|
+
},
|
828
|
+
onError
|
829
|
+
});
|
830
|
+
}
|
831
|
+
function dedupeAndSortKeyAuths(existing, additions) {
|
832
|
+
const merged = /* @__PURE__ */ new Map();
|
833
|
+
existing.forEach(([key, weight]) => {
|
834
|
+
merged.set(key.toString(), weight);
|
835
|
+
});
|
836
|
+
additions.forEach(([key, weight]) => {
|
837
|
+
merged.set(key.toString(), weight);
|
838
|
+
});
|
839
|
+
return Array.from(merged.entries()).sort(([keyA], [keyB]) => keyA.localeCompare(keyB)).map(([key, weight]) => [key, weight]);
|
840
|
+
}
|
841
|
+
function useAccountUpdateKeyAuths(username, options) {
|
842
|
+
const { data: accountData } = reactQuery.useQuery(getAccountFullQueryOptions(username));
|
843
|
+
return reactQuery.useMutation({
|
844
|
+
mutationKey: ["accounts", "keys-update", username],
|
845
|
+
mutationFn: async ({ keys, keepCurrent = false, currentKey }) => {
|
846
|
+
if (!accountData) {
|
847
|
+
throw new Error(
|
848
|
+
"[SDK][Update password] \u2013 cannot update keys for anon user"
|
849
|
+
);
|
850
|
+
}
|
851
|
+
const prepareAuth = (keyName) => {
|
852
|
+
const auth = R__namespace.clone(accountData[keyName]);
|
853
|
+
auth.key_auths = dedupeAndSortKeyAuths(
|
854
|
+
keepCurrent ? auth.key_auths : [],
|
855
|
+
keys.map(
|
856
|
+
(values, i) => [values[keyName].createPublic().toString(), i + 1]
|
857
|
+
)
|
858
|
+
);
|
859
|
+
return auth;
|
860
|
+
};
|
861
|
+
return CONFIG.hiveClient.broadcast.updateAccount(
|
862
|
+
{
|
863
|
+
account: username,
|
864
|
+
json_metadata: accountData.json_metadata,
|
865
|
+
owner: prepareAuth("owner"),
|
866
|
+
active: prepareAuth("active"),
|
867
|
+
posting: prepareAuth("posting"),
|
868
|
+
memo_key: keepCurrent ? accountData.memo_key : keys[0].memo_key.createPublic().toString()
|
869
|
+
},
|
870
|
+
currentKey
|
871
|
+
);
|
872
|
+
},
|
873
|
+
...options
|
874
|
+
});
|
875
|
+
}
|
876
|
+
function useAccountUpdatePassword(username, options) {
|
877
|
+
const { data: accountData } = reactQuery.useQuery(getAccountFullQueryOptions(username));
|
878
|
+
const { mutateAsync: updateKeys } = useAccountUpdateKeyAuths(username);
|
879
|
+
return reactQuery.useMutation({
|
880
|
+
mutationKey: ["accounts", "password-update", username],
|
881
|
+
mutationFn: async ({
|
882
|
+
newPassword,
|
883
|
+
currentPassword,
|
884
|
+
keepCurrent
|
885
|
+
}) => {
|
886
|
+
if (!accountData) {
|
887
|
+
throw new Error(
|
888
|
+
"[SDK][Update password] \u2013 cannot update password for anon user"
|
889
|
+
);
|
890
|
+
}
|
891
|
+
const currentKey = dhive.PrivateKey.fromLogin(
|
892
|
+
username,
|
893
|
+
currentPassword,
|
894
|
+
"owner"
|
895
|
+
);
|
896
|
+
return updateKeys({
|
897
|
+
currentKey,
|
898
|
+
keepCurrent,
|
899
|
+
keys: [
|
900
|
+
{
|
901
|
+
owner: dhive.PrivateKey.fromLogin(username, newPassword, "owner"),
|
902
|
+
active: dhive.PrivateKey.fromLogin(username, newPassword, "active"),
|
903
|
+
posting: dhive.PrivateKey.fromLogin(username, newPassword, "posting"),
|
904
|
+
memo_key: dhive.PrivateKey.fromLogin(username, newPassword, "memo")
|
905
|
+
}
|
906
|
+
]
|
907
|
+
});
|
908
|
+
},
|
909
|
+
...options
|
910
|
+
});
|
911
|
+
}
|
912
|
+
function useAccountRevokePosting(username, options) {
|
913
|
+
const queryClient = reactQuery.useQueryClient();
|
914
|
+
const { data } = reactQuery.useQuery(getAccountFullQueryOptions(username));
|
915
|
+
return reactQuery.useMutation({
|
916
|
+
mutationKey: ["accounts", "revoke-posting", data?.name],
|
917
|
+
mutationFn: async ({ accountName, type, key }) => {
|
918
|
+
if (!data) {
|
919
|
+
throw new Error(
|
920
|
+
"[SDK][Accounts] \u2013\xA0cannot revoke posting for anonymous user"
|
921
|
+
);
|
922
|
+
}
|
923
|
+
const posting = R__namespace.pipe(
|
924
|
+
{},
|
925
|
+
R__namespace.mergeDeep(data.posting)
|
926
|
+
);
|
927
|
+
posting.account_auths = posting.account_auths.filter(
|
928
|
+
([account]) => account !== accountName
|
929
|
+
);
|
930
|
+
const operationBody = {
|
931
|
+
account: data.name,
|
932
|
+
posting,
|
933
|
+
memo_key: data.memo_key,
|
934
|
+
json_metadata: data.json_metadata
|
935
|
+
};
|
936
|
+
if (type === "key" && key) {
|
937
|
+
return CONFIG.hiveClient.broadcast.updateAccount(operationBody, key);
|
938
|
+
} else if (type === "keychain") {
|
939
|
+
return keychain_exports.broadcast(
|
940
|
+
data.name,
|
941
|
+
[["account_update", operationBody]],
|
942
|
+
"Active"
|
943
|
+
);
|
944
|
+
} else {
|
945
|
+
const params = {
|
946
|
+
callback: `https://ecency.com/@${data.name}/permissions`
|
947
|
+
};
|
948
|
+
return hs__default.default.sendOperation(
|
949
|
+
["account_update", operationBody],
|
950
|
+
params,
|
951
|
+
() => {
|
952
|
+
}
|
953
|
+
);
|
954
|
+
}
|
955
|
+
},
|
956
|
+
onError: options.onError,
|
957
|
+
onSuccess: (resp, payload, ctx) => {
|
958
|
+
options.onSuccess?.(resp, payload, ctx);
|
959
|
+
queryClient.setQueryData(
|
960
|
+
getAccountFullQueryOptions(username).queryKey,
|
961
|
+
(data2) => ({
|
962
|
+
...data2,
|
963
|
+
posting: {
|
964
|
+
...data2?.posting,
|
965
|
+
account_auths: data2?.posting?.account_auths?.filter(
|
966
|
+
([account]) => account !== payload.accountName
|
967
|
+
) ?? []
|
968
|
+
}
|
969
|
+
})
|
970
|
+
);
|
971
|
+
}
|
972
|
+
});
|
973
|
+
}
|
974
|
+
function useAccountUpdateRecovery(username, options) {
|
975
|
+
const { data } = reactQuery.useQuery(getAccountFullQueryOptions(username));
|
976
|
+
return reactQuery.useMutation({
|
977
|
+
mutationKey: ["accounts", "recovery", data?.name],
|
978
|
+
mutationFn: async ({ accountName, type, key, email }) => {
|
979
|
+
if (!data) {
|
980
|
+
throw new Error(
|
981
|
+
"[SDK][Accounts] \u2013\xA0cannot change recovery for anonymous user"
|
982
|
+
);
|
983
|
+
}
|
984
|
+
const operationBody = {
|
985
|
+
account_to_recover: data.name,
|
986
|
+
new_recovery_account: accountName,
|
987
|
+
extensions: []
|
988
|
+
};
|
989
|
+
if (type === "ecency") {
|
990
|
+
return fetch(CONFIG.privateApiHost + "/private-api/recoveries-add", {
|
991
|
+
method: "POST",
|
992
|
+
body: JSON.stringify({
|
993
|
+
code: getAccessToken(data.name),
|
994
|
+
email,
|
995
|
+
publicKeys: [
|
996
|
+
...data.owner.key_auths,
|
997
|
+
...data.active.key_auths,
|
998
|
+
...data.posting.key_auths,
|
999
|
+
data.memo_key
|
1000
|
+
]
|
1001
|
+
})
|
1002
|
+
});
|
1003
|
+
} else if (type === "key" && key) {
|
1004
|
+
return CONFIG.hiveClient.broadcast.sendOperations(
|
1005
|
+
[["change_recovery_account", operationBody]],
|
1006
|
+
key
|
1007
|
+
);
|
1008
|
+
} else if (type === "keychain") {
|
1009
|
+
return keychain_exports.broadcast(
|
1010
|
+
data.name,
|
1011
|
+
[["change_recovery_account", operationBody]],
|
1012
|
+
"Active"
|
1013
|
+
);
|
1014
|
+
} else {
|
1015
|
+
const params = {
|
1016
|
+
callback: `https://ecency.com/@${data.name}/permissions`
|
1017
|
+
};
|
1018
|
+
return hs__default.default.sendOperation(
|
1019
|
+
["change_recovery_account", operationBody],
|
1020
|
+
params,
|
1021
|
+
() => {
|
1022
|
+
}
|
1023
|
+
);
|
1024
|
+
}
|
1025
|
+
},
|
1026
|
+
onError: options.onError,
|
1027
|
+
onSuccess: options.onSuccess
|
1028
|
+
});
|
1029
|
+
}
|
1030
|
+
function useAccountRevokeKey(username, options) {
|
1031
|
+
const { data: accountData } = reactQuery.useQuery(getAccountFullQueryOptions(username));
|
1032
|
+
return reactQuery.useMutation({
|
1033
|
+
mutationKey: ["accounts", "revoke-key", accountData?.name],
|
1034
|
+
mutationFn: async ({ currentKey, revokingKey }) => {
|
1035
|
+
if (!accountData) {
|
1036
|
+
throw new Error(
|
1037
|
+
"[SDK][Update password] \u2013 cannot update keys for anon user"
|
1038
|
+
);
|
1039
|
+
}
|
1040
|
+
const prepareAuth = (keyName) => {
|
1041
|
+
const auth = R__namespace.clone(accountData[keyName]);
|
1042
|
+
auth.key_auths = auth.key_auths.filter(
|
1043
|
+
([key]) => key !== revokingKey.toString()
|
1044
|
+
);
|
1045
|
+
return auth;
|
1046
|
+
};
|
1047
|
+
return CONFIG.hiveClient.broadcast.updateAccount(
|
1048
|
+
{
|
1049
|
+
account: accountData.name,
|
1050
|
+
json_metadata: accountData.json_metadata,
|
1051
|
+
owner: prepareAuth("owner"),
|
1052
|
+
active: prepareAuth("active"),
|
1053
|
+
posting: prepareAuth("posting"),
|
1054
|
+
memo_key: accountData.memo_key
|
1055
|
+
},
|
1056
|
+
currentKey
|
1057
|
+
);
|
1058
|
+
},
|
1059
|
+
...options
|
1060
|
+
});
|
1061
|
+
}
|
1062
|
+
function useSignOperationByKey(username) {
|
1063
|
+
return reactQuery.useMutation({
|
1064
|
+
mutationKey: ["operations", "sign", username],
|
1065
|
+
mutationFn: ({
|
1066
|
+
operation,
|
1067
|
+
keyOrSeed
|
1068
|
+
}) => {
|
1069
|
+
if (!username) {
|
1070
|
+
throw new Error("[Operations][Sign] \u2013 cannot sign op with anon user");
|
1071
|
+
}
|
1072
|
+
let privateKey;
|
1073
|
+
if (keyOrSeed.split(" ").length === 12) {
|
1074
|
+
privateKey = dhive.PrivateKey.fromLogin(username, keyOrSeed, "active");
|
1075
|
+
} else if (dhive.cryptoUtils.isWif(keyOrSeed)) {
|
1076
|
+
privateKey = dhive.PrivateKey.fromString(keyOrSeed);
|
1077
|
+
} else {
|
1078
|
+
privateKey = dhive.PrivateKey.from(keyOrSeed);
|
1079
|
+
}
|
1080
|
+
return CONFIG.hiveClient.broadcast.sendOperations(
|
1081
|
+
[operation],
|
1082
|
+
privateKey
|
1083
|
+
);
|
1084
|
+
}
|
1085
|
+
});
|
1086
|
+
}
|
1087
|
+
function useSignOperationByKeychain(username, keyType = "Active") {
|
1088
|
+
return reactQuery.useMutation({
|
1089
|
+
mutationKey: ["operations", "sign-keychain", username],
|
1090
|
+
mutationFn: ({ operation }) => {
|
1091
|
+
if (!username) {
|
1092
|
+
throw new Error(
|
1093
|
+
"[SDK][Keychain] \u2013\xA0cannot sign operation with anon user"
|
1094
|
+
);
|
1095
|
+
}
|
1096
|
+
return keychain_exports.broadcast(username, [operation], keyType);
|
1097
|
+
}
|
1098
|
+
});
|
1099
|
+
}
|
1100
|
+
function useSignOperationByHivesigner(callbackUri = "/") {
|
1101
|
+
return reactQuery.useMutation({
|
1102
|
+
mutationKey: ["operations", "sign-hivesigner", callbackUri],
|
1103
|
+
mutationFn: async ({ operation }) => {
|
1104
|
+
return hs__default.default.sendOperation(operation, { callback: callbackUri }, () => {
|
1105
|
+
});
|
1106
|
+
}
|
1107
|
+
});
|
1108
|
+
}
|
1109
|
+
function getChainPropertiesQueryOptions() {
|
1110
|
+
return reactQuery.queryOptions({
|
1111
|
+
queryKey: ["operations", "chain-properties"],
|
1112
|
+
queryFn: async () => {
|
1113
|
+
return await CONFIG.hiveClient.database.getChainProperties();
|
1114
|
+
}
|
1115
|
+
});
|
1116
|
+
}
|
1117
|
+
function getTrendingTagsQueryOptions(limit = 20) {
|
1118
|
+
return reactQuery.infiniteQueryOptions({
|
1119
|
+
queryKey: ["posts", "trending-tags"],
|
1120
|
+
queryFn: async ({ pageParam: { afterTag } }) => CONFIG.hiveClient.database.call("get_trending_tags", [afterTag, limit]).then(
|
1121
|
+
(tags) => tags.filter((x) => x.name !== "").filter((x) => !x.name.startsWith("hive-")).map((x) => x.name)
|
1122
|
+
),
|
1123
|
+
initialPageParam: { afterTag: "" },
|
1124
|
+
getNextPageParam: (lastPage) => ({
|
1125
|
+
afterTag: lastPage?.[lastPage?.length - 1]
|
1126
|
+
}),
|
1127
|
+
staleTime: Infinity,
|
1128
|
+
refetchOnMount: true
|
1129
|
+
});
|
1130
|
+
}
|
1131
|
+
function getFragmentsQueryOptions(username) {
|
1132
|
+
return reactQuery.queryOptions({
|
1133
|
+
queryKey: ["posts", "fragments", username],
|
1134
|
+
queryFn: async () => {
|
1135
|
+
const response = await fetch(
|
1136
|
+
CONFIG.privateApiHost + "/private-api/fragments",
|
1137
|
+
{
|
1138
|
+
method: "POST",
|
1139
|
+
body: JSON.stringify({
|
1140
|
+
code: getAccessToken(username)
|
1141
|
+
}),
|
1142
|
+
headers: {
|
1143
|
+
"Content-Type": "application/json"
|
1144
|
+
}
|
1145
|
+
}
|
1146
|
+
);
|
1147
|
+
return response.json();
|
1148
|
+
},
|
1149
|
+
enabled: !!username
|
1150
|
+
});
|
1151
|
+
}
|
1152
|
+
function getPromotedPostsQuery(type = "feed") {
|
1153
|
+
return reactQuery.queryOptions({
|
1154
|
+
queryKey: ["posts", "promoted", type],
|
1155
|
+
queryFn: async () => {
|
1156
|
+
const url = new URL(
|
1157
|
+
CONFIG.privateApiHost + "/private-api/promoted-entries"
|
1158
|
+
);
|
1159
|
+
if (type === "waves") {
|
1160
|
+
url.searchParams.append("short_content", "1");
|
1161
|
+
}
|
1162
|
+
const response = await fetch(url.toString(), {
|
1163
|
+
method: "GET",
|
1164
|
+
headers: {
|
1165
|
+
"Content-Type": "application/json"
|
1166
|
+
}
|
1167
|
+
});
|
1168
|
+
const data = await response.json();
|
1169
|
+
return data;
|
1170
|
+
}
|
1171
|
+
});
|
1172
|
+
}
|
1173
|
+
function useAddFragment(username) {
|
1174
|
+
return reactQuery.useMutation({
|
1175
|
+
mutationKey: ["posts", "add-fragment", username],
|
1176
|
+
mutationFn: async ({ title, body }) => {
|
1177
|
+
const response = await fetch(
|
1178
|
+
CONFIG.privateApiHost + "/private-api/fragments-add",
|
1179
|
+
{
|
1180
|
+
method: "POST",
|
1181
|
+
body: JSON.stringify({
|
1182
|
+
code: getAccessToken(username),
|
1183
|
+
title,
|
1184
|
+
body
|
1185
|
+
}),
|
1186
|
+
headers: {
|
1187
|
+
"Content-Type": "application/json"
|
1188
|
+
}
|
1189
|
+
}
|
1190
|
+
);
|
1191
|
+
return response.json();
|
1192
|
+
},
|
1193
|
+
onSuccess(response) {
|
1194
|
+
getQueryClient().setQueryData(
|
1195
|
+
getFragmentsQueryOptions(username).queryKey,
|
1196
|
+
(data) => [response, ...data ?? []]
|
1197
|
+
);
|
1198
|
+
}
|
1199
|
+
});
|
1200
|
+
}
|
1201
|
+
function useEditFragment(username, fragmentId) {
|
1202
|
+
return reactQuery.useMutation({
|
1203
|
+
mutationKey: ["posts", "edit-fragment", username, fragmentId],
|
1204
|
+
mutationFn: async ({ title, body }) => {
|
1205
|
+
const response = await fetch(
|
1206
|
+
CONFIG.privateApiHost + "/private-api/fragments-update",
|
1207
|
+
{
|
1208
|
+
method: "POST",
|
1209
|
+
body: JSON.stringify({
|
1210
|
+
code: getAccessToken(username),
|
1211
|
+
id: fragmentId,
|
1212
|
+
title,
|
1213
|
+
body
|
1214
|
+
}),
|
1215
|
+
headers: {
|
1216
|
+
"Content-Type": "application/json"
|
1217
|
+
}
|
1218
|
+
}
|
1219
|
+
);
|
1220
|
+
return response.json();
|
1221
|
+
},
|
1222
|
+
onSuccess(response) {
|
1223
|
+
getQueryClient().setQueryData(
|
1224
|
+
getFragmentsQueryOptions(username).queryKey,
|
1225
|
+
(data) => {
|
1226
|
+
if (!data) {
|
1227
|
+
return [];
|
1228
|
+
}
|
1229
|
+
const index = data.findIndex(({ id }) => id === fragmentId);
|
1230
|
+
if (index >= 0) {
|
1231
|
+
data[index] = response;
|
1232
|
+
}
|
1233
|
+
return [...data];
|
1234
|
+
}
|
1235
|
+
);
|
1236
|
+
}
|
1237
|
+
});
|
1238
|
+
}
|
1239
|
+
function useRemoveFragment(username, fragmentId) {
|
1240
|
+
return reactQuery.useMutation({
|
1241
|
+
mutationKey: ["posts", "remove-fragment", username],
|
1242
|
+
mutationFn: async () => fetch(CONFIG.privateApiHost + "/private-api/fragments-delete", {
|
1243
|
+
method: "POST",
|
1244
|
+
body: JSON.stringify({
|
1245
|
+
code: getAccessToken(username),
|
1246
|
+
id: fragmentId
|
1247
|
+
}),
|
1248
|
+
headers: {
|
1249
|
+
"Content-Type": "application/json"
|
1250
|
+
}
|
1251
|
+
}),
|
1252
|
+
onSuccess() {
|
1253
|
+
getQueryClient().setQueryData(
|
1254
|
+
getFragmentsQueryOptions(username).queryKey,
|
1255
|
+
(data) => [...data ?? []].filter(({ id }) => id !== fragmentId)
|
1256
|
+
);
|
1257
|
+
}
|
1258
|
+
});
|
1259
|
+
}
|
1260
|
+
|
1261
|
+
// src/modules/analytics/mutations/index.ts
|
1262
|
+
var mutations_exports = {};
|
1263
|
+
__export(mutations_exports, {
|
1264
|
+
useRecordActivity: () => useRecordActivity
|
1265
|
+
});
|
1266
|
+
function useRecordActivity(username, activityType) {
|
1267
|
+
return reactQuery.useMutation({
|
1268
|
+
mutationKey: ["analytics", activityType],
|
1269
|
+
mutationFn: async () => {
|
1270
|
+
if (!activityType) {
|
1271
|
+
throw new Error("[SDK][Analytics] \u2013 no activity type provided");
|
1272
|
+
}
|
1273
|
+
await fetch(CONFIG.plausibleHost + "/api/event", {
|
1274
|
+
method: "POST",
|
1275
|
+
headers: {
|
1276
|
+
"Content-Type": "application/json"
|
1277
|
+
},
|
1278
|
+
body: JSON.stringify({
|
1279
|
+
name: activityType,
|
1280
|
+
url: window.location.href,
|
1281
|
+
domain: window.location.host,
|
1282
|
+
props: {
|
1283
|
+
username
|
1284
|
+
}
|
1285
|
+
})
|
1286
|
+
});
|
1287
|
+
}
|
1288
|
+
});
|
1289
|
+
}
|
1290
|
+
|
1291
|
+
// src/modules/integrations/3speak/queries/index.ts
|
1292
|
+
var queries_exports2 = {};
|
1293
|
+
__export(queries_exports2, {
|
1294
|
+
getAccountTokenQueryOptions: () => getAccountTokenQueryOptions,
|
1295
|
+
getAccountVideosQueryOptions: () => getAccountVideosQueryOptions
|
1296
|
+
});
|
1297
|
+
|
1298
|
+
// src/modules/integrations/hivesigner/queries/index.ts
|
1299
|
+
var queries_exports = {};
|
1300
|
+
__export(queries_exports, {
|
1301
|
+
getDecodeMemoQueryOptions: () => getDecodeMemoQueryOptions
|
1302
|
+
});
|
1303
|
+
function getDecodeMemoQueryOptions(username, memo) {
|
1304
|
+
return reactQuery.queryOptions({
|
1305
|
+
queryKey: ["integrations", "hivesigner", "decode-memo", username],
|
1306
|
+
queryFn: async () => {
|
1307
|
+
const accessToken = getAccessToken(username);
|
1308
|
+
if (accessToken) {
|
1309
|
+
const hsClient = new hs__default.default.Client({
|
1310
|
+
accessToken
|
1311
|
+
});
|
1312
|
+
return hsClient.decode(memo);
|
1313
|
+
}
|
1314
|
+
}
|
1315
|
+
});
|
1316
|
+
}
|
1317
|
+
|
1318
|
+
// src/modules/integrations/hivesigner/index.ts
|
1319
|
+
var HiveSignerIntegration = {
|
1320
|
+
queries: queries_exports
|
1321
|
+
};
|
1322
|
+
|
1323
|
+
// src/modules/integrations/3speak/queries/get-account-token-query-options.ts
|
1324
|
+
function getAccountTokenQueryOptions(username) {
|
1325
|
+
return reactQuery.queryOptions({
|
1326
|
+
queryKey: ["integrations", "3speak", "authenticate", username],
|
1327
|
+
enabled: !!username,
|
1328
|
+
queryFn: async () => {
|
1329
|
+
if (!username) {
|
1330
|
+
throw new Error("[SDK][Integrations][3Speak] \u2013\xA0anon user");
|
1331
|
+
}
|
1332
|
+
const response = await fetch(
|
1333
|
+
`https://studio.3speak.tv/mobile/login?username=${username}&hivesigner=true`,
|
1334
|
+
{
|
1335
|
+
headers: {
|
1336
|
+
"Content-Type": "application/json"
|
1337
|
+
}
|
1338
|
+
}
|
1339
|
+
);
|
1340
|
+
const memoQueryOptions = HiveSignerIntegration.queries.getDecodeMemoQueryOptions(
|
1341
|
+
username,
|
1342
|
+
(await response.json()).memo
|
1343
|
+
);
|
1344
|
+
await getQueryClient().prefetchQuery(memoQueryOptions);
|
1345
|
+
const { memoDecoded } = getQueryClient().getQueryData(
|
1346
|
+
memoQueryOptions.queryKey
|
1347
|
+
);
|
1348
|
+
return memoDecoded.replace("#", "");
|
1349
|
+
}
|
1350
|
+
});
|
1351
|
+
}
|
1352
|
+
function getAccountVideosQueryOptions(username) {
|
1353
|
+
return reactQuery.queryOptions({
|
1354
|
+
queryKey: ["integrations", "3speak", "videos", username],
|
1355
|
+
enabled: !!username,
|
1356
|
+
queryFn: async () => {
|
1357
|
+
await getQueryClient().prefetchQuery(
|
1358
|
+
getAccountTokenQueryOptions(username)
|
1359
|
+
);
|
1360
|
+
const token = getQueryClient().getQueryData(
|
1361
|
+
getAccountTokenQueryOptions(username).queryKey
|
1362
|
+
);
|
1363
|
+
const response = await fetch(
|
1364
|
+
`https://studio.3speak.tv/mobile/api/my-videos`,
|
1365
|
+
{
|
1366
|
+
headers: {
|
1367
|
+
"Content-Type": "application/json",
|
1368
|
+
Authorization: `Bearer ${token}`
|
1369
|
+
}
|
1370
|
+
}
|
1371
|
+
);
|
1372
|
+
return await response.json();
|
1373
|
+
}
|
1374
|
+
});
|
1375
|
+
}
|
1376
|
+
|
1377
|
+
// src/modules/integrations/3speak/index.ts
|
1378
|
+
var ThreeSpeakIntegration = {
|
1379
|
+
queries: queries_exports2
|
1380
|
+
};
|
1381
|
+
function getHivePoshLinksQueryOptions(username) {
|
1382
|
+
return reactQuery.queryOptions({
|
1383
|
+
queryKey: ["integrations", "hiveposh", "links", username],
|
1384
|
+
queryFn: async () => {
|
1385
|
+
const response = await fetch(
|
1386
|
+
`https://hiveposh.com/api/v0/linked-accounts/${username}`,
|
1387
|
+
{
|
1388
|
+
headers: {
|
1389
|
+
"Content-Type": "application/json"
|
1390
|
+
}
|
1391
|
+
}
|
1392
|
+
);
|
1393
|
+
const data = await response.json();
|
1394
|
+
return {
|
1395
|
+
twitter: {
|
1396
|
+
username: data.twitter_username,
|
1397
|
+
profile: data.twitter_profile
|
1398
|
+
},
|
1399
|
+
reddit: {
|
1400
|
+
username: data.reddit_username,
|
1401
|
+
profile: data.reddit_profile
|
1402
|
+
}
|
1403
|
+
};
|
1404
|
+
}
|
1405
|
+
});
|
1406
|
+
}
|
1407
|
+
function getStatsQueryOptions({
|
1408
|
+
url,
|
1409
|
+
dimensions = [],
|
1410
|
+
metrics = ["visitors", "pageviews", "visit_duration"],
|
1411
|
+
enabled = true
|
1412
|
+
}) {
|
1413
|
+
return reactQuery.queryOptions({
|
1414
|
+
queryKey: ["integrations", "plausible", url, dimensions, metrics],
|
1415
|
+
queryFn: async () => {
|
1416
|
+
const response = await fetch(`https://ecency.com/api/stats`, {
|
1417
|
+
method: "POST",
|
1418
|
+
body: JSON.stringify({
|
1419
|
+
metrics,
|
1420
|
+
url: encodeURIComponent(url),
|
1421
|
+
dimensions
|
1422
|
+
}),
|
1423
|
+
headers: {
|
1424
|
+
"Content-Type": "application/json"
|
1425
|
+
}
|
1426
|
+
});
|
1427
|
+
return await response.json();
|
1428
|
+
},
|
1429
|
+
enabled: !!url && enabled
|
1430
|
+
});
|
1431
|
+
}
|
1432
|
+
function getRcStatsQueryOptions() {
|
1433
|
+
return reactQuery.queryOptions({
|
1434
|
+
queryKey: ["resource-credits", "stats"],
|
1435
|
+
queryFn: async () => {
|
1436
|
+
const response = await CONFIG.hiveClient.call(
|
1437
|
+
"rc_api",
|
1438
|
+
"get_rc_stats",
|
1439
|
+
{}
|
1440
|
+
);
|
1441
|
+
return response.rc_stats;
|
1442
|
+
}
|
1443
|
+
});
|
1444
|
+
}
|
1445
|
+
function getAccountRcQueryOptions(username) {
|
1446
|
+
return reactQuery.queryOptions({
|
1447
|
+
queryKey: ["resource-credits", "account", username],
|
1448
|
+
queryFn: async () => {
|
1449
|
+
const rcClient = new dhive.RCAPI(CONFIG.hiveClient);
|
1450
|
+
return rcClient.findRCAccounts([username]);
|
1451
|
+
},
|
1452
|
+
enabled: !!username
|
1453
|
+
});
|
1454
|
+
}
|
1455
|
+
function getGameStatusCheckQueryOptions(username, gameType) {
|
1456
|
+
return reactQuery.queryOptions({
|
1457
|
+
queryKey: ["games", "status-check", gameType, username],
|
1458
|
+
enabled: !!username,
|
1459
|
+
queryFn: async () => {
|
1460
|
+
if (!username) {
|
1461
|
+
throw new Error("[SDK][Games] \u2013 anon user in status check");
|
1462
|
+
}
|
1463
|
+
const response = await fetch(
|
1464
|
+
CONFIG.privateApiHost + "/private-api/get-game",
|
1465
|
+
{
|
1466
|
+
method: "POST",
|
1467
|
+
body: JSON.stringify({
|
1468
|
+
game_type: gameType,
|
1469
|
+
code: getAccessToken(username)
|
1470
|
+
}),
|
1471
|
+
headers: {
|
1472
|
+
"Content-Type": "application/json"
|
1473
|
+
}
|
1474
|
+
}
|
1475
|
+
);
|
1476
|
+
return await response.json();
|
1477
|
+
}
|
1478
|
+
});
|
1479
|
+
}
|
1480
|
+
function useGameClaim(username, gameType, key) {
|
1481
|
+
const { mutateAsync: recordActivity } = useRecordActivity(
|
1482
|
+
username,
|
1483
|
+
"spin-rolled"
|
1484
|
+
);
|
1485
|
+
return reactQuery.useMutation({
|
1486
|
+
mutationKey: ["games", "post", gameType, username],
|
1487
|
+
mutationFn: async () => {
|
1488
|
+
if (!username) {
|
1489
|
+
throw new Error("[SDK][Games] \u2013 anon user in game post");
|
1490
|
+
}
|
1491
|
+
const response = await fetch(
|
1492
|
+
CONFIG.privateApiHost + "/private-api/post-game",
|
1493
|
+
{
|
1494
|
+
method: "POST",
|
1495
|
+
body: JSON.stringify({
|
1496
|
+
game_type: gameType,
|
1497
|
+
code: getAccessToken(username),
|
1498
|
+
key
|
1499
|
+
}),
|
1500
|
+
headers: {
|
1501
|
+
"Content-Type": "application/json"
|
1502
|
+
}
|
1503
|
+
}
|
1504
|
+
);
|
1505
|
+
return await response.json();
|
1506
|
+
},
|
1507
|
+
onSuccess() {
|
1508
|
+
recordActivity();
|
1509
|
+
}
|
1510
|
+
});
|
1511
|
+
}
|
1512
|
+
function getCommunitiesQueryOptions(sort, query, limit = 100, observer = void 0, enabled = true) {
|
1513
|
+
return reactQuery.queryOptions({
|
1514
|
+
queryKey: ["communities", "list", sort, query, limit],
|
1515
|
+
enabled,
|
1516
|
+
queryFn: async () => {
|
1517
|
+
const response = await CONFIG.hiveClient.call(
|
1518
|
+
"bridge",
|
1519
|
+
"list_communities",
|
1520
|
+
{
|
1521
|
+
last: "",
|
1522
|
+
limit,
|
1523
|
+
sort: sort === "hot" ? "rank" : sort,
|
1524
|
+
query: query ? query : null,
|
1525
|
+
observer
|
1526
|
+
}
|
1527
|
+
);
|
1528
|
+
return response ? sort === "hot" ? response.sort(() => Math.random() - 0.5) : response : [];
|
1529
|
+
}
|
1530
|
+
});
|
1531
|
+
}
|
1532
|
+
function getCommunityContextQueryOptions(username, communityName) {
|
1533
|
+
return reactQuery.queryOptions({
|
1534
|
+
queryKey: ["community", "context", username, communityName],
|
1535
|
+
enabled: !!username && !!communityName,
|
1536
|
+
queryFn: async () => {
|
1537
|
+
const response = await CONFIG.hiveClient.call(
|
1538
|
+
"bridge",
|
1539
|
+
"get_community_context",
|
1540
|
+
{
|
1541
|
+
account: username,
|
1542
|
+
name: communityName
|
1543
|
+
}
|
1544
|
+
);
|
1545
|
+
return {
|
1546
|
+
role: response?.role ?? "guest",
|
1547
|
+
subscribed: response?.subscribed ?? false
|
1548
|
+
};
|
1549
|
+
}
|
1550
|
+
});
|
1551
|
+
}
|
1552
|
+
|
1553
|
+
// src/modules/communities/types/community.ts
|
1554
|
+
var ROLES = /* @__PURE__ */ ((ROLES2) => {
|
1555
|
+
ROLES2["OWNER"] = "owner";
|
1556
|
+
ROLES2["ADMIN"] = "admin";
|
1557
|
+
ROLES2["MOD"] = "mod";
|
1558
|
+
ROLES2["MEMBER"] = "member";
|
1559
|
+
ROLES2["GUEST"] = "guest";
|
1560
|
+
ROLES2["MUTED"] = "muted";
|
1561
|
+
return ROLES2;
|
1562
|
+
})(ROLES || {});
|
1563
|
+
var roleMap = {
|
1564
|
+
["owner" /* OWNER */]: [
|
1565
|
+
"admin" /* ADMIN */,
|
1566
|
+
"mod" /* MOD */,
|
1567
|
+
"member" /* MEMBER */,
|
1568
|
+
"guest" /* GUEST */,
|
1569
|
+
"muted" /* MUTED */
|
1570
|
+
],
|
1571
|
+
["admin" /* ADMIN */]: ["mod" /* MOD */, "member" /* MEMBER */, "guest" /* GUEST */, "muted" /* MUTED */],
|
1572
|
+
["mod" /* MOD */]: ["member" /* MEMBER */, "guest" /* GUEST */, "muted" /* MUTED */]
|
1573
|
+
};
|
1574
|
+
|
1575
|
+
// src/modules/communities/utils/index.ts
|
1576
|
+
function getCommunityType(name, type_id) {
|
1577
|
+
if (name.startsWith("hive-3") || type_id === 3) return "Council";
|
1578
|
+
if (name.startsWith("hive-2") || type_id === 2) return "Journal";
|
1579
|
+
return "Topic";
|
1580
|
+
}
|
1581
|
+
function getCommunityPermissions({
|
1582
|
+
communityType,
|
1583
|
+
userRole,
|
1584
|
+
subscribed
|
1585
|
+
}) {
|
1586
|
+
const canPost = (() => {
|
1587
|
+
if (userRole === "muted" /* MUTED */) return false;
|
1588
|
+
if (communityType === "Topic") return true;
|
1589
|
+
return ["owner" /* OWNER */, "admin" /* ADMIN */, "mod" /* MOD */, "member" /* MEMBER */].includes(
|
1590
|
+
userRole
|
1591
|
+
);
|
1592
|
+
})();
|
1593
|
+
const canComment = (() => {
|
1594
|
+
if (userRole === "muted" /* MUTED */) return false;
|
1595
|
+
switch (communityType) {
|
1596
|
+
case "Topic":
|
1597
|
+
return true;
|
1598
|
+
case "Journal":
|
1599
|
+
return userRole !== "guest" /* GUEST */ || subscribed;
|
1600
|
+
case "Council":
|
1601
|
+
return canPost;
|
1602
|
+
}
|
1603
|
+
})();
|
1604
|
+
const isModerator = ["owner" /* OWNER */, "admin" /* ADMIN */, "mod" /* MOD */].includes(userRole);
|
1605
|
+
return {
|
1606
|
+
canPost,
|
1607
|
+
canComment,
|
1608
|
+
isModerator
|
1609
|
+
};
|
1610
|
+
}
|
1611
|
+
|
1612
|
+
exports.CONFIG = CONFIG;
|
1613
|
+
exports.EcencyAnalytics = mutations_exports;
|
1614
|
+
exports.HiveSignerIntegration = HiveSignerIntegration;
|
1615
|
+
exports.Keychain = keychain_exports;
|
1616
|
+
exports.ROLES = ROLES;
|
1617
|
+
exports.ThreeSpeakIntegration = ThreeSpeakIntegration;
|
1618
|
+
exports.broadcastJson = broadcastJson;
|
1619
|
+
exports.checkUsernameWalletsPendingQueryOptions = checkUsernameWalletsPendingQueryOptions;
|
1620
|
+
exports.dedupeAndSortKeyAuths = dedupeAndSortKeyAuths;
|
1621
|
+
exports.getAccessToken = getAccessToken;
|
1622
|
+
exports.getAccountFullQueryOptions = getAccountFullQueryOptions;
|
1623
|
+
exports.getAccountPendingRecoveryQueryOptions = getAccountPendingRecoveryQueryOptions;
|
1624
|
+
exports.getAccountRcQueryOptions = getAccountRcQueryOptions;
|
1625
|
+
exports.getAccountRecoveriesQueryOptions = getAccountRecoveriesQueryOptions;
|
1626
|
+
exports.getAccountSubscriptionsQueryOptions = getAccountSubscriptionsQueryOptions;
|
1627
|
+
exports.getActiveAccountBookmarksQueryOptions = getActiveAccountBookmarksQueryOptions;
|
1628
|
+
exports.getActiveAccountFavouritesQueryOptions = getActiveAccountFavouritesQueryOptions;
|
1629
|
+
exports.getChainPropertiesQueryOptions = getChainPropertiesQueryOptions;
|
1630
|
+
exports.getCommunitiesQueryOptions = getCommunitiesQueryOptions;
|
1631
|
+
exports.getCommunityContextQueryOptions = getCommunityContextQueryOptions;
|
1632
|
+
exports.getCommunityPermissions = getCommunityPermissions;
|
1633
|
+
exports.getCommunityType = getCommunityType;
|
1634
|
+
exports.getDynamicPropsQueryOptions = getDynamicPropsQueryOptions;
|
1635
|
+
exports.getFragmentsQueryOptions = getFragmentsQueryOptions;
|
1636
|
+
exports.getGameStatusCheckQueryOptions = getGameStatusCheckQueryOptions;
|
1637
|
+
exports.getHivePoshLinksQueryOptions = getHivePoshLinksQueryOptions;
|
1638
|
+
exports.getLoginType = getLoginType;
|
1639
|
+
exports.getPostingKey = getPostingKey;
|
1640
|
+
exports.getPromotedPostsQuery = getPromotedPostsQuery;
|
1641
|
+
exports.getQueryClient = getQueryClient;
|
1642
|
+
exports.getRcStatsQueryOptions = getRcStatsQueryOptions;
|
1643
|
+
exports.getRefreshToken = getRefreshToken;
|
1644
|
+
exports.getRelationshipBetweenAccountsQueryOptions = getRelationshipBetweenAccountsQueryOptions;
|
1645
|
+
exports.getSearchAccountsByUsernameQueryOptions = getSearchAccountsByUsernameQueryOptions;
|
1646
|
+
exports.getStatsQueryOptions = getStatsQueryOptions;
|
1647
|
+
exports.getTrendingTagsQueryOptions = getTrendingTagsQueryOptions;
|
1648
|
+
exports.getUser = getUser;
|
1649
|
+
exports.makeQueryClient = makeQueryClient;
|
1650
|
+
exports.roleMap = roleMap;
|
1651
|
+
exports.useAccountFavouriteAdd = useAccountFavouriteAdd;
|
1652
|
+
exports.useAccountFavouriteDelete = useAccountFavouriteDelete;
|
1653
|
+
exports.useAccountRelationsUpdate = useAccountRelationsUpdate;
|
1654
|
+
exports.useAccountRevokeKey = useAccountRevokeKey;
|
1655
|
+
exports.useAccountRevokePosting = useAccountRevokePosting;
|
1656
|
+
exports.useAccountUpdate = useAccountUpdate;
|
1657
|
+
exports.useAccountUpdateKeyAuths = useAccountUpdateKeyAuths;
|
1658
|
+
exports.useAccountUpdatePassword = useAccountUpdatePassword;
|
1659
|
+
exports.useAccountUpdateRecovery = useAccountUpdateRecovery;
|
1660
|
+
exports.useAddFragment = useAddFragment;
|
1661
|
+
exports.useBookmarkAdd = useBookmarkAdd;
|
1662
|
+
exports.useBookmarkDelete = useBookmarkDelete;
|
1663
|
+
exports.useBroadcastMutation = useBroadcastMutation;
|
1664
|
+
exports.useEditFragment = useEditFragment;
|
1665
|
+
exports.useGameClaim = useGameClaim;
|
1666
|
+
exports.useRemoveFragment = useRemoveFragment;
|
1667
|
+
exports.useSignOperationByHivesigner = useSignOperationByHivesigner;
|
1668
|
+
exports.useSignOperationByKey = useSignOperationByKey;
|
1669
|
+
exports.useSignOperationByKeychain = useSignOperationByKeychain;
|
1670
|
+
//# sourceMappingURL=index.cjs.map
|
1671
|
+
//# sourceMappingURL=index.cjs.map
|