@audius/sdk 1.0.16 → 1.0.18

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.
@@ -2,6 +2,6 @@ import type BN from 'bn.js';
2
2
  /**
3
3
  * Converts a BN to a Uint8Array of length 8, in little endian notation.
4
4
  * Useful for when Rust wants a u64 (8 * 8) represented as a byte array.
5
- * Ex: https://github.com/AudiusProject/audius-protocol/blob/master/solana-programs/reward-manager/program/src/processor.rs#L389
5
+ * Ex: https://github.com/AudiusProject/audius-protocol/blob/main/solana-programs/reward-manager/program/src/processor.rs#L389
6
6
  */
7
7
  export declare const padBNToUint8Array: (bn: BN) => number[];
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@audius/sdk",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "audius": {
5
- "releaseSHA": "e0b7ce2e170d45ba8be2a30623688bd77cf6b4b4"
5
+ "releaseSHA": "cc52bcb636e5a70a3e50f6fe3b7eccc8f1f0c479"
6
6
  },
7
7
  "description": "",
8
8
  "main": "dist/index.cjs.js",
@@ -133,7 +133,7 @@
133
133
  },
134
134
  "repository": {
135
135
  "type": "git",
136
- "url": "git+https://github.com/AudiusProject/audius-protocol/tree/master/libs"
136
+ "url": "git+https://github.com/AudiusProject/audius-protocol/tree/main/libs"
137
137
  },
138
138
  "engines": {
139
139
  "node": ">=14.0.0"
@@ -143,5 +143,5 @@
143
143
  "bugs": {
144
144
  "url": "https://github.com/AudiusProject/audius-protocol/issues"
145
145
  },
146
- "homepage": "https://github.com/AudiusProject/audius-protocol/tree/master/libs"
146
+ "homepage": "https://github.com/AudiusProject/audius-protocol/tree/main/libs"
147
147
  }
@@ -33,27 +33,27 @@ function commit-message () {
33
33
  ${CHANGE_LOG}"
34
34
  }
35
35
 
