@ecency/sdk 1.0.30 → 1.0.31
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/ecency-sdk.es.js +81 -66
- package/dist/index.d.ts +1 -0
- package/package.json +1 -1
package/dist/ecency-sdk.es.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
var
|
2
|
-
var
|
3
|
-
var g = (e, t, n) =>
|
4
|
-
import { QueryClient as v, useMutation as
|
1
|
+
var Q = Object.defineProperty;
|
2
|
+
var K = (e, t, n) => t in e ? Q(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
3
|
+
var g = (e, t, n) => K(e, typeof t != "symbol" ? t + "" : t, n);
|
4
|
+
import { QueryClient as v, useMutation as f, useQuery as q, useInfiniteQuery as O, queryOptions as l, infiniteQueryOptions as _ } from "@tanstack/react-query";
|
5
5
|
import { Client as k, PrivateKey as p, cryptoUtils as S } from "@hiveio/dhive";
|
6
|
-
import
|
7
|
-
class
|
6
|
+
import m from "hivesigner";
|
7
|
+
class b {
|
8
8
|
constructor() {
|
9
9
|
g(this, "length", 0);
|
10
10
|
}
|
@@ -26,7 +26,7 @@ class _ {
|
|
26
26
|
}
|
27
27
|
const a = {
|
28
28
|
privateApiHost: "https://ecency.com",
|
29
|
-
storage: typeof window > "u" ? new
|
29
|
+
storage: typeof window > "u" ? new b() : window.localStorage,
|
30
30
|
storagePrefix: "ecency",
|
31
31
|
hiveClient: new k(
|
32
32
|
[
|
@@ -58,7 +58,7 @@ var d;
|
|
58
58
|
}
|
59
59
|
e.setQueryClient = t;
|
60
60
|
})(d || (d = {}));
|
61
|
-
function
|
61
|
+
function I(e) {
|
62
62
|
let t = atob(e);
|
63
63
|
if (t[0] === "{")
|
64
64
|
return JSON.parse(t);
|
@@ -68,16 +68,16 @@ const y = (e) => {
|
|
68
68
|
const t = a.storage.getItem(
|
69
69
|
a.storagePrefix + "_user_" + e
|
70
70
|
);
|
71
|
-
return
|
71
|
+
return I(JSON.parse(t));
|
72
72
|
} catch (t) {
|
73
73
|
console.error(t);
|
74
74
|
return;
|
75
75
|
}
|
76
|
-
},
|
76
|
+
}, T = (e) => y(e) && y(e).accessToken, A = (e) => y(e) && y(e).postingKey, x = (e) => y(e) && y(e).refreshToken;
|
77
77
|
function D(e = [], t, n) {
|
78
|
-
return
|
78
|
+
return f({
|
79
79
|
mutationKey: [...e, t],
|
80
|
-
mutationFn: async (
|
80
|
+
mutationFn: async (r) => {
|
81
81
|
if (!t)
|
82
82
|
throw new Error(
|
83
83
|
"[Core][Broadcast] Attempted to call broadcast API with anon user"
|
@@ -86,15 +86,15 @@ function D(e = [], t, n) {
|
|
86
86
|
if (o) {
|
87
87
|
const c = p.fromString(o);
|
88
88
|
return a.hiveClient.broadcast.sendOperations(
|
89
|
-
n(
|
89
|
+
n(r),
|
90
90
|
c
|
91
91
|
);
|
92
92
|
}
|
93
|
-
let s =
|
93
|
+
let s = T(t);
|
94
94
|
if (s)
|
95
|
-
return (await new
|
95
|
+
return (await new m.Client({
|
96
96
|
accessToken: s
|
97
|
-
}).broadcast(n(
|
97
|
+
}).broadcast(n(r))).result;
|
98
98
|
throw new Error(
|
99
99
|
"[SDK][Broadcast] – cannot broadcast w/o posting key or token"
|
100
100
|
);
|
@@ -117,37 +117,37 @@ function H() {
|
|
117
117
|
const u = () => a.queryClient;
|
118
118
|
var w;
|
119
119
|
((e) => {
|
120
|
-
function t(
|
121
|
-
return u().getQueryData(
|
120
|
+
function t(i) {
|
121
|
+
return u().getQueryData(i);
|
122
122
|
}
|
123
123
|
e.getQueryData = t;
|
124
|
-
function n(
|
125
|
-
return u().getQueryData(
|
124
|
+
function n(i) {
|
125
|
+
return u().getQueryData(i);
|
126
126
|
}
|
127
127
|
e.getInfiniteQueryData = n;
|
128
|
-
async function i
|
129
|
-
return await u().prefetchQuery(
|
128
|
+
async function r(i) {
|
129
|
+
return await u().prefetchQuery(i), t(i.queryKey);
|
130
130
|
}
|
131
|
-
e.prefetchQuery =
|
132
|
-
async function o(
|
133
|
-
return await u().prefetchInfiniteQuery(
|
131
|
+
e.prefetchQuery = r;
|
132
|
+
async function o(i) {
|
133
|
+
return await u().prefetchInfiniteQuery(i), n(i.queryKey);
|
134
134
|
}
|
135
135
|
e.prefetchInfiniteQuery = o;
|
136
|
-
function s(
|
136
|
+
function s(i) {
|
137
137
|
return {
|
138
|
-
prefetch: () => i
|
139
|
-
getData: () => t(
|
140
|
-
useClientQuery: () => q(
|
141
|
-
fetchAndGet: () => u().fetchQuery(
|
138
|
+
prefetch: () => r(i),
|
139
|
+
getData: () => t(i.queryKey),
|
140
|
+
useClientQuery: () => q(i),
|
141
|
+
fetchAndGet: () => u().fetchQuery(i)
|
142
142
|
};
|
143
143
|
}
|
144
144
|
e.generateClientServerQuery = s;
|
145
|
-
function c(
|
145
|
+
function c(i) {
|
146
146
|
return {
|
147
|
-
prefetch: () => o(
|
148
|
-
getData: () => n(
|
149
|
-
useClientQuery: () => O(
|
150
|
-
fetchAndGet: () => u().fetchInfiniteQuery(
|
147
|
+
prefetch: () => o(i),
|
148
|
+
getData: () => n(i.queryKey),
|
149
|
+
useClientQuery: () => O(i),
|
150
|
+
fetchAndGet: () => u().fetchInfiniteQuery(i)
|
151
151
|
};
|
152
152
|
}
|
153
153
|
e.generateClientServerInfiniteQuery = c;
|
@@ -175,8 +175,8 @@ function J(e) {
|
|
175
175
|
]
|
176
176
|
);
|
177
177
|
}
|
178
|
-
function
|
179
|
-
return
|
178
|
+
function E(e) {
|
179
|
+
return l({
|
180
180
|
queryKey: ["get-account-full", e],
|
181
181
|
queryFn: async () => {
|
182
182
|
if (!e)
|
@@ -185,9 +185,9 @@ function x(e) {
|
|
185
185
|
if (!t[0])
|
186
186
|
throw new Error("[SDK] No account with given username");
|
187
187
|
const n = JSON.parse(t[0].posting_json_metadata).profile;
|
188
|
-
let
|
188
|
+
let r;
|
189
189
|
try {
|
190
|
-
|
190
|
+
r = await a.hiveClient.database.call(
|
191
191
|
"get_follow_count",
|
192
192
|
[e]
|
193
193
|
);
|
@@ -200,7 +200,7 @@ function x(e) {
|
|
200
200
|
);
|
201
201
|
return {
|
202
202
|
...t,
|
203
|
-
follow_stats:
|
203
|
+
follow_stats: r,
|
204
204
|
reputation: o[0].reputation,
|
205
205
|
profile: {
|
206
206
|
...n,
|
@@ -212,8 +212,8 @@ function x(e) {
|
|
212
212
|
staleTime: 6e4
|
213
213
|
});
|
214
214
|
}
|
215
|
-
function
|
216
|
-
return
|
215
|
+
function M(e, t = 5, n = []) {
|
216
|
+
return l({
|
217
217
|
queryKey: ["accounts", "search", e, n],
|
218
218
|
enabled: !!e,
|
219
219
|
queryFn: async () => (await a.hiveClient.database.call(
|
@@ -225,7 +225,7 @@ function E(e, t = 5, n = []) {
|
|
225
225
|
});
|
226
226
|
}
|
227
227
|
function U(e) {
|
228
|
-
return
|
228
|
+
return f({
|
229
229
|
mutationKey: ["operations", "sign", e],
|
230
230
|
mutationFn: ({
|
231
231
|
operation: t,
|
@@ -233,10 +233,10 @@ function U(e) {
|
|
233
233
|
}) => {
|
234
234
|
if (!e)
|
235
235
|
throw new Error("[Operations][Sign] – cannot sign op with anon user");
|
236
|
-
let
|
237
|
-
return n.split(" ").length === 12 ?
|
236
|
+
let r;
|
237
|
+
return n.split(" ").length === 12 ? r = p.fromLogin(e, n, "active") : S.isWif(n) ? r = p.fromString(n) : r = p.from(n), a.hiveClient.broadcast.sendOperations(
|
238
238
|
[t],
|
239
|
-
|
239
|
+
r
|
240
240
|
);
|
241
241
|
}
|
242
242
|
});
|
@@ -249,43 +249,43 @@ function F() {
|
|
249
249
|
});
|
250
250
|
});
|
251
251
|
}
|
252
|
-
const
|
252
|
+
const C = (e, t, n, r = null) => new Promise((o, s) => {
|
253
253
|
var c;
|
254
254
|
(c = window.hive_keychain) == null || c.requestBroadcast(
|
255
255
|
e,
|
256
256
|
t,
|
257
257
|
n,
|
258
|
-
(
|
259
|
-
|
258
|
+
(i) => {
|
259
|
+
i.success || s({ message: "Operation cancelled" }), o(i);
|
260
260
|
},
|
261
|
-
|
261
|
+
r
|
262
262
|
);
|
263
263
|
}), G = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
264
264
|
__proto__: null,
|
265
|
-
broadcast:
|
265
|
+
broadcast: C,
|
266
266
|
handshake: F
|
267
267
|
}, Symbol.toStringTag, { value: "Module" }));
|
268
|
-
function
|
269
|
-
return
|
268
|
+
function W(e, t = "Active") {
|
269
|
+
return f({
|
270
270
|
mutationKey: ["operations", "sign-keychain", e],
|
271
271
|
mutationFn: ({ operation: n }) => {
|
272
272
|
if (!e)
|
273
273
|
throw new Error(
|
274
274
|
"[SDK][Keychain] – cannot sign operation with anon user"
|
275
275
|
);
|
276
|
-
return
|
276
|
+
return C(e, [n], t);
|
277
277
|
}
|
278
278
|
});
|
279
279
|
}
|
280
|
-
function
|
281
|
-
return
|
280
|
+
function z(e = "/") {
|
281
|
+
return f({
|
282
282
|
mutationKey: ["operations", "sign-hivesigner", e],
|
283
|
-
mutationFn: async ({ operation: t }) =>
|
283
|
+
mutationFn: async ({ operation: t }) => m.sendOperation(t, { callback: e }, () => {
|
284
284
|
})
|
285
285
|
});
|
286
286
|
}
|
287
|
-
function
|
288
|
-
return
|
287
|
+
function R(e, t) {
|
288
|
+
return l({
|
289
289
|
queryKey: ["hive-engine", "tokens-list", e, t],
|
290
290
|
queryFn: async () => (await (await fetch(
|
291
291
|
`${a.privateApiHost}/private-api/engine-api`,
|
@@ -309,23 +309,38 @@ function z(e, t) {
|
|
309
309
|
)).json()).result
|
310
310
|
});
|
311
311
|
}
|
312
|
+
function $(e = 20) {
|
313
|
+
return _({
|
314
|
+
queryKey: ["posts", "trending-tags"],
|
315
|
+
queryFn: async ({ pageParam: { afterTag: t } }) => a.hiveClient.database.call("get_trending_tags", [t, e]).then(
|
316
|
+
(n) => n.filter((r) => r.name !== "").filter((r) => !r.name.startsWith("hive-")).map((r) => r.name)
|
317
|
+
),
|
318
|
+
initialPageParam: { afterTag: "" },
|
319
|
+
getNextPageParam: (t) => ({
|
320
|
+
afterTag: t == null ? void 0 : t[(t == null ? void 0 : t.length) - 1]
|
321
|
+
}),
|
322
|
+
staleTime: 1 / 0,
|
323
|
+
refetchOnMount: !0
|
324
|
+
});
|
325
|
+
}
|
312
326
|
export {
|
313
327
|
a as CONFIG,
|
314
328
|
d as ConfigManager,
|
315
329
|
w as EcencyQueriesManager,
|
316
330
|
G as Keychain,
|
317
|
-
|
318
|
-
|
319
|
-
|
331
|
+
T as getAccessToken,
|
332
|
+
E as getAccountFullQueryOptions,
|
333
|
+
R as getHiveEngineTokensListQueryOptions,
|
320
334
|
A as getPostingKey,
|
321
335
|
u as getQueryClient,
|
322
|
-
|
323
|
-
|
336
|
+
x as getRefreshToken,
|
337
|
+
M as getSearchAccountsByUsernameQueryOptions,
|
338
|
+
$ as getTrendingTagsQueryOptions,
|
324
339
|
y as getUser,
|
325
340
|
H as makeQueryClient,
|
326
341
|
J as useAccountUpdate,
|
327
342
|
D as useBroadcastMutation,
|
328
|
-
|
343
|
+
z as useSignOperationByHivesigner,
|
329
344
|
U as useSignOperationByKey,
|
330
|
-
|
345
|
+
W as useSignOperationByKeychain
|
331
346
|
};
|
package/dist/index.d.ts
CHANGED