@ecency/sdk 1.3.3 → 1.3.5

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.
@@ -3,7 +3,7 @@
3
3
  var reactQuery = require('@tanstack/react-query');
4
4
  var dhive = require('@hiveio/dhive');
5
5
  var hs = require('hivesigner');
6
- var R = require('remeda');
6
+ var R4 = require('remeda');
7
7
 
8
8
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
9
 
@@ -26,7 +26,7 @@ function _interopNamespace(e) {
26
26
  }
27
27
 
28
28
  var hs__default = /*#__PURE__*/_interopDefault(hs);
29
- var R__namespace = /*#__PURE__*/_interopNamespace(R);
29
+ var R4__namespace = /*#__PURE__*/_interopNamespace(R4);
30
30
 
31
31
  var __defProp = Object.defineProperty;
32
32
  var __export = (target, all) => {
@@ -427,11 +427,7 @@ function getAccountFullQueryOptions(username) {
427
427
  if (!response[0]) {
428
428
  throw new Error("[SDK] No account with given username");
429
429
  }
430
- let profile = {};
431
- try {
432
- profile = JSON.parse(response[0].posting_json_metadata).profile;
433
- } catch (e) {
434
- }
430
+ const profile = parseProfileMetadata(response[0].posting_json_metadata);
435
431
  let follow_stats;
436
432
  try {
437
433
  follow_stats = await CONFIG.hiveClient.database.call(
@@ -725,21 +721,42 @@ function sanitizeTokens(tokens) {
725
721
  return { ...rest, meta: safeMeta };
726
722
  });
727
723
  }
728
- function getBuiltProfile({
724
+ function parseProfileMetadata(postingJsonMetadata) {
725
+ if (!postingJsonMetadata) {
726
+ return {};
727
+ }
728
+ try {
729
+ const parsed = JSON.parse(postingJsonMetadata);
730
+ if (parsed && typeof parsed === "object" && parsed.profile && typeof parsed.profile === "object") {
731
+ return parsed.profile;
732
+ }
733
+ } catch (err) {
734
+ }
735
+ return {};
736
+ }
737
+ function extractAccountProfile(data) {
738
+ return parseProfileMetadata(data?.posting_json_metadata);
739
+ }
740
+ function buildProfileMetadata({
741
+ existingProfile,
729
742
  profile,
730
- tokens,
731
- data
743
+ tokens
732
744
  }) {
733
- const metadata = R__namespace.pipe(
734
- JSON.parse(data?.posting_json_metadata || "{}").profile,
735
- R__namespace.mergeDeep(profile ?? {})
745
+ const { tokens: profileTokens, version: _ignoredVersion, ...profileRest } = profile ?? {};
746
+ const metadata = R4__namespace.mergeDeep(
747
+ existingProfile ?? {},
748
+ profileRest
736
749
  );
737
- if (tokens && tokens.length > 0) {
738
- metadata.tokens = tokens;
750
+ const nextTokens = tokens ?? profileTokens;
751
+ if (nextTokens && nextTokens.length > 0) {
752
+ metadata.tokens = nextTokens;
739
753
  }
740
754
  metadata.tokens = sanitizeTokens(metadata.tokens);
755
+ metadata.version = 2;
741
756
  return metadata;
742
757
  }
758
+
759
+ // src/modules/accounts/mutations/use-account-update.ts
743
760
  function useAccountUpdate(username) {
744
761
  const queryClient = reactQuery.useQueryClient();
745
762
  const { data } = reactQuery.useQuery(getAccountFullQueryOptions(username));
@@ -750,6 +767,11 @@ function useAccountUpdate(username) {
750
767
  if (!data) {
751
768
  throw new Error("[SDK][Accounts] \u2013 cannot update not existing account");
752
769
  }
770
+ const profile = buildProfileMetadata({
771
+ existingProfile: extractAccountProfile(data),
772
+ profile: payload.profile,
773
+ tokens: payload.tokens
774
+ });
753
775
  return [
754
776
  [
755
777
  "account_update2",
@@ -758,7 +780,7 @@ function useAccountUpdate(username) {
758
780
  json_metadata: "",
759
781
  extensions: [],
760
782
  posting_json_metadata: JSON.stringify({
761
- profile: getBuiltProfile({ ...payload, data })
783
+ profile
762
784
  })
763
785
  }
764
786
  ]
@@ -770,8 +792,12 @@ function useAccountUpdate(username) {
770
792
  if (!data2) {
771
793
  return data2;
772
794
  }
773
- const obj = R__namespace.clone(data2);
774
- obj.profile = getBuiltProfile({ ...variables, data: data2 });
795
+ const obj = R4__namespace.clone(data2);
796
+ obj.profile = buildProfileMetadata({
797
+ existingProfile: extractAccountProfile(data2),
798
+ profile: variables.profile,
799
+ tokens: variables.tokens
800
+ });
775
801
  return obj;
776
802
  }
777
803
  )
@@ -966,7 +992,7 @@ function useAccountUpdateKeyAuths(username, options) {
966
992
  );
967
993
  }
968
994
  const prepareAuth = (keyName) => {
969
- const auth = R__namespace.clone(accountData[keyName]);
995
+ const auth = R4__namespace.clone(accountData[keyName]);
970
996
  auth.key_auths = dedupeAndSortKeyAuths(
971
997
  keepCurrent ? auth.key_auths : [],
972
998
  keys.map(
@@ -1037,9 +1063,9 @@ function useAccountRevokePosting(username, options) {
1037
1063
  "[SDK][Accounts] \u2013\xA0cannot revoke posting for anonymous user"
1038
1064
  );
1039
1065
  }
1040
- const posting = R__namespace.pipe(
1066
+ const posting = R4__namespace.pipe(
1041
1067
  {},
1042
- R__namespace.mergeDeep(data.posting)
1068
+ R4__namespace.mergeDeep(data.posting)
1043
1069
  );
1044
1070
  posting.account_auths = posting.account_auths.filter(
1045
1071
  ([account]) => account !== accountName
@@ -1156,7 +1182,7 @@ function useAccountRevokeKey(username, options) {
1156
1182
  );
1157
1183
  }
1158
1184
  const prepareAuth = (keyName) => {
1159
- const auth = R__namespace.clone(accountData[keyName]);
1185
+ const auth = R4__namespace.clone(accountData[keyName]);
1160
1186
  auth.key_auths = auth.key_auths.filter(
1161
1187
  ([key]) => key !== revokingKey.toString()
1162
1188
  );
@@ -1750,10 +1776,12 @@ exports.ROLES = ROLES;
1750
1776
  exports.Symbol = Symbol2;
1751
1777
  exports.ThreeSpeakIntegration = ThreeSpeakIntegration;
1752
1778
  exports.broadcastJson = broadcastJson;
1779
+ exports.buildProfileMetadata = buildProfileMetadata;
1753
1780
  exports.checkUsernameWalletsPendingQueryOptions = checkUsernameWalletsPendingQueryOptions;
1754
1781
  exports.decodeObj = decodeObj;
1755
1782
  exports.dedupeAndSortKeyAuths = dedupeAndSortKeyAuths;
1756
1783
  exports.encodeObj = encodeObj;
1784
+ exports.extractAccountProfile = extractAccountProfile;
1757
1785
  exports.getAccessToken = getAccessToken;
1758
1786
  exports.getAccountFullQueryOptions = getAccountFullQueryOptions;
1759
1787
  exports.getAccountPendingRecoveryQueryOptions = getAccountPendingRecoveryQueryOptions;
@@ -1785,6 +1813,7 @@ exports.getTrendingTagsQueryOptions = getTrendingTagsQueryOptions;
1785
1813
  exports.getUser = getUser;
1786
1814
  exports.makeQueryClient = makeQueryClient;
1787
1815
  exports.parseAsset = parseAsset;
1816
+ exports.parseProfileMetadata = parseProfileMetadata;
1788
1817
  exports.roleMap = roleMap;
1789
1818
  exports.useAccountFavouriteAdd = useAccountFavouriteAdd;
1790
1819
  exports.useAccountFavouriteDelete = useAccountFavouriteDelete;