Skip to content

Commit

Permalink
[C-551] Bundle and init @audius/sdk (#3170)
Browse files Browse the repository at this point in the history
* Move libs to deprecated named export

* Expose sdk

* Export and polyfill sdk for the browser

* [WIP] Fix sdk bundling

* Fix runtime errors

* Multiple entrypoint bundle

* Single entrypoint bundle

* Clean up rollup.config

* Create legacy bundle for use in client

* Clean up sdk init

* Integrate oauth changes

* Change package name

* Set version to 0.0.0

* Address PR comments

* Fix libs import in initAudiusLibs

* Update libs usages -> sdk

* Update libs dep -> sdk

* Clean up discovery provider configuration

* Fix formatting

* Revert and fix formatting

* Fix formatting in audiusLibsInstance

* Fix formatting and helpers

* Make appName required

* Fix libs tests

* Fix libs tests

* lint fix

* Install dependencies before made dog

* Install service command deps before mad dog

* Always init discovery provider

* Bump sdk to 0.0.2

* Revery always init discovery
  • Loading branch information
sliptype authored Jun 3, 2022
1 parent 782a1c4 commit 5c94b3d
Show file tree
Hide file tree
Showing 70 changed files with 3,224 additions and 2,517 deletions.
505 changes: 238 additions & 267 deletions creator-node/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion creator-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"author": "",
"license": "Apache-2.0",
"dependencies": {
"@audius/libs": "1.2.114",
"@audius/sdk": "0.0.2",
"@bull-board/express": "3.11.0",
"@solana/web3.js": "1.31.0",
"JSONStream": "^1.3.5",
Expand Down
2 changes: 1 addition & 1 deletion creator-node/scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ if [[ "$devMode" == "true" ]]; then
cd ../audius-libs
npm link
cd ../app
npm link @audius/libs
npm link @audius/sdk
npx nodemon --exec 'node --inspect=0.0.0.0:${debuggerPort} --require ts-node/register src/index.ts' --watch src/ --watch ../audius-libs/ | tee >(logger) | ./node_modules/.bin/bunyan
else
npx nodemon --exec 'node --inspect=0.0.0.0:${debuggerPort} --require ts-node/register src/index.ts' --watch src/ | tee >(logger) | ./node_modules/.bin/bunyan
Expand Down
3 changes: 2 additions & 1 deletion creator-node/src/apiSigning.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { Utils: LibsUtils } = require('@audius/libs')
const { libs } = require('@audius/sdk')
const LibsUtils = libs.Utils
const Web3 = require('web3')
const web3 = new Web3()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const {
const { getSegmentsDuration } = require('../../segmentDuration')

const models = require('../../models')
const { Utils } = require('@audius/libs')
const { libs } = require('@audius/sdk')
const Utils = libs.Utils
const DBManager = require('../../dbManager')
const TranscodingQueue = require('../../TranscodingQueue')
const FileManager = require('../../fileManager')
Expand Down
3 changes: 2 additions & 1 deletion creator-node/src/fileManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const axios = require('axios')

const config = require('./config')
const Utils = require('./utils')
const { Utils: LibsUtils } = require('@audius/libs')
const { libs } = require('@audius/sdk')
const LibsUtils = libs.Utils
const DiskManager = require('./diskManager')
const { logger: genericLogger } = require('./logging')
const { sendResponse, errorResponseBadRequest } = require('./apiHelpers')
Expand Down
3 changes: 2 additions & 1 deletion creator-node/src/resizeImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const fs = require('fs-extra')
const path = require('path')

const { logger: genericLogger } = require('./logging')
const { Utils } = require('@audius/libs')
const { libs } = require('@audius/sdk')
const Utils = libs.Utils
const DiskManager = require('./diskManager')

const MAX_HEIGHT = 6000 // No image should be taller than this.
Expand Down
3 changes: 2 additions & 1 deletion creator-node/src/routes/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ const {
const ImageProcessingQueue = require('../ImageProcessingQueue')
const DBManager = require('../dbManager')
const DiskManager = require('../diskManager')
const { Utils } = require('@audius/libs')
const { libs } = require('@audius/sdk')
const Utils = libs.Utils

const { promisify } = require('util')

Expand Down
17 changes: 5 additions & 12 deletions creator-node/src/serviceRegistry.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const AudiusLibs = require('@audius/libs')
const { libs: AudiusLibs } = require('@audius/sdk')
const redisClient = require('./redis')
const BlacklistManager = require('./blacklistManager')
const { SnapbackSM } = require('./snapbackSM/snapbackSM')
Expand Down Expand Up @@ -365,17 +365,10 @@ class ServiceRegistry {
// TODO - formatting this private key here is not ideal
config.get('delegatePrivateKey').replace('0x', '')
),
discoveryProviderConfig: AudiusLibs.configDiscoveryProvider(
discoveryProviderWhitelist,
/* blacklist */ null,
/* reselectTimeout */ null,
/* selectionCallback */ null,
/* monitoringCallbacks */ {},
/* selectionRequestTimeout */ null,
/* selectionRequestRetries */ null,
/* unhealthySlotDiffPlays */ null,
discoveryNodeUnhealthyBlockDiff
),
discoveryProviderConfig: {
whitelist: discoveryProviderWhitelist,
unhealthyBlockDiff: discoveryNodeUnhealthyBlockDiff
},
// If an identity service config is present, set up libs with the connection, otherwise do nothing
identityServiceConfig: identityService
? AudiusLibs.configIdentityService(identityService)
Expand Down
3 changes: 2 additions & 1 deletion creator-node/src/services/URSMRegistrationManager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const axios = require('axios')
const _ = require('lodash')
const { Utils: LibsUtils } = require('@audius/libs')
const { libs } = require('@audius/sdk')
const LibsUtils = libs.Utils

const { logger } = require('../logging')
const { generateTimestampAndSignature } = require('../apiSigning')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { CreatorNode } = require('@audius/libs')
const { libs } = require('@audius/sdk')
const CreatorNode = libs.CreatorNode
const axios = require('axios')
const retry = require('async-retry')

Expand Down
3 changes: 2 additions & 1 deletion creator-node/src/snapbackSM/snapbackSM.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const redis = require('../redis.js')

const SyncDeDuplicator = require('./snapbackDeDuplicator')
const PeerSetManager = require('./peerSetManager')
const { CreatorNode } = require('@audius/libs')
const { libs } = require('@audius/sdk')
const CreatorNode = libs.CreatorNode
const SecondarySyncHealthTracker = require('./secondarySyncHealthTracker')
const { generateTimestampAndSignature } = require('../apiSigning')
const {
Expand Down
3 changes: 2 additions & 1 deletion creator-node/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const models = require('./models')
const redis = require('./redis')
const config = require('./config')
const { generateTimestampAndSignature } = require('./apiSigning')
const { Utils: LibsUtils } = require('@audius/libs')
const { libs } = require('@audius/sdk')
const LibsUtils = libs.Utils

const THIRTY_MINUTES_IN_SECONDS = 60 * 30

Expand Down
21 changes: 12 additions & 9 deletions creator-node/test/dbManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const DBManager = require('../src/dbManager')
const BlacklistManager = require('../src/blacklistManager')
const FileManager = require('../src/fileManager')
const DiskManager = require('../src/diskManager')
const { Utils } = require('@audius/libs')
const { libs } = require('@audius/sdk')
const Utils = libs.Utils
const utils = require('../src/utils')
const {
createStarterCNodeUser,
Expand Down Expand Up @@ -702,14 +703,16 @@ describe('Test deleteAllCNodeUserDataFromDB()', async () => {
const { handleTrackContentRoute } = proxyquire(
'../src/components/tracks/tracksComponentService.js',
{
'@audius/libs': {
Utils: {
fileHasher: {
generateNonImageCid: sinon.stub().returns(
new Promise((resolve) => {
return resolve(mockCid)
})
)
'@audius/sdk': {
libs: {
Utils: {
fileHasher: {
generateNonImageCid: sinon.stub().returns(
new Promise((resolve) => {
return resolve(mockCid)
})
)
}
}
},
'@global': true
Expand Down
3 changes: 2 additions & 1 deletion creator-node/test/fileManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const fs = require('fs-extra')
const path = require('path')
const proxyquire = require('proxyquire')

const { Utils } = require('@audius/libs')
const { libs } = require('@audius/sdk')
const Utils = libs.Utils
const { logger: genericLogger } = require('../src/logging')
const {
removeTrackFolder,
Expand Down
21 changes: 12 additions & 9 deletions creator-node/test/pollingTracks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const crypto = require('crypto')

const config = require('../src/config')
const defaultConfig = require('../default-config.json')
const { Utils } = require('@audius/libs')
const { libs } = require('@audius/sdk')
const Utils = libs
const BlacklistManager = require('../src/blacklistManager')
const TranscodingQueue = require('../src/TranscodingQueue')
const models = require('../src/models')
Expand Down Expand Up @@ -94,14 +95,16 @@ describe('test Polling Tracks with mocks', function () {
;({ handleTrackContentRoute } = proxyquire(
'../src/components/tracks/tracksComponentService.js',
{
'@audius/libs': {
Utils: {
fileHasher: {
generateNonImageCid: sinon.stub().returns(
new Promise((resolve) => {
return resolve(mockCid)
})
)
'@audius/sdk': {
libs: {
Utils: {
fileHasher: {
generateNonImageCid: sinon.stub().returns(
new Promise((resolve) => {
return resolve(mockCid)
})
)
}
}
},
'@global': true
Expand Down
3 changes: 2 additions & 1 deletion creator-node/test/resizeImage.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { Utils } = require('@audius/libs')
const { libs } = require('@audius/sdk')
const Utils = libs.Utils
const resizeImageJob = require('../src/resizeImage')
const config = require('../src/config')
const DiskManager = require('../src/diskManager')
Expand Down
16 changes: 10 additions & 6 deletions creator-node/test/stateMachineUtils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,11 @@ describe('test retrieveClockValueForUserFromReplica()', function () {
const { retrieveClockValueForUserFromReplica } = proxyquire(
'../src/services/stateMachineManager/stateMachineUtils.js',
{
'@audius/libs': {
CreatorNode: {
getClockValue: getClockValueStub
'@audius/sdk': {
libs: {
CreatorNode: {
getClockValue: getClockValueStub
}
}
}
}
Expand All @@ -169,9 +171,11 @@ describe('test retrieveClockValueForUserFromReplica()', function () {
const { retrieveClockValueForUserFromReplica } = proxyquire(
'../src/services/stateMachineManager/stateMachineUtils.js',
{
'@audius/libs': {
CreatorNode: {
getClockValue: getClockValueStub
'@audius/sdk': {
libs: {
CreatorNode: {
getClockValue: getClockValueStub
}
}
}
}
Expand Down
Loading

0 comments on commit 5c94b3d

Please sign in to comment.