36
- # Pull in master, ensure commit is on master, ensure clean build environment
36
+ # Pull in main, ensure commit is on main, ensure clean build environment
37
37
  function git-reset () {
38
38
  (
39
39
  # Configure git client
40
40
  git config --global user.email "audius-infra@audius.co"
41
41
  git config --global user.name "audius-infra"
42
42
 
43
- # Make sure master is up to date
44
- git checkout master -f
43
+ # Make sure main is up to date
44
+ git checkout main -f
45
45
  git pull
46
46
 
47
- if [[ "${GIT_COMMIT}" == "master" ]]; then
48
- echo "Commit cannot be 'master'."
47
+ if [[ "${GIT_COMMIT}" == "main" ]]; then
48
+ echo "Commit cannot be 'main'."
49
49
  exit 1
50
50
  fi
51
51
 
52
- # only allow commits found on master or release branches to be deployed
53
- echo "commit has to be on master or a release branch"
52
+ # only allow commits found on main or release branches to be deployed
53
+ echo "commit has to be on main or a release branch"
54
54
  git branch -a --contains ${GIT_COMMIT} \
55
55
  | tee /dev/tty \
56
- | grep -Eq 'remotes/origin/master|remotes/origin/release' \
56
+ | grep -Eq 'remotes/origin/main|remotes/origin/release' \
57
57
  || exit 1
58
58
 
59
59
  # Ensure working directory clean
@@ -88,10 +88,10 @@ function bump-version () {
88
88
  )
89
89
  }
90
90
 
91
- # Merge the created branch into master, then delete the branch
91
+ # Merge the created branch into main, then delete the branch
92
92
  function merge-bump () {
93
93
  (
94
- git checkout master -f
94
+ git checkout main -f
95
95
 
96
96
  # pull in any additional commits that may have trickled in
97
97
  git pull
@@ -105,7 +105,7 @@ function merge-bump () {
105
105
  git push origin --tags || exit 1
106
106
 
107
107
  # if pushing fails, ensure we cleanup()
108
- git push -u origin master || exit 1
108
+ git push -u origin main || exit 1
109
109
  git push origin :${STUB}-${VERSION}
110
110
  )
111
111
  }
@@ -118,7 +118,7 @@ function publish () {
118
118
  # informative links
119
119
  function info () {
120
120
  echo "Released to:
121
- https://github.com/AudiusProject/audius-protocol/commits/master
121
+ https://github.com/AudiusProject/audius-protocol/commits/main
122
122
  https://github.com/AudiusProject/audius-protocol/tags
123
123
  https://www.npmjs.com/package/@audius/sdk?activeTab=versions"
124
124
  }
@@ -134,7 +134,7 @@ function cleanup () {
134
134
  STUB=sdk
135
135
  cd ${PROTOCOL_DIR}/libs
136
136
 
137
- # pull in master
137
+ # pull in main
138
138
  git-reset
139
139
 
140
140
  # grab change log early, before the version bump
package/src/AudiusLibs.ts CHANGED
@@ -654,7 +654,7 @@ export class AudiusLibs {
654
654
  this.Account = new Account(this.User, ...services)
655
655
  this.Track = new Track(...services)
656
656
  this.Playlist = new Playlists(...services)
657
- this.File = new File(this.User, ...services)
657
+ this.File = new File(this.User, this.ServiceProvider, ...services)
658
658
  this.Rewards = new Rewards(this.ServiceProvider, ...services)
659
659
  this.Reactions = new Reactions(...services)
660
660
  this.EntityManager = new EntityManager(...services)
@@ -600,7 +600,7 @@ export class AudiusLibs {
600
600
  this.Account = new Account(this.User, ...services)
601
601
  this.Track = new Track(...services)
602
602
  this.Playlist = new Playlists(...services)
603
- this.File = new File(this.User, ...services)
603
+ this.File = new File(this.User, this.ServiceProvider, ...services)
604
604
  this.Rewards = new Rewards(this.ServiceProvider, ...services)
605
605
  this.Reactions = new Reactions(...services)
606
606
  this.EntityManager = new EntityManager(...services)
package/src/api/File.ts CHANGED
@@ -6,6 +6,7 @@ import { raceRequests } from '../utils/network'
6
6
  import retry from 'async-retry'
7
7
  import type { Users } from './Users'
8
8
  import type { Nullable } from '../utils'
9
+ import type { ServiceProvider } from './ServiceProvider'
9
10
 
10
11
  /**
11
12
  * Downloads a file using an element in the DOM
@@ -24,11 +25,17 @@ const downloadURL = (url: string, filename: string) => {
24
25
 
25
26
  export class File extends Base {
26
27
  User: Users
28
+ ServiceProvider: ServiceProvider
27
29
 
28
- constructor(user: Users, ...args: BaseConstructorArgs) {
30
+ constructor(
31
+ user: Users,
32
+ serviceProvider: ServiceProvider,
33
+ ...args: BaseConstructorArgs
34
+ ) {
29
35
  super(...args)
30
36
 
31
37
  this.User = user
38
+ this.ServiceProvider = serviceProvider
32
39
  }
33
40
 
34
41
  /**
@@ -46,6 +53,45 @@ export class File extends Base {
46
53
  responseType: ResponseType = 'blob',
47
54
  trackId = null,
48
55
  premiumContentHeaders = {}
56
+ ) {
57
+ try {
58
+ const replicaSetAttempt = await this.fetchCIDInternal(
59
+ cid,
60
+ creatorNodeGateways,
61
+ callback,
62
+ responseType,
63
+ trackId,
64
+ premiumContentHeaders
65
+ )
66
+ return replicaSetAttempt
67
+ } catch (e) {
68
+ // In the case we can't find the CID from anywhere in the user's replica set,
69
+ // retry the whole network
70
+ console.error(e)
71
+ const allCreatorNodes = await this.ServiceProvider.listCreatorNodes()
72
+ const allCreatorNodeEndpoints = allCreatorNodes.map((node) =>
73
+ urlJoin(node.endpoint, 'ipfs')
74
+ )
75
+ // Re-throw whatever error might happen here
76
+ const allNodesAttempt = await this.fetchCIDInternal(
77
+ cid,
78
+ allCreatorNodeEndpoints,
79
+ callback,
80
+ responseType,
81
+ trackId,
82
+ premiumContentHeaders
83
+ )
84
+ return allNodesAttempt
85
+ }
86
+ }
87
+
88
+ async fetchCIDInternal(
89
+ cid: string,
90
+ creatorNodeGateways: string[],
91
+ callback: Nullable<(url: string) => void> = null,
92
+ responseType: ResponseType = 'blob',
93
+ trackId = null,
94
+ premiumContentHeaders = {}
49
95
  ) {
50
96
  const urls: string[] = []
51
97
 
@@ -123,7 +169,7 @@ export class File extends Base {
123
169
  minTimeout: 500,
124
170
  maxTimeout: 4000,
125
171
  factor: 3,
126
- retries: 5,
172
+ retries: 3,
127
173
  onRetry: (err: any, i) => {
128
174
  // eslint-disable-next-line no-console
129
175
  console.log(`FetchCID attempt ${i} error: ${err}`)
@@ -275,7 +275,7 @@
275
275
  "title": "CID"
276
276
  },
277
277
  "PremiumConditions": {
278
- "type": "object",
278
+ "type": ["object", "null"],
279
279
  "additionalProperties": false,
280
280
  "properties": {
281
281
  "nft_collection": {
@@ -2,6 +2,6 @@ import type BN from 'bn.js'
2
2
  /**
3
3
  * Converts a BN to a Uint8Array of length 8, in little endian notation.
4
4
  * Useful for when Rust wants a u64 (8 * 8) represented as a byte array.
5
- * Ex: https://github.com/AudiusProject/audius-protocol/blob/master/solana-programs/reward-manager/program/src/processor.rs#L389
5
+ * Ex: https://github.com/AudiusProject/audius-protocol/blob/main/solana-programs/reward-manager/program/src/processor.rs#L389
6
6
  */
7
7
  export const padBNToUint8Array = (bn: BN): number[] => bn.toArray('le', 8)