Skip to content

Commit e0e1ecb

Browse files
authored
Create SDK without services by default in all cases (#13906)
See changeset. Motivation is to make the SDK types the same regardless of which config you pass in, and use the API endpoints by default. To keep the existing "services" version of SDK, call `createSdkWithServices` explicitly. This is not recommended - writes and other services won't work without tedious and proper integration with the user's wallet. Also: - Adds `UploadsApi` to services SDK - Updates `storageService` to `storage` in `UploadsApi` config
1 parent b9c2df5 commit e0e1ecb

42 files changed

Lines changed: 234 additions & 214 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/real-rabbits-pretend.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@audius/sdk': major
3+
---
4+
5+
Create SDK without services by default in all cases
6+
7+
Updates the `sdk()` constructor to create the SDK without the old services and API structure regardless of config. This will align all configurations to have the same API surface that matches existing docs and examples.
8+
9+
To maintain compatibility, older legacy apps can use `createSdkWithServices()` instead of `sdk()` when initting the SDK. This is not advised for third-party apps.

packages/commands/src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
sdk,
2+
createSdkWithServices,
33
SolanaRelay,
44
Configuration,
55
createHedgehogWalletClient,
@@ -163,7 +163,7 @@ export const initializeAudiusSdk = async ({
163163

164164
const audiusWalletClient = createHedgehogWalletClient(getHedgehog())
165165

166-
audiusSdk = sdk({
166+
audiusSdk = createSdkWithServices({
167167
appName: 'audius-cmd',
168168
environment: 'development',
169169
services: {

packages/common/src/api/tan-query/batchers/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import type { AudiusSdk } from '@audius/sdk'
1+
import type { AudiusSdkWithServices } from '@audius/sdk'
22
import { QueryClient } from '@tanstack/react-query'
33
import { AnyAction, Dispatch } from 'redux'
44

55
import { ID } from '~/models/Identifiers'
66

77
export type BatchContext = {
8-
sdk: AudiusSdk
8+
sdk: AudiusSdkWithServices
99
currentUserId: ID | null | undefined
1010
queryClient: QueryClient
1111
dispatch: Dispatch<AnyAction>

packages/common/src/api/tan-query/collection/useCollection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useMemo } from 'react'
22

3-
import { AudiusSdk } from '@audius/sdk'
3+
import type { AudiusSdkWithServices } from '@audius/sdk'
44
import { useQuery, useQueryClient, QueryClient } from '@tanstack/react-query'
55
import { useDispatch } from 'react-redux'
66
import { AnyAction, Dispatch } from 'redux'
@@ -26,7 +26,7 @@ export const getCollectionQueryFn = async (
2626
collectionId: ID,
2727
currentUserId: number | null | undefined,
2828
queryClient: QueryClient,
29-
sdk: AudiusSdk,
29+
sdk: AudiusSdkWithServices,
3030
dispatch: Dispatch<AnyAction>
3131
) => {
3232
const batchGetCollections = getCollectionsBatcher({

packages/common/src/api/tan-query/jupiter/executors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FixedDecimal } from '@audius/fixed-decimal'
2-
import { AudiusSdk } from '@audius/sdk'
2+
import type { AudiusSdkWithServices } from '@audius/sdk'
33
import { SwapRequest } from '@jup-ag/api'
44
import {
55
createAssociatedTokenAccountIdempotentInstruction,
@@ -72,7 +72,7 @@ async function executeMeteoraSwap(
7272
swapDirection: 'audioToCoin' | 'coinToAudio',
7373
inputAmountUi: number,
7474
dependencies: {
75-
sdk: AudiusSdk
75+
sdk: AudiusSdkWithServices
7676
userPublicKey: PublicKey
7777
keypair: Keypair
7878
ethAddress: string

packages/common/src/api/tan-query/jupiter/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { AudiusSdk } from '@audius/sdk'
1+
import type { AudiusSdkWithServices } from '@audius/sdk'
22
import { PublicKey } from '@solana/web3.js'
33
import type { Keypair } from '@solana/web3.js'
44
import { useQueryClient } from '@tanstack/react-query'
@@ -74,7 +74,7 @@ export interface UserBankManagedTokenInfo {
7474
}
7575

7676
export type SwapDependencies = {
77-
sdk: AudiusSdk
77+
sdk: AudiusSdkWithServices
7878
keypair: Keypair
7979
userPublicKey: PublicKey
8080
feePayer: PublicKey

packages/common/src/api/tan-query/jupiter/useCoinExchangeRate.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useMemo } from 'react'
22

33
import { FixedDecimal } from '@audius/fixed-decimal'
4-
import type { AudiusSdk } from '@audius/sdk'
4+
import type { AudiusSdkWithServices } from '@audius/sdk'
55
import { QuoteResponse, SwapMode } from '@jup-ag/api'
66
import { QueryClient, useQuery, useQueryClient } from '@tanstack/react-query'
77

@@ -116,7 +116,7 @@ export const getDirectQuote = async (
116116
swapMode?: SwapMode
117117
},
118118
queryClient: QueryClient,
119-
sdk: AudiusSdk
119+
sdk: AudiusSdkWithServices
120120
): Promise<CoinExchangeRateResponse> => {
121121
const { hasPool: inputHasPool } = getCoinPoolState(
122122
params.inputMint,
@@ -172,7 +172,7 @@ export const getIndirectQuoteViaAudio = async (
172172
swapMode?: SwapMode
173173
},
174174
queryClient: QueryClient,
175-
sdk: AudiusSdk
175+
sdk: AudiusSdkWithServices
176176
): Promise<CoinExchangeRateResponse> => {
177177
const { hasPool: inputHasPool } = getCoinPoolState(
178178
params.inputMint,
@@ -273,7 +273,7 @@ export const getQuoteViaMeteoraDBC = async (
273273
amountUi: number
274274
swapMode?: SwapMode
275275
},
276-
sdk: AudiusSdk
276+
sdk: AudiusSdkWithServices
277277
): Promise<JupiterQuoteResult> => {
278278
const { inputMint, outputMint, inputDecimals, outputDecimals, amountUi } =
279279
params

packages/common/src/api/tan-query/jupiter/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { USDC } from '@audius/fixed-decimal'
2-
import type { AudiusSdk } from '@audius/sdk'
2+
import type { AudiusSdkWithServices } from '@audius/sdk'
33
import { SwapInstructionsResponse, SwapRequest } from '@jup-ag/api'
44
import {
55
createAssociatedTokenAccountIdempotentInstruction,
@@ -121,7 +121,7 @@ export async function addTransferToUserBankInstructions({
121121
ethAddress: string
122122
amountLamports: bigint
123123
sourceAta: PublicKey
124-
sdk: AudiusSdk
124+
sdk: AudiusSdkWithServices
125125
feePayer: PublicKey
126126
instructions: TransactionInstruction[]
127127
}): Promise<PublicKey> {
@@ -372,7 +372,7 @@ export const getJupiterSwapInstructions = async (
372372
}
373373

374374
export const buildAndSendTransaction = async (
375-
sdk: AudiusSdk,
375+
sdk: AudiusSdkWithServices,
376376
keypair: Keypair,
377377
feePayer: PublicKey,
378378
instructions: TransactionInstruction[],
@@ -421,7 +421,7 @@ export const invalidateSwapQueries = async (
421421
}
422422

423423
export const prepareOutputUserBank = async (
424-
sdk: AudiusSdk,
424+
sdk: AudiusSdkWithServices,
425425
ethAddress: string,
426426
outputTokenConfig: UserBankManagedTokenInfo
427427
): Promise<string> => {

packages/common/src/api/tan-query/tracks/useTrack.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useMemo } from 'react'
22

3-
import { AudiusSdk } from '@audius/sdk'
3+
import { AudiusSdkWithServices } from '@audius/sdk'
44
import { QueryClient, useQuery, useQueryClient } from '@tanstack/react-query'
55
import { useDispatch } from 'react-redux'
66
import { AnyAction, Dispatch } from 'redux'
@@ -23,7 +23,7 @@ export const getTrackQueryFn = async (
2323
trackId: ID,
2424
currentUserId: ID | null | undefined,
2525
queryClient: QueryClient,
26-
sdk: AudiusSdk,
26+
sdk: AudiusSdkWithServices,
2727
dispatch: Dispatch<AnyAction>
2828
) => {
2929
const batchGetTracks = getTracksBatcher({

packages/common/src/api/tan-query/users/account/useUpdatePlaylistLibrary.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AudiusSdk } from '@audius/sdk'
1+
import { AudiusSdkWithServices } from '@audius/sdk'
22
import { useQueryClient, useMutation, QueryClient } from '@tanstack/react-query'
33
import { useDispatch } from 'react-redux'
44
import { Dispatch } from 'redux'
@@ -34,7 +34,7 @@ export const useUpdatePlaylistLibrary = () => {
3434

3535
// feature-tan-query TODO: migrate saga usages, then remove this
3636
export const updatePlaylistLibrary = async (
37-
audiusSdk: AudiusSdk,
37+
audiusSdk: AudiusSdkWithServices,
3838
userId: ID | null | undefined,
3939
playlistLibrary: PlaylistLibrary,
4040
queryClient: QueryClient,

0 commit comments

Comments
 (0)