@ecency/sdk 1.0.32 → 1.0.33

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.
@@ -1,12 +1,12 @@
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
- import { Client as k, PrivateKey as p, cryptoUtils as S } from "@hiveio/dhive";
1
+ var O = Object.defineProperty;
2
+ var K = (e, t, n) => t in e ? O(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var d = (e, t, n) => K(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import { QueryClient as v, useMutation as y, useQuery as Q, useInfiniteQuery as b, queryOptions as f, infiniteQueryOptions as q } from "@tanstack/react-query";
5
+ import { Client as S, PrivateKey as l, cryptoUtils as _ } from "@hiveio/dhive";
6
6
  import m from "hivesigner";
7
- class b {
7
+ class k {
8
8
  constructor() {
9
- g(this, "length", 0);
9
+ d(this, "length", 0);
10
10
  }
11
11
  clear() {
12
12
  throw new Error("Method not implemented.");
@@ -24,11 +24,11 @@ class b {
24
24
  this[t] = n;
25
25
  }
26
26
  }
27
- const a = {
27
+ const o = {
28
28
  privateApiHost: "https://ecency.com",
29
- storage: typeof window > "u" ? new b() : window.localStorage,
29
+ storage: typeof window > "u" ? new k() : window.localStorage,
30
30
  storagePrefix: "ecency",
31
- hiveClient: new k(
31
+ hiveClient: new S(
32
32
  [
33
33
  "https://api.hive.blog",
34
34
  "https://api.deathwing.me",
@@ -49,48 +49,49 @@ const a = {
49
49
  }
50
50
  ),
51
51
  heliusApiKey: void 0,
52
- queryClient: new v()
52
+ queryClient: new v(),
53
+ plausibleHost: "https://pl.ecency.com"
53
54
  };
54
- var d;
55
+ var g;
55
56
  ((e) => {
56
57
  function t(n) {
57
- a.queryClient = n;
58
+ o.queryClient = n;
58
59
  }
59
60
  e.setQueryClient = t;
60
- })(d || (d = {}));
61
- function I(e) {
61
+ })(g || (g = {}));
62
+ function T(e) {
62
63
  let t = atob(e);
63
64
  if (t[0] === "{")
64
65
  return JSON.parse(t);
65
66
  }
66
- const y = (e) => {
67
+ const p = (e) => {
67
68
  try {
68
- const t = a.storage.getItem(
69
- a.storagePrefix + "_user_" + e
69
+ const t = o.storage.getItem(
70
+ o.storagePrefix + "_user_" + e
70
71
  );
71
- return I(JSON.parse(t));
72
+ return T(JSON.parse(t));
72
73
  } catch (t) {
73
74
  console.error(t);
74
75
  return;
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
- function D(e = [], t, n) {
78
- return f({
77
+ }, A = (e) => p(e) && p(e).accessToken, I = (e) => p(e) && p(e).postingKey, J = (e) => p(e) && p(e).refreshToken;
78
+ function j(e = [], t, n) {
79
+ return y({
79
80
  mutationKey: [...e, t],
80
81
  mutationFn: async (r) => {
81
82
  if (!t)
82
83
  throw new Error(
83
84
  "[Core][Broadcast] Attempted to call broadcast API with anon user"
84
85
  );
85
- const o = A(t);
86
- if (o) {
87
- const c = p.fromString(o);
88
- return a.hiveClient.broadcast.sendOperations(
86
+ const a = I(t);
87
+ if (a) {
88
+ const c = l.fromString(a);
89
+ return o.hiveClient.broadcast.sendOperations(
89
90
  n(r),
90
91
  c
91
92
  );
92
93
  }
93
- let s = T(t);
94
+ let s = A(t);
94
95
  if (s)
95
96
  return (await new m.Client({
96
97
  accessToken: s
@@ -101,7 +102,7 @@ function D(e = [], t, n) {
101
102
  }
102
103
  });
103
104
  }
104
- function H() {
105
+ function x() {
105
106
  return new v({
106
107
  defaultOptions: {
107
108
  queries: {
@@ -114,7 +115,7 @@ function H() {
114
115
  }
115
116
  });
116
117
  }
117
- const u = () => a.queryClient;
118
+ const u = () => o.queryClient;
118
119
  var w;
119
120
  ((e) => {
120
121
  function t(i) {
@@ -129,31 +130,31 @@ var w;
129
130
  return await u().prefetchQuery(i), t(i.queryKey);
130
131
  }
131
132
  e.prefetchQuery = r;
132
- async function o(i) {
133
+ async function a(i) {
133
134
  return await u().prefetchInfiniteQuery(i), n(i.queryKey);
134
135
  }
135
- e.prefetchInfiniteQuery = o;
136
+ e.prefetchInfiniteQuery = a;
136
137
  function s(i) {
137
138
  return {
138
139
  prefetch: () => r(i),
139
140
  getData: () => t(i.queryKey),
140
- useClientQuery: () => q(i),
141
+ useClientQuery: () => Q(i),
141
142
  fetchAndGet: () => u().fetchQuery(i)
142
143
  };
143
144
  }
144
145
  e.generateClientServerQuery = s;
145
146
  function c(i) {
146
147
  return {
147
- prefetch: () => o(i),
148
+ prefetch: () => a(i),
148
149
  getData: () => n(i.queryKey),
149
- useClientQuery: () => O(i),
150
+ useClientQuery: () => b(i),
150
151
  fetchAndGet: () => u().fetchInfiniteQuery(i)
151
152
  };
152
153
  }
153
154
  e.generateClientServerInfiniteQuery = c;
154
155
  })(w || (w = {}));
155
- function J(e) {
156
- return D(
156
+ function E(e) {
157
+ return j(
157
158
  ["accounts", "update"],
158
159
  e,
159
160
  ({
@@ -175,25 +176,25 @@ function J(e) {
175
176
  ]
176
177
  );
177
178
  }
178
- function E(e) {
179
- return l({
179
+ function M(e) {
180
+ return f({
180
181
  queryKey: ["get-account-full", e],
181
182
  queryFn: async () => {
182
183
  if (!e)
183
184
  throw new Error("[SDK] Username is empty");
184
- const t = await a.hiveClient.database.getAccounts([e]);
185
+ const t = await o.hiveClient.database.getAccounts([e]);
185
186
  if (!t[0])
186
187
  throw new Error("[SDK] No account with given username");
187
188
  const n = JSON.parse(t[0].posting_json_metadata).profile;
188
189
  let r;
189
190
  try {
190
- r = await a.hiveClient.database.call(
191
+ r = await o.hiveClient.database.call(
191
192
  "get_follow_count",
192
193
  [e]
193
194
  );
194
195
  } catch {
195
196
  }
196
- const o = await a.hiveClient.call(
197
+ const a = await o.hiveClient.call(
197
198
  "condenser_api",
198
199
  "get_account_reputations",
199
200
  [e, 1]
@@ -201,10 +202,10 @@ function E(e) {
201
202
  return {
202
203
  ...t,
203
204
  follow_stats: r,
204
- reputation: o[0].reputation,
205
+ reputation: a[0].reputation,
205
206
  profile: {
206
207
  ...n,
207
- reputation: o[0].reputation
208
+ reputation: a[0].reputation
208
209
  }
209
210
  };
210
211
  },
@@ -212,20 +213,39 @@ function E(e) {
212
213
  staleTime: 6e4
213
214
  });
214
215
  }
215
- function M(e, t = 5, n = []) {
216
- return l({
216
+ function U(e, t = 5, n = []) {
217
+ return f({
217
218
  queryKey: ["accounts", "search", e, n],
218
219
  enabled: !!e,
219
- queryFn: async () => (await a.hiveClient.database.call(
220
+ queryFn: async () => (await o.hiveClient.database.call(
220
221
  "lookup_accounts",
221
222
  [e, t]
222
223
  )).filter(
223
- (o) => n.length > 0 ? !n.includes(o) : !0
224
+ (a) => n.length > 0 ? !n.includes(a) : !0
224
225
  )
225
226
  });
226
227
  }
227
- function U(e) {
228
+ function W(e) {
228
229
  return f({
230
+ queryKey: ["accounts", "check-wallet-pending", e],
231
+ queryFn: async () => (await (await fetch(
232
+ o.privateApiHost + "/private-api/wallets-chkuser",
233
+ {
234
+ method: "POST",
235
+ headers: {
236
+ "Content-Type": "application/json"
237
+ },
238
+ body: JSON.stringify({
239
+ username: e
240
+ })
241
+ }
242
+ )).json()).length === 0,
243
+ enabled: !!e,
244
+ refetchOnMount: !0
245
+ });
246
+ }
247
+ function G(e) {
248
+ return y({
229
249
  mutationKey: ["operations", "sign", e],
230
250
  mutationFn: ({
231
251
  operation: t,
@@ -234,7 +254,7 @@ function U(e) {
234
254
  if (!e)
235
255
  throw new Error("[Operations][Sign] – cannot sign op with anon user");
236
256
  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(
257
+ return n.split(" ").length === 12 ? r = l.fromLogin(e, n, "active") : _.isWif(n) ? r = l.fromString(n) : r = l.from(n), o.hiveClient.broadcast.sendOperations(
238
258
  [t],
239
259
  r
240
260
  );
@@ -249,24 +269,24 @@ function F() {
249
269
  });
250
270
  });
251
271
  }
252
- const C = (e, t, n, r = null) => new Promise((o, s) => {
272
+ const C = (e, t, n, r = null) => new Promise((a, s) => {
253
273
  var c;
254
274
  (c = window.hive_keychain) == null || c.requestBroadcast(
255
275
  e,
256
276
  t,
257
277
  n,
258
278
  (i) => {
259
- i.success || s({ message: "Operation cancelled" }), o(i);
279
+ i.success || s({ message: "Operation cancelled" }), a(i);
260
280
  },
261
281
  r
262
282
  );
263
- }), G = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
283
+ }), z = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
264
284
  __proto__: null,
265
285
  broadcast: C,
266
286
  handshake: F
267
287
  }, Symbol.toStringTag, { value: "Module" }));
268
- function W(e, t = "Active") {
269
- return f({
288
+ function R(e, t = "Active") {
289
+ return y({
270
290
  mutationKey: ["operations", "sign-keychain", e],
271
291
  mutationFn: ({ operation: n }) => {
272
292
  if (!e)
@@ -277,18 +297,18 @@ function W(e, t = "Active") {
277
297
  }
278
298
  });
279
299
  }
280
- function z(e = "/") {
281
- return f({
300
+ function $(e = "/") {
301
+ return y({
282
302
  mutationKey: ["operations", "sign-hivesigner", e],
283
303
  mutationFn: async ({ operation: t }) => m.sendOperation(t, { callback: e }, () => {
284
304
  })
285
305
  });
286
306
  }
287
- function R(e, t) {
288
- return l({
307
+ function L(e, t) {
308
+ return f({
289
309
  queryKey: ["hive-engine", "tokens-list", e, t],
290
310
  queryFn: async () => (await (await fetch(
291
- `${a.privateApiHost}/private-api/engine-api`,
311
+ `${o.privateApiHost}/private-api/engine-api`,
292
312
  {
293
313
  method: "POST",
294
314
  body: JSON.stringify({
@@ -309,10 +329,10 @@ function R(e, t) {
309
329
  )).json()).result
310
330
  });
311
331
  }
312
- function $(e = 20) {
313
- return _({
332
+ function V(e = 20) {
333
+ return q({
314
334
  queryKey: ["posts", "trending-tags"],
315
- queryFn: async ({ pageParam: { afterTag: t } }) => a.hiveClient.database.call("get_trending_tags", [t, e]).then(
335
+ queryFn: async ({ pageParam: { afterTag: t } }) => o.hiveClient.database.call("get_trending_tags", [t, e]).then(
316
336
  (n) => n.filter((r) => r.name !== "").filter((r) => !r.name.startsWith("hive-")).map((r) => r.name)
317
337
  ),
318
338
  initialPageParam: { afterTag: "" },
@@ -323,24 +343,53 @@ function $(e = 20) {
323
343
  refetchOnMount: !0
324
344
  });
325
345
  }
346
+ function D(e, t) {
347
+ return y({
348
+ mutationKey: ["analytics", t],
349
+ mutationFn: async () => {
350
+ if (!t)
351
+ throw new Error("[SDK][Analytics] – no activity type provided");
352
+ await fetch(o.plausibleHost + "/api/event", {
353
+ method: "POST",
354
+ headers: {
355
+ "Content-Type": "application/json"
356
+ },
357
+ body: JSON.stringify({
358
+ name: t,
359
+ url: window.location.href,
360
+ domain: window.location.host,
361
+ props: {
362
+ username: e
363
+ }
364
+ })
365
+ });
366
+ }
367
+ });
368
+ }
369
+ const X = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
370
+ __proto__: null,
371
+ useRecordActivity: D
372
+ }, Symbol.toStringTag, { value: "Module" }));
326
373
  export {
327
- a as CONFIG,
328
- d as ConfigManager,
374
+ o as CONFIG,
375
+ g as ConfigManager,
376
+ X as EcencyAnalytics,
329
377
  w as EcencyQueriesManager,
330
- G as Keychain,
331
- T as getAccessToken,
332
- E as getAccountFullQueryOptions,
333
- R as getHiveEngineTokensListQueryOptions,
334
- A as getPostingKey,
378
+ z as Keychain,
379
+ W as checkUsernameWalletsPendingQueryOptions,
380
+ A as getAccessToken,
381
+ M as getAccountFullQueryOptions,
382
+ L as getHiveEngineTokensListQueryOptions,
383
+ I as getPostingKey,
335
384
  u as getQueryClient,
336
- x as getRefreshToken,
337
- M as getSearchAccountsByUsernameQueryOptions,
338
- $ as getTrendingTagsQueryOptions,
339
- y as getUser,
340
- H as makeQueryClient,
341
- J as useAccountUpdate,
342
- D as useBroadcastMutation,
343
- z as useSignOperationByHivesigner,
344
- U as useSignOperationByKey,
345
- W as useSignOperationByKeychain
385
+ J as getRefreshToken,
386
+ U as getSearchAccountsByUsernameQueryOptions,
387
+ V as getTrendingTagsQueryOptions,
388
+ p as getUser,
389
+ x as makeQueryClient,
390
+ E as useAccountUpdate,
391
+ j as useBroadcastMutation,
392
+ $ as useSignOperationByHivesigner,
393
+ G as useSignOperationByKey,
394
+ R as useSignOperationByKeychain
346
395
  };
package/dist/index.d.ts CHANGED
@@ -4,3 +4,4 @@ export * from './modules/core';
4
4
  export * from './modules/hive-engine';
5
5
  export * from './modules/keychain';
6
6
  export * from './modules/posts';
7
+ export * from './modules/analytics';
@@ -0,0 +1,8 @@
1
+ export declare function checkUsernameWalletsPendingQueryOptions(username: string): import('@tanstack/query-core').OmitKeyof<import('@tanstack/react-query').UseQueryOptions<boolean, Error, boolean, string[]>, "queryFn"> & {
2
+ queryFn?: import('@tanstack/query-core').QueryFunction<boolean, string[], never> | undefined;
3
+ } & {
4
+ queryKey: string[] & {
5
+ [dataTagSymbol]: boolean;
6
+ [dataTagErrorSymbol]: Error;
7
+ };
8
+ };
@@ -1,2 +1,3 @@
1
1
  export * from './get-account-full-query-options';
2
2
  export * from './search-accounts-by-username-query-options';
3
+ export * from './check-username-wallets-pending-query-options';
@@ -0,0 +1,2 @@
1
+ import * as EcencyAnalytics from "./mutations";
2
+ export { EcencyAnalytics };
@@ -0,0 +1 @@
1
+ export * from './use-record-activity';
@@ -0,0 +1,3 @@
1
+ type ActivityType = "post-created" | "post-updated" | "post-scheduled" | "draft-created";
2
+ export declare function useRecordActivity(username: string | undefined, activityType: ActivityType): import('@tanstack/react-query').UseMutationResult<void, Error, void, unknown>;
3
+ export {};
@@ -7,6 +7,7 @@ export declare const CONFIG: {
7
7
  hiveClient: Client;
8
8
  heliusApiKey: any;
9
9
  queryClient: QueryClient;
10
+ plausibleHost: string;
10
11
  };
11
12
  export declare namespace ConfigManager {
12
13
  function setQueryClient(client: QueryClient): void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ecency/sdk",
3
3
  "private": false,
4
- "version": "1.0.32",
4
+ "version": "1.0.33",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "main": "./dist/ecency-sdk.umd.js",