@audius/sdk 1.0.34 → 1.0.35

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.
@@ -76,7 +76,7 @@ export declare class CreatorNode {
76
76
  * @param timeout max time alloted for clock request
77
77
  * @param params optional query string params
78
78
  */
79
- static getClockValue(endpoint: string, wallet: string, timeout: number, params?: Record<string, string>): Promise<any>;
79
+ static getClockValue(endpoint: string, wallet: string, timeout?: number, params?: Record<string, string>): Promise<any>;
80
80
  /**
81
81
  * Checks if a download is available from provided creator node endpoints
82
82
  * @param endpoints creator node endpoints
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@audius/sdk",
3
- "version": "1.0.34",
3
+ "version": "1.0.35",
4
4
  "audius": {
5
- "releaseSHA": "8f0ae0d181bf1ee2dcf5ccc26987aaf1d0861903"
5
+ "releaseSHA": "e40315da81c1fcf7d1d43d1b7a4bcefc5d1243d1"
6
6
  },
7
7
  "description": "",
8
8
  "main": "dist/index.cjs.js",
@@ -1,6 +1,7 @@
1
1
  import { Nullable, Utils } from '../utils'
2
2
  import { CreatorNode } from '../services/creatorNode'
3
3
  import type { AudiusLibs } from '../AudiusLibs'
4
+ import maxBy from 'lodash/maxBy'
4
5
 
5
6
  const THREE_SECONDS = 3000
6
7
  const MAX_TRIES = 3
@@ -23,15 +24,26 @@ const checkPrimaryHealthy = async (
23
24
  }
24
25
 
25
26
  /** Gets new endpoints from a user's secondaries */
26
- const getNewPrimary = async (libs: AudiusLibs, secondaries: string[]) => {
27
- for (const secondary of secondaries) {
28
- const syncStatus = await libs.creatorNode?.getSyncStatus(secondary)
29
- if (!syncStatus) continue
30
- if (!syncStatus.isBehind) {
31
- return secondary
32
- }
27
+ const getNewPrimary = async (secondaries: string[], wallet: string) => {
28
+ const secondaryStatuses = (
29
+ await Promise.all(
30
+ secondaries.map(async (secondary) => {
31
+ try {
32
+ const clockValue = await CreatorNode.getClockValue(secondary, wallet)
33
+ if (clockValue) return { secondary, clockValue }
34
+ return undefined
35
+ } catch (e) {
36
+ console.warn(e)
37
+ return undefined
38
+ }
39
+ })
40
+ )
41
+ ).filter(Boolean)
42
+ const max = maxBy(secondaryStatuses, (s) => s?.clockValue)?.secondary
43
+ if (!max) {
44
+ throw new Error(`Could not find valid secondaries for user ${secondaries}`)
33
45
  }
34
- throw new Error(`Could not find valid secondaries for user ${secondaries}`)
46
+ return max
35
47
  }
36
48
 
37
49
  export const rolloverNodes = async (
@@ -54,7 +66,7 @@ export const rolloverNodes = async (
54
66
 
55
67
  try {
56
68
  // Get a new primary
57
- const newPrimary = await getNewPrimary(libs, secondaries)
69
+ const newPrimary = await getNewPrimary(secondaries, user.wallet!)
58
70
  const index = secondaries.indexOf(newPrimary)
59
71
  // Get new secondaries and backfill up to 2
60
72
  let newSecondaries = [...secondaries]
@@ -85,7 +97,11 @@ export const rolloverNodes = async (
85
97
  console.debug(
86
98
  `Sanity Check - rolloverNodes - new nodes ${newMetadata.creator_node_endpoint}`
87
99
  )
88
- await libs.User?.updateCreator(user.user_id, newMetadata)
100
+ await libs.User?.updateCreator(
101
+ user.user_id,
102
+ newMetadata,
103
+ true /* useEntityManager */
104
+ )
89
105
  } catch (e) {
90
106
  console.error(e)
91
107
  }
@@ -115,7 +115,7 @@ export class CreatorNode {
115
115
  static async getClockValue(
116
116
  endpoint: string,
117
117
  wallet: string,
118
- timeout: number,
118
+ timeout?: number,
119
119
  params: Record<string, string> = {}
120
120
  ) {
121
121
  const baseReq: AxiosRequestConfig = {