@ecency/sdk 1.4.1 → 1.5.1

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.mjs CHANGED
@@ -189,8 +189,8 @@ var getBoundFetch2 = () => {
189
189
  }
190
190
  return globalThis.fetch;
191
191
  };
192
- function useBroadcastMutation(mutationKey = [], username, operations, onSuccess = () => {
193
- }) {
192
+ function useBroadcastMutation(mutationKey = [], username, accessToken, operations, onSuccess = () => {
193
+ }, auth) {
194
194
  return useMutation({
195
195
  onSuccess,
196
196
  mutationKey: [...mutationKey, username],
@@ -200,7 +200,7 @@ function useBroadcastMutation(mutationKey = [], username, operations, onSuccess
200
200
  "[Core][Broadcast] Attempted to call broadcast API with anon user"
201
201
  );
202
202
  }
203
- const postingKey = getPostingKey(username);
203
+ const postingKey = auth?.postingKey;
204
204
  if (postingKey) {
205
205
  const privateKey = PrivateKey.fromString(postingKey);
206
206
  return CONFIG.hiveClient.broadcast.sendOperations(
@@ -208,7 +208,7 @@ function useBroadcastMutation(mutationKey = [], username, operations, onSuccess
208
208
  privateKey
209
209
  );
210
210
  }
211
- const loginType = getLoginType(username);
211
+ const loginType = auth?.loginType;
212
212
  if (loginType && loginType == "keychain") {
213
213
  return keychain_exports.broadcast(
214
214
  username,
@@ -216,13 +216,12 @@ function useBroadcastMutation(mutationKey = [], username, operations, onSuccess
216
216
  "Posting"
217
217
  ).then((r) => r.result);
218
218
  }
219
- let token = getAccessToken(username);
220
- if (token) {
219
+ if (accessToken) {
221
220
  const f = getBoundFetch2();
222
221
  const res = await f("https://hivesigner.com/api/broadcast", {
223
222
  method: "POST",
224
223
  headers: {
225
- Authorization: token,
224
+ Authorization: accessToken,
226
225
  "Content-Type": "application/json",
227
226
  Accept: "application/json"
228
227
  },
@@ -244,7 +243,7 @@ function useBroadcastMutation(mutationKey = [], username, operations, onSuccess
244
243
  }
245
244
  });
246
245
  }
247
- async function broadcastJson(username, id, payload) {
246
+ async function broadcastJson(username, id, payload, accessToken, auth) {
248
247
  if (!username) {
249
248
  throw new Error(
250
249
  "[Core][Broadcast] Attempted to call broadcast API with anon user"
@@ -256,7 +255,7 @@ async function broadcastJson(username, id, payload) {
256
255
  required_posting_auths: [username],
257
256
  json: JSON.stringify(payload)
258
257
  };
259
- const postingKey = getPostingKey(username);
258
+ const postingKey = auth?.postingKey;
260
259
  if (postingKey) {
261
260
  const privateKey = PrivateKey.fromString(postingKey);
262
261
  return CONFIG.hiveClient.broadcast.json(
@@ -264,14 +263,13 @@ async function broadcastJson(username, id, payload) {
264
263
  privateKey
265
264
  );
266
265
  }
267
- const loginType = getLoginType(username);
266
+ const loginType = auth?.loginType;
268
267
  if (loginType && loginType == "keychain") {
269
268
  return keychain_exports.broadcast(username, [["custom_json", jjson]], "Posting").then((r) => r.result);
270
269
  }
271
- let token = getAccessToken(username);
272
- if (token) {
270
+ if (accessToken) {
273
271
  const response = await new hs.Client({
274
- accessToken: token
272
+ accessToken
275
273
  }).customJson([], [username], id, JSON.stringify(payload));
276
274
  return response.result;
277
275
  }
@@ -587,11 +585,14 @@ function getActiveAccountFavouritesQueryOptions(activeUsername) {
587
585
  }
588
586
  });
589
587
  }
590
- function getAccountRecoveriesQueryOptions(username) {
588
+ function getAccountRecoveriesQueryOptions(username, code) {
591
589
  return queryOptions({
592
- enabled: !!username,
590
+ enabled: !!username && !!code,
593
591
  queryKey: ["accounts", "recoveries", username],
594
592
  queryFn: async () => {
593
+ if (!username || !code) {
594
+ throw new Error("[SDK][Accounts] Missing username or access token");
595
+ }
595
596
  const fetchApi = getBoundFetch();
596
597
  const response = await fetchApi(
597
598
  CONFIG.privateApiHost + "/private-api/recoveries",
@@ -600,7 +601,7 @@ function getAccountRecoveriesQueryOptions(username) {
600
601
  headers: {
601
602
  "Content-Type": "application/json"
602
603
  },
603
- body: JSON.stringify({ code: getAccessToken(username) })
604
+ body: JSON.stringify({ code })
604
605
  }
605
606
  );
606
607
  return response.json();
@@ -642,12 +643,13 @@ function getBuiltProfile({
642
643
  metadata.tokens = sanitizeTokens(metadata.tokens);
643
644
  return metadata;
644
645
  }
645
- function useAccountUpdate(username) {
646
+ function useAccountUpdate(username, accessToken, auth) {
646
647
  const queryClient = useQueryClient();
647
648
  const { data } = useQuery(getAccountFullQueryOptions(username));
648
649
  return useBroadcastMutation(
649
650
  ["accounts", "update"],
650
651
  username,
652
+ accessToken,
651
653
  (payload) => {
652
654
  if (!data) {
653
655
  throw new Error("[SDK][Accounts] \u2013 cannot update not existing account");
@@ -676,7 +678,8 @@ function useAccountUpdate(username) {
676
678
  obj.profile = getBuiltProfile({ ...variables, data: data2 });
677
679
  return obj;
678
680
  }
679
- )
681
+ ),
682
+ auth
680
683
  );
681
684
  }
682
685
  function useAccountRelationsUpdate(reference, target, onSuccess, onError) {
@@ -1328,11 +1331,10 @@ var queries_exports = {};
1328
1331
  __export(queries_exports, {
1329
1332
  getDecodeMemoQueryOptions: () => getDecodeMemoQueryOptions
1330
1333
  });
1331
- function getDecodeMemoQueryOptions(username, memo) {
1334
+ function getDecodeMemoQueryOptions(username, memo, accessToken) {
1332
1335
  return queryOptions({
1333
1336
  queryKey: ["integrations", "hivesigner", "decode-memo", username],
1334
1337
  queryFn: async () => {
1335
- const accessToken = getAccessToken(username);
1336
1338
  if (accessToken) {
1337
1339
  const hsClient = new hs.Client({
1338
1340
  accessToken
@@ -1349,12 +1351,12 @@ var HiveSignerIntegration = {
1349
1351
  };
1350
1352
 
1351
1353
  // src/modules/integrations/3speak/queries/get-account-token-query-options.ts
1352
- function getAccountTokenQueryOptions(username) {
1354
+ function getAccountTokenQueryOptions(username, accessToken) {
1353
1355
  return queryOptions({
1354
1356
  queryKey: ["integrations", "3speak", "authenticate", username],
1355
- enabled: !!username,
1357
+ enabled: !!username && !!accessToken,
1356
1358
  queryFn: async () => {
1357
- if (!username) {
1359
+ if (!username || !accessToken) {
1358
1360
  throw new Error("[SDK][Integrations][3Speak] \u2013\xA0anon user");
1359
1361
  }
1360
1362
  const fetchApi = getBoundFetch();
@@ -1368,7 +1370,8 @@ function getAccountTokenQueryOptions(username) {
1368
1370
  );
1369
1371
  const memoQueryOptions = HiveSignerIntegration.queries.getDecodeMemoQueryOptions(
1370
1372
  username,
1371
- (await response.json()).memo
1373
+ (await response.json()).memo,
1374
+ accessToken
1372
1375
  );
1373
1376
  await getQueryClient().prefetchQuery(memoQueryOptions);
1374
1377
  const { memoDecoded } = getQueryClient().getQueryData(
@@ -1378,17 +1381,25 @@ function getAccountTokenQueryOptions(username) {
1378
1381
  }
1379
1382
  });
1380
1383
  }
1381
- function getAccountVideosQueryOptions(username) {
1384
+ function getAccountVideosQueryOptions(username, accessToken) {
1382
1385
  return queryOptions({
1383
1386
  queryKey: ["integrations", "3speak", "videos", username],
1384
- enabled: !!username,
1387
+ enabled: !!username && !!accessToken,
1385
1388
  queryFn: async () => {
1386
- await getQueryClient().prefetchQuery(
1387
- getAccountTokenQueryOptions(username)
1389
+ if (!username || !accessToken) {
1390
+ throw new Error("[SDK][Integrations][3Speak] \u2013\xA0anon user");
1391
+ }
1392
+ const tokenQueryOptions = getAccountTokenQueryOptions(
1393
+ username,
1394
+ accessToken
1388
1395
  );
1396
+ await getQueryClient().prefetchQuery(tokenQueryOptions);
1389
1397
  const token = getQueryClient().getQueryData(
1390
- getAccountTokenQueryOptions(username).queryKey
1398
+ tokenQueryOptions.queryKey
1391
1399
  );
1400
+ if (!token) {
1401
+ throw new Error("[SDK][Integrations][3Speak] \u2013 missing account token");
1402
+ }
1392
1403
  const fetchApi = getBoundFetch();
1393
1404
  const response = await fetchApi(
1394
1405
  `https://studio.3speak.tv/mobile/api/my-videos`,
@@ -1645,4 +1656,4 @@ function getCommunityPermissions({
1645
1656
 
1646
1657
  export { CONFIG, ConfigManager, mutations_exports as EcencyAnalytics, EcencyQueriesManager, HiveSignerIntegration, keychain_exports as Keychain, NaiMap, ROLES, Symbol2 as Symbol, ThreeSpeakIntegration, broadcastJson, checkUsernameWalletsPendingQueryOptions, decodeObj, dedupeAndSortKeyAuths, encodeObj, getAccessToken, getAccountFullQueryOptions, getAccountPendingRecoveryQueryOptions, getAccountRcQueryOptions, getAccountRecoveriesQueryOptions, getAccountSubscriptionsQueryOptions, getActiveAccountBookmarksQueryOptions, getActiveAccountFavouritesQueryOptions, getBoundFetch, getChainPropertiesQueryOptions, getCommunitiesQueryOptions, getCommunityContextQueryOptions, getCommunityPermissions, getCommunityType, getDynamicPropsQueryOptions, getFragmentsQueryOptions, getGameStatusCheckQueryOptions, getHivePoshLinksQueryOptions, getLoginType, getPostingKey, getPromotedPostsQuery, getQueryClient, getRcStatsQueryOptions, getRefreshToken, getRelationshipBetweenAccountsQueryOptions, getSearchAccountsByUsernameQueryOptions, getStatsQueryOptions, getTrendingTagsQueryOptions, getUser, makeQueryClient, parseAsset, roleMap, useAccountFavouriteAdd, useAccountFavouriteDelete, useAccountRelationsUpdate, useAccountRevokeKey, useAccountRevokePosting, useAccountUpdate, useAccountUpdateKeyAuths, useAccountUpdatePassword, useAccountUpdateRecovery, useAddFragment, useBookmarkAdd, useBookmarkDelete, useBroadcastMutation, useEditFragment, useGameClaim, useRemoveFragment, useSignOperationByHivesigner, useSignOperationByKey, useSignOperationByKeychain };
1647
1658
  //# sourceMappingURL=index.mjs.map
1648
- //# sourceMappingURL=index.mjs.map
1659
+ //# sourceMappingURL=index.mjs.